Free Support Forum - aspose.com

How to export the data from IChartDataWorkbook as an Excel (Java)

Dear Team,

I already have code setup to export a chart to ppt. And I want to export the formatted data of the chart as an excel.
So, I would like to know the way to export the data in IChartDataWorkbook to an excel file with same data as in the IChartDataWorkbook.

Please let me know the options available and provide an example.

Thanks in advance.

Thilak.

@Thilakbabu,

I have observed your requirements and like to share that ChartDataWorkbook internally contains an Excel file. You can try using following sample code on your end to serve the purpose.

		// Instantiating presentation// Instantiating presentation
		Presentation pres = new Presentation();

		// Accessing the first slide
		ISlide slide = pres.Slides[0];

		// Adding the sample chart
		IChart chart = slide.Shapes.AddChart(ChartType.LineWithMarkers, 50, 50, 500, 400);

		var MemStream =chart.ChartData.ReadWorkbookStream();

		Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(MemStream);
		wb.Save("test.xlsx");

Hi @mudassir.fayyaz ,

Thanks for your quick reply.

I want the example in Java. Could you please update in Java ?

Thanks

@Thilakbabu,

Please check following code.

public static void TestExcel()
{
    try
    {
        // Instantiating presentation// Instantiating presentation
        Presentation pres = new Presentation();

        // Accessing the first slide
        ISlide slide = pres.getSlides().get_Item(0);

        // Adding the sample chart
        IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 50, 50, 500, 400);

        byte[] byteArr =chart.getChartData().readWorkbookStream();

        ByteArrayInputStream MemStream=new ByteArrayInputStream(byteArr);

        com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(MemStream);
        wb.save("test.xlsx");

    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}

Hi @mudassir.fayyaz,

Greetings! Hope you are doing good.

With the above example, Can you please let me know if I can save the chartDataWorkbook to any particular sheet of the workbook ?

Because I have multiple charts and need to save it in multiple sheets.

Thanks in advance.

@Thilakbabu,

I like to share that every chart has its own Workbook. So for every chart there will be one workbook with default worksheet holding the chart data. You can also visit this documentation link for your kind reference.

Hi @mudassir.fayyaz,

Could you please share the documentation for the Java ?

Thanks

@Thilakbabu,

Please visit this documentation link for your reference.