我试图以这种方式从 Excel 单元格中获取价值:
SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(filePath, true);
WorksheetPart worksheetPart = getWorksheetByName(spreadSheetDocument, DEFAULT_SHEET_NAME);
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>();
Cell theCell1 = worksheetPart.Worksheet.Descendants<Cell>().FirstOrDefault(c => c.CellReference == "A5");
Cell theCell2 = worksheetPart.Worksheet.Descendants<Cell>().FirstOrDefault(c => c.CellReference == "A6");
Cell theCell3 = worksheetPart.Worksheet.Descendants<Cell>().FirstOrDefault(c => c.CellReference == "B5");
Cell theCell4 = worksheetPart.Worksheet.Descendants<Cell>().FirstOrDefault(c => c.CellReference == "B6");
然后我正在检查 Cell1.CellValue.Text 属性,我得到了一些奇怪的数据,比如 4,5,248 等,这实际上与真实数据相去甚远。我可以使用 Excel 查看和编辑的实际值。
有谁知道为什么会这样?