Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using excel interoperability in my code and i want to export the below delimited excel data into sql table.

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
C#
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 "|"

Please help
Posted
Updated 1-Apr-11 4:06am
v2
Comments
Eager2Lern 6-Apr-11 18:04pm    
Thank you walterhevedeich...that really helped...you are a gem of a person

1 solution

Since you are using your own delimiter, format parameter should be 6 and not 1. Refer to the code below

ExcelObj.Workbooks.Open(FI.FullName, 0, true, 6, "","",false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "|", true, false, 0, true,false, false);


Workbooks.Open Method
[^]
 
Share this answer
 

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