EPPlus工作表System.Collections.Generic.KeyNotFoundException

时间:2018-11-13 09:45:44

标签: excel epplus worksheet

我对一个Excel及其工作表有疑问。当我使用基本代码

using (var p =new ExcelPackage(new FileInfo(path))){
      int wN=p.Workbook.Worksheets.Count;
}

我收到一个错误:System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. 另外,当我在Excel中打开文件时,工作表就在那里。 这是该.xlsx文件的workbook.xml部分。

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion lastEdited="4" lowestEdited="4" rupBuild="4505" /><workbookPr defaultThemeVersion="123820" /><bookViews><workbookView xWindow="480" yWindow="15" windowWidth="15120" windowHeight="9285" /></bookViews><sheets><sheet name="Report Page" sheetId="1" r:id="rId1"/></sheets><calcPr calcId="122211" /><webPublishing codePage="1252" /></workbook>

打开其他.xlsx文件没有问题,并且该文件位于磁盘上,因此没有网络问题。

编辑这里是错误:

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at OfficeOpenXml.Packaging.ZipPackageRelationshipCollection.get_Item(String id)
at OfficeOpenXml.Packaging.ZipPackageRelationshipBase.GetRelationship(String id)
at OfficeOpenXml.ExcelWorksheet.LoadHyperLinks(XmlReader xr)
at OfficeOpenXml.ExcelWorksheet.CreateXml()
at OfficeOpenXml.ExcelWorksheet..ctor(XmlNamespaceManager ns, ExcelPackage excelPackage, String relID, Uri uriWorksheet, String sheetName, Int32 sheetID, Int32 positionID, eWorkSheetHidden hide)
at OfficeOpenXml.ExcelWorksheets..ctor(ExcelPackage pck, XmlNamespaceManager nsm, XmlNode topNode)
at OfficeOpenXml.ExcelWorkbook.get_Worksheets()
at Testing_process.CreateExcel.MainTest(String path, String worksheet, Int32 offset) in c:\Users\*******\CreateExcel.cs:line 36
at Testing_process.Program.Main(String[] args) in c:\Users\******\Program.cs:line 302

0 个答案:

没有答案