我试图获取WorkbookStylesPart的上下文/句柄,但我无法从第3行跳转到第4行:
using (SpreadsheetDocument document = SpreadsheetDocument.Open(path, true)) {
IEnumerable<Sheet> sheets = document.WorkbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == dr["horse"].ToString());
WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheets.FirstOrDefault().Id);
var stylesPart = document.WorkbookPart.AddNewPart<WorkbookStylesPart>();
stylesPart.Stylesheet = new Stylesheet();
...
它崩溃了
var stylesPart = document.WorkbookPart.AddNewPart();
错误是&#34;未处理的异常:DocumentFormat.OpenXml.Packaging.OpenXmlPackageException:此父级只允许该类型的一个实例。&#34;
我不知道该怎么做。谢谢你的帮助。