Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using excel interoperability in my code and i want to read the below delimited excel data.

MAS|201012211616360001|Q-0263014640218 067 0423|LIMITED TOO|SS SOLID POLO||6110202075|100% COTTON####|||Q086|CASUAL TOPS CUT SEWN S|CH|CHILDREN|CUT SEWN|CASUAL TOPS|0423|067|0263014640218|59024316||||||||||N|||1|EA|1|0|1|1|CM|0|KG

The code is as follow


string path = txtFile.Text;
                DirectoryInfo dir = new DirectoryInfo(path);
                FileInfo[] FileList = dir.GetFiles("*.*", SearchOption.AllDirectories);
                foreach (FileInfo FI in FileList)
                {
                    using (SqlConnection Connection = ConnectionManager.GetConnection())
                    {
                        Microsoft.Office.Interop.Excel.Application ExcelObj = new Microsoft.Office.Interop.Excel.Application();
                        Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(FI.FullName, 0, true, 1, "","",false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "|", true, false, 0, true,false, false);
                        Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
                        Microsoft.Office.Interop.Excel.Worksheet workSheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
                        int rowIndex = 1;
                        int colIndex1 = 1;
                        int index = 0;
                    a:  while (((Microsoft.Office.Interop.Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null)
                        {

At this point the value2 is showing the entire row, its not delimiting based on "|"

I am going crazy...it was working fine somedays ago...I donno what's happening
Please help I am using Microsoft.Office.Interop.Excel 12.0
Posted
Updated 19-Apr-11 20:47pm
v2
Comments
Eager2Lern 20-Apr-11 2:53am    
Walter, i am going crazy....I tried object format 6..not working please help
walterhevedeich 20-Apr-11 3:11am    
Relax. Welcome to the world of programming. :)
Eager2Lern 20-Apr-11 3:05am    
Walter, do you want me to upload the excel file
walterhevedeich 20-Apr-11 3:12am    
No need. as long as you put what is needed for this question. My advice is that you should check the differences on the excel of your new project vs. the old one. You might get some hints.
Eager2Lern 20-Apr-11 3:22am    
walter, i found the solution
My file is of excel(xlsx) format and the interoperability method works in text files only when i copied the data into a text file and renamed it to a different format for eg. .MAS format it started reading fine..thanks man..

1 solution

I answered this a few weeks ago and you confirmed it helped.

Excel interoperability delimiting option not working[^]
 
Share this answer
 
Comments
Eager2Lern 20-Apr-11 3:02am    
I am using the same code in another project at this point its not working..why is this happening even after setting the object format as 6 which is for special characters
walterhevedeich 20-Apr-11 3:10am    
I was under the assumption that you are still using 1, basing it on what you posted. You may want to update your question to reflect what you really put in your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900