/// <summary> /// Creates a chart. /// </summary> /// <param name="anchor">the client anchor describes how this chart is attached to</param> /// <returns>the newly created chart</returns> public IChart CreateChart(IClientAnchor anchor) { int chartNumber = GetPackagePart().Package. GetPartsByContentType(XSSFRelation.CHART.ContentType).Count + 1; XSSFChart chart = (XSSFChart)CreateRelationship( XSSFRelation.CHART, XSSFFactory.GetInstance(), chartNumber); String chartRelId = chart.GetPackageRelationship().Id; XSSFGraphicFrame frame = CreateGraphicFrame((XSSFClientAnchor)anchor); frame.SetChart(chart, chartRelId); return(chart); }
internal override void OnDocumentRead() { try { this.workbook = WorkbookDocument.Parse(this.GetPackagePart().GetInputStream()).Workbook; Dictionary <string, XSSFSheet> dictionary = new Dictionary <string, XSSFSheet>(); foreach (POIXMLDocumentPart relation in this.GetRelations()) { if (relation is SharedStringsTable) { this.sharedStringSource = (SharedStringsTable)relation; } else if (relation is StylesTable) { this.stylesSource = (StylesTable)relation; } else if (relation is ThemesTable) { this.theme = (ThemesTable)relation; } else if (relation is CalculationChain) { this.calcChain = (CalculationChain)relation; } else if (relation is MapInfo) { this.mapInfo = (MapInfo)relation; } else if (relation is XSSFSheet) { dictionary.Add(relation.GetPackageRelationship().Id, (XSSFSheet)relation); } } if (this.stylesSource != null) { this.stylesSource.SetTheme(this.theme); } if (this.sharedStringSource == null) { this.sharedStringSource = (SharedStringsTable)this.CreateRelationship((POIXMLRelation)XSSFRelation.SHARED_STRINGS, (POIXMLFactory)XSSFFactory.GetInstance()); } this.sheets = new List <XSSFSheet>(dictionary.Count); foreach (CT_Sheet ctSheet in this.workbook.sheets.sheet) { XSSFSheet xssfSheet = dictionary[ctSheet.id]; if (xssfSheet == null) { XSSFWorkbook.logger.Log(5, (object)("Sheet with name " + ctSheet.name + " and r:id " + ctSheet.id + " was defined, but didn't exist in package, skipping")); } else { xssfSheet.sheet = ctSheet; xssfSheet.OnDocumentRead(); this.sheets.Add(xssfSheet); } } this.namedRanges = new List <XSSFName>(); if (!this.workbook.IsSetDefinedNames()) { return; } foreach (CT_DefinedName name in this.workbook.definedNames.definedName) { this.namedRanges.Add(new XSSFName(name, this)); } } catch (XmlException ex) { throw new POIXMLException((Exception)ex); } }
public XSSFWorkbook(OPCPackage pkg) : base(pkg) { this.Load((POIXMLFactory)XSSFFactory.GetInstance()); }
public XSSFWorkbook(Stream is1) : base(PackageHelper.Open(is1)) { this.Load((POIXMLFactory)XSSFFactory.GetInstance()); }
public ISheet CreateSheet(string sheetname) { if (sheetname == null) { throw new ArgumentException("sheetName must not be null"); } if (this.ContainsSheet(sheetname, this.sheets.Count)) { throw new ArgumentException("The workbook already contains a sheet of this name"); } if (sheetname.Length > 31) { sheetname = sheetname.Substring(0, 31); } WorkbookUtil.ValidateSheetName(sheetname); CT_Sheet ctSheet = this.AddSheet(sheetname); int idx = 1; foreach (XSSFSheet sheet in this.sheets) { idx = (int)Math.Max((long)(sheet.sheet.sheetId + 1U), (long)idx); } XSSFSheet relationship = (XSSFSheet)this.CreateRelationship((POIXMLRelation)XSSFRelation.WORKSHEET, (POIXMLFactory)XSSFFactory.GetInstance(), idx); relationship.sheet = ctSheet; ctSheet.id = relationship.GetPackageRelationship().Id; ctSheet.sheetId = (uint)idx; if (this.sheets.Count == 0) { relationship.IsSelected = true; } this.sheets.Add(relationship); return((ISheet)relationship); }
public int AddPicture(Stream picStream, int format) { int idx = this.GetAllPictures().Count + 1; XSSFPictureData relationship = (XSSFPictureData)this.CreateRelationship(XSSFPictureData.RELATIONS[format], (POIXMLFactory)XSSFFactory.GetInstance(), idx, true); Stream outputStream = relationship.GetPackagePart().GetOutputStream(); IOUtils.Copy(picStream, outputStream); outputStream.Close(); this.pictures.Add(relationship); return(idx - 1); }
private void OnWorkbookCreate() { this.workbook = new CT_Workbook(); this.workbook.AddNewWorkbookPr().date1904 = false; this.workbook.AddNewBookViews().AddNewWorkbookView().activeTab = 0U; this.workbook.AddNewSheets(); CT_ExtendedProperties underlyingProperties = this.GetProperties().GetExtendedProperties().GetUnderlyingProperties(); underlyingProperties.Application = POIXMLDocument.DOCUMENT_CREATOR; underlyingProperties.DocSecurity = 0; underlyingProperties.DocSecuritySpecified = true; underlyingProperties.ScaleCrop = false; underlyingProperties.ScaleCropSpecified = true; underlyingProperties.LinksUpToDate = false; underlyingProperties.LinksUpToDateSpecified = true; underlyingProperties.HyperlinksChanged = false; underlyingProperties.HyperlinksChangedSpecified = true; underlyingProperties.SharedDoc = false; underlyingProperties.SharedDocSpecified = true; this.sharedStringSource = (SharedStringsTable)this.CreateRelationship((POIXMLRelation)XSSFRelation.SHARED_STRINGS, (POIXMLFactory)XSSFFactory.GetInstance()); this.stylesSource = (StylesTable)this.CreateRelationship((POIXMLRelation)XSSFRelation.STYLES, (POIXMLFactory)XSSFFactory.GetInstance()); this.namedRanges = new List <XSSFName>(); this.sheets = new List <XSSFSheet>(); }
public int AddPicture(byte[] pictureData, PictureType format) { int idx = this.GetAllPictures().Count + 1; XSSFPictureData relationship = (XSSFPictureData)this.CreateRelationship(XSSFPictureData.RELATIONS[(int)format], (POIXMLFactory)XSSFFactory.GetInstance(), idx, true); try { Stream outputStream = relationship.GetPackagePart().GetOutputStream(); outputStream.Write(pictureData, 0, pictureData.Length); outputStream.Close(); } catch (IOException ex) { throw new POIXMLException((Exception)ex); } this.pictures.Add(relationship); return(idx - 1); }
public IChart CreateChart(IClientAnchor anchor) { int idx = this.GetPackagePart().Package.GetPartsByContentType(XSSFRelation.CHART.ContentType).Count + 1; XSSFChart relationship = (XSSFChart)this.CreateRelationship((POIXMLRelation)XSSFRelation.CHART, (POIXMLFactory)XSSFFactory.GetInstance(), idx); string id = relationship.GetPackageRelationship().Id; this.CreateGraphicFrame((XSSFClientAnchor)anchor).SetChart(relationship, id); return((IChart)relationship); }