Force EPPLUS to read as text

后端 未结 2 1315
猫巷女王i
猫巷女王i 2021-01-17 16:27

I\'m developping an application to read xlsx files, do some validation and insert into database. Unfortunatelly when I try to read columns marked as numeric (fe with EAN-13

2条回答
  •  粉色の甜心
    2021-01-17 16:53

    Apparently this is the solution (not complete code though, you have to add columns to datatable). I couldn't find the format string which specifies 'no formatting' in Epplus, but here you have it.

     var ws = MainExcel.Workbook.Worksheets.First();
     DataTable tbl = new DataTable();
     for (var rowNum = 1; rowNum <= ws.Dimension.End.Row; rowNum++)      
     {
         var wsRow = ws.Cells[rowNum, 1, rowNum, ws.Dimension.End.Column];
         var array = wsRow.Value as object[,];
    
         var row = tbl.NewRow();
         int hhh =0;
    
         foreach (var cell in wsRow)
              {
               cell.Style.Numberformat.Format = "@";
               row[cell.Start.Column - 1] = cell.Text;
              }
         tbl.Rows.Add(row);
     }
    

提交回复
热议问题