【问题标题】:How to read file excel with empty cells using EPPlus如何使用 EPPlus 读取带有空单元格的文件 excel
【发布时间】:2019-07-12 13:44:28
【问题描述】:

我有一个包含 2 列的 excel 文件:Nameprice。 我使用 EPPlus 读取文件 excel:

OpenFileDialog dlg = new OpenFileDialog();
var package = new ExcelPackage(new FileInfo("" + dlg.FileName));
ExcelWorksheet workSheet = package.Workbook.Worksheets[1];
for (int i = workSheet.Dimension.Start.Row + 1; i <= workSheet.Dimension.End.Row; i++)
{
    try
    {
         int j = 1;
         string name = workSheet.Cells[i, j++].Value.ToString();
         string price = workSheet.Cells[i, j++].Value == null ? string.Empty : workSheet.Cells[i, j++].Value.ToString();

我想从价格列中读取带有空单元格的文件 excel,我找到了很多解决方案,我看到了这样的解决方案:string price = workSheet.Cells[i,j++].Value == null ? string.Empty : workSheet.Cells[i, j++].Value.ToString();

我调试了一下,看到price = true

我使用OriPrice= decimal.Parse(price)(OriPrice 是数据库中表中列的名称)将值从 excel 添加到数据库。 但我有一个错误。

我知道string price = workSheet.Cells[i,j++].Value == null ? string.Empty : workSheet.Cells[i, j++].Value.ToString(); 行有错误,因为price = true,我想定价=string.EmptyworkSheet.Cells[i, j++].Value.ToString();

但我不知道该怎么做。

【问题讨论】:

    标签: c# excel epplus


    【解决方案1】:

    试试吧

    string price =  workSheet.Cells[i, j++].Text.Trim() 
    

    如果没有,应该可以。 我想。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多