How to Export Charts to Excel files from your .NET applications?
Following example shows how to export charts to Excel files by using only GemBox.Spreadsheet .NET component.
GemBox.Spreadsheet is a .NET component which provides easy and high performance
way to write, read or convert native Microsoft Excel files (XLS, CSV or XLSX) and
HTML files without the need for Microsoft Excel on either the developer or client
machines. GemBox.Spreadsheet Free comes free of charge while GemBox.Spreadsheet
Professional is a commercial version (licensed per developer). Find more information
about GemBox.Spreadsheet features or reasons why our component is better then Excel Automation.
Inserting charts is not supported directly, so template file (with empty chart dataset)
is used. Example reads template Excel file (in XLSX format), fills it with chart
data and writes the new file:
|
ExcelFile ef =
new ExcelFile();
// Loads template Excel file that contains chart on the empty
dataset.
ef.LoadXlsx("templateChart.xlsx",
XlsxOptions.PreserveKeepOpen);
// Selects the first worksheet.
ExcelWorksheet ws = ef.Worksheets[0];
// Fills the data used to create chart.
ws.Cells[0, 0].Value = "John Doe";
ws.Cells[0, 1].Value = 8;
ws.Cells[1, 0].Value = "Hans Meier";
ws.Cells[1, 1].Value = 9;
ws.Cells[2, 0].Value = "Jean Dupont";
ws.Cells[2, 1].Value = 12;
// Saves the Excel file.
ef.SaveXlsx("newChart.xlsx");
|
|
Dim ef
As New ExcelFile
' Loads template Excel file that contains chart on the empty
dataset.
ef.LoadXlsx("templateChart.xlsx",
XlsxOptions.PreserveKeepOpen)
' Selects the first worksheet.
Dim worksheet As
ExcelWorksheet = ef.Worksheets(0)
' Fills the data used to create chart.
worksheet.Cells(0, 0).Value = "John Doe"
worksheet.Cells(0, 1).Value = 8
worksheet.Cells(1, 0).Value = "Hans Meier"
worksheet.Cells(1, 1).Value = 9
worksheet.Cells(2, 0).Value = "Jean Dupont"
worksheet.Cells(2, 1).Value = 12
' Saves the Excel file.
ef.SaveXlsx("newChart.xlsx")
|
Template file had no chart data and looked like this:

New file was created by using the code above and looks like this:

|
|
|
© GemBox Software. All rights reserved.
|