internal override void OnDocumentRead() { try { XmlDocument xmldoc = ConvertStreamToXml(GetPackagePart().GetInputStream()); doc = WorkbookDocument.Parse(xmldoc, NamespaceManager); this.workbook = doc.Workbook; Dictionary<String, XSSFSheet> shIdMap = new Dictionary<String, XSSFSheet>(); foreach (POIXMLDocumentPart p in GetRelations()) { if (p is SharedStringsTable) sharedStringSource = (SharedStringsTable)p; else if (p is StylesTable) stylesSource = (StylesTable)p; else if (p is ThemesTable) theme = (ThemesTable)p; else if (p is CalculationChain) calcChain = (CalculationChain)p; else if (p is MapInfo) mapInfo = (MapInfo)p; else if (p is XSSFSheet) { shIdMap.Add(p.GetPackageRelationship().Id,(XSSFSheet)p); } } if (null != stylesSource) { stylesSource.SetTheme(theme); } if (sharedStringSource == null) { //Create SST if it is missing sharedStringSource = (SharedStringsTable)CreateRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.GetInstance()); } // Load individual sheets. The order of sheets is defined by the order of CT_Sheet elements in the workbook sheets = new List<XSSFSheet>(shIdMap.Count); foreach (CT_Sheet ctSheet in this.workbook.sheets.sheet) { XSSFSheet sh = shIdMap[ctSheet.id]; if (sh == null) { logger.Log(POILogger.WARN, "Sheet with name " + ctSheet.name + " and r:id " + ctSheet.id + " was defined, but didn't exist in package, skipping"); continue; } sh.sheet = ctSheet; sh.OnDocumentRead(); sheets.Add(sh); } // Process the named ranges namedRanges = new List<XSSFName>(); if (workbook.IsSetDefinedNames()) { foreach (CT_DefinedName ctName in workbook.definedNames.definedName) { namedRanges.Add(new XSSFName(ctName, this)); } } } catch (XmlException e) { throw new POIXMLException(e); } }
internal override void OnDocumentRead() { try { XmlDocument xmldoc = ConvertStreamToXml(GetPackagePart().GetInputStream()); doc = WorkbookDocument.Parse(xmldoc, NamespaceManager); this.workbook = doc.Workbook; Dictionary<String, XSSFSheet> shIdMap = new Dictionary<String, XSSFSheet>(); Dictionary<String, ExternalLinksTable> elIdMap = new Dictionary<String, ExternalLinksTable>(); foreach (POIXMLDocumentPart p in GetRelations()) { if (p is SharedStringsTable) sharedStringSource = (SharedStringsTable)p; else if (p is StylesTable) stylesSource = (StylesTable)p; else if (p is ThemesTable) theme = (ThemesTable)p; else if (p is CalculationChain) calcChain = (CalculationChain)p; else if (p is MapInfo) mapInfo = (MapInfo)p; else if (p is XSSFSheet) { shIdMap.Add(p.GetPackageRelationship().Id,(XSSFSheet)p); } else if (p is ExternalLinksTable) { elIdMap.Add(p.GetPackageRelationship().Id, (ExternalLinksTable)p); } } bool packageReadOnly = (Package.GetPackageAccess() == PackageAccess.READ); if (stylesSource == null) { // Create Styles if it is missing if (packageReadOnly) { stylesSource = new StylesTable(); } else { stylesSource = (StylesTable)CreateRelationship(XSSFRelation.STYLES, XSSFFactory.GetInstance()); } } stylesSource.SetTheme(theme); if (sharedStringSource == null) { //Create SST if it is missing if (packageReadOnly) { sharedStringSource = new SharedStringsTable(); } else { sharedStringSource = (SharedStringsTable)CreateRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.GetInstance()); } } // Load individual sheets. The order of sheets is defined by the order // of CTSheet elements in the workbook sheets = new List<XSSFSheet>(shIdMap.Count); foreach (CT_Sheet ctSheet in this.workbook.sheets.sheet) { XSSFSheet sh = null; if(shIdMap.ContainsKey(ctSheet.id)) sh = shIdMap[ctSheet.id]; if (sh == null) { logger.Log(POILogger.WARN, "Sheet with name " + ctSheet.name + " and r:id " + ctSheet.id + " was defined, but didn't exist in package, skipping"); continue; } sh.sheet = ctSheet; sh.OnDocumentRead(); sheets.Add(sh); } // Load the external links tables. Their order is defined by the order // of CTExternalReference elements in the workbook externalLinks = new List<ExternalLinksTable>(elIdMap.Count); if (this.workbook.IsSetExternalReferences()) { foreach (CT_ExternalReference er in this.workbook.externalReferences.externalReference) { ExternalLinksTable el = null; if(elIdMap.ContainsKey(er.id)) el = elIdMap[(er.id)]; if (el == null) { logger.Log(POILogger.WARN, "ExternalLinksTable with r:id " + er.id + " was defined, but didn't exist in package, skipping"); continue; } externalLinks.Add(el); } } // Process the named ranges ReprocessNamedRanges(); } catch (XmlException e) { throw new POIXMLException(e); } }
public XSSFMap(CT_Map ctMap, MapInfo mapInfo) { this.ctMap = ctMap; this.mapInfo = mapInfo; }