DocumentFormat.openxml Excel文件读取问题

时间:2016-06-21 04:15:10

标签: c# .net excel openxml openxml-sdk

我在我的一个项目中使用了DocumentFormat.OpenXml dll来读取和编写excel文件。

在阅读Excel文件时,让我们说某些专栏说Column1我的单元格值为" TRUE"和"错误"。当我使用以下代码阅读此Excel文件时

private SharedStringTable sharedStringTable;
using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fileName, false))
{

  WorkbookPart workbookPart = doc.WorkbookPart;
  WorksheetPart worksheetPart = workbookPart.WorksheetParts.FirstOrDefault();
  SharedStringTablePart sharedStringTablePart = workbookPart.SharedStringTablePart;
  if (sharedStringTablePart != null)
  {
    sharedStringTable = sharedStringTablePart.SharedStringTable;
  }
    var sheets = workbookPart.Workbook.Sheets;

    foreach (Sheet sheet in sheets)
    {   
            Worksheet requiredItem = (doc.WorkbookPart.GetPartById(sheet.Id.Value) as WorksheetPart).Worksheet;
            var sheetData = requiredItem.Elements<SheetData>().First();

            foreach (var rowItem in sheetData.Elements<Row>())
            {
                foreach (var item in rowItem.Elements<Cell>())
                {
                    string requiredText = string.empty;
                    if (item.CellValue != null)
                    {
                        requiredText = item.CellValue.InnerText;
                    }
                }
            }
    }

}

当时对于Cell Values&#34; TRUE&#34;和&#34;错误&#34;我分别得到值1和0。

任何人都可以为我提供任何方式,以便我能够获得价值并且真正的#34;真实的&#34;和&#34;错误&#34;而不是1和0?

0 个答案:

没有答案