在C#

时间:2018-10-31 16:40:37

标签: c# excel openxml openxml-sdk

我正在尝试使用C#中的Open-XML SDK读取非常简单的Excel文件,但无法获取WorksheetPart。 Excel文件在这里:https://files.fm/u/e6348uzt

using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open("C:\\Test.xlsx", true)) {
      WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart;
      Workbook workbook = workbookPart.Workbook;
      Sheet sheet = workbook.Descendants<Sheet>().FirstOrDefault();
      WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id);
}

GetPartyById引发:

System.ArgumentOutOfRangeException: 'Specified argument was out of the range of valid values.'

Internet上的所有简单示例都遵循该模式,但对我而言不起作用。我在做什么错了?

0 个答案:

没有答案