I want to create a Chart in Aspose.Cells and insert it into a newly created Document in Aspose.Words.
I understand that "there are no plans to allow inserting new embedded objects at this time" for Aspose.Words. (http://www.aspose.com/Community/forums/AddPost.aspx?PostID=58093) So I cannot embed such a Chart into a Document.
But is it possible in Aspose.Cells to create an image of my newly created Chart? Then I can use insertImage in Aspose.Words.
You can convert the Excel Charts to images and PDF formats via Aspose.Cells without requirement MS Excel or any other tool (to be installed). The feature has become more robust and efficient now, so you may concert all types of MS Excel to image format on the fly. In order to provide rendering support, the Chart class has exposed ToImage & ToPdf methods with a verity of overloads to best suit the application requirements.
See the following sample code for your reference:
e.g Sample code:
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook
int sheetIndex = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection
Worksheet worksheet = workbook.Worksheets[sheetIndex];
// Adding sample values to cells
// Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
// Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3"
// Create an instance of ImageOrPrintOptions and set a few properties
ImageOrPrintOptions options = new ImageOrPrintOptions()
VerticalResolution = 300,
HorizontalResolution = 300,
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
// Convert chart to image with additional settings
See the document for your further reference:
You may also download the up-to-date examples/demos here.