xlsgen > overview > Charts management |
xlsgen provides the following mechanisms to manage charts :
worksheet.NewChart
(embedded chart)workbook.AddChart
(stand-alone chart, has its own sheet tab)charts.Item(i).Delete()
worksheet.Charts
returns the charts collection for the given worksheetcharts.Item(i)
returns the i-th chart in that collectionchart.ExtractToFile()
returns a snapshot of the chart (PNG file)chart.ExtractToMemory()
returns a buffer with a snapshot of the chart (PNG buffer)chart.CommitChanges
method which ensures that the changes are indeed written back to the file. Example : change the chart type of an existing chart, example source code is in C/C++ :
C/C++ code |
xlsgen::IXlsEnginePtr engine( __uuidof(xlsgen::CoXlsEngine) ); xlsgen::IXlsWorkbookPtr wbk = engine->Open(L"existingFile.xslx", L"updatedFile.xlsx"); // we want to edit the second chart in the first worksheet xlsgen::IXlsChartPtr chart = wbk->WorksheetByIndex[1]->Charts->Item[2]; // change the chart type chart->Type = xlsgen::charttype_bar3D; // commit the changes chart->CommitChanges(); wbk->Close(); |
worksheet.PrintWith
prints the worksheet and its contents
worksheet.PrintPreview
previews the worksheet and its contents
worksheet.Export.ExportAsPDF
exports the worksheet and its contents as a PDF file
1) ensure to enable the reading of a separate workbook from the current workbook. This is achieved by doing the following : workbook.AutoOpenExternalWorkbookReference = TRUE;
2) help xlsgen by passing the filepath where the separate workbook is stored. Note that by filepath is not meant the full file path, only the directory file path. For instance if the separate workbook (where the data is stored) is located in C:\tmp\workdir
, make sure to do the following : engine.Workbooks.AddFilepath("C:\\tmp\\workdir");
, where engine
is the xlsgen instance.
TurnToStandalone
method call available at the chart level. And there is the opposite method available too, TurnToEmbedded
, which turns a chart from being stand-alone to being embedded.CopyTo
method call. A refined method call, CopyToLocation
makes it possible to copy a chart to a given location in the target sheet. These two method calls are suited when the scenario tries to avoid bringing over the entire content of a sheet (including chart) which is what happens with the Duplicate
method call exposed at the worksheet level. Note that when a chart is copied from an external workbook, the range of cells of the data source are resolved and replaced by arrays of fix values.
xlsgen documentation. © ARsT Design all rights reserved.