I’m having some problem reading the date from an xlsx file, what I mean is that it doesn’t read all the information in the cells, for example I have in a cell this information:
"4876112","3456151712","345627712","3125HPC21017500011","34131HPC210349014112","35134HPC210273008212"
and when I check to see the DataTable I only see this information in the rows
"4876112","3456151712","345627712",
this is my code:
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook = excelApp.Workbooks.Open(input, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
string sheetname = "";
foreach (Microsoft.Office.Interop.Excel.Worksheet sheet in workbook.Sheets)
{
sheetname = sheet.Name;
break;
}
string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", input);
string query = String.Format("select * from [{0}$]", sheetname);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
tabela = ds.Tables[0];
I entered and Formated the cells of the Excel into text and worked fine. Can I programatically change all the cells format into text.
Thanks!
If you want all the cells in your worksheet to be formatted as text you can simply do: