We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copy image (chart) from excel to filesystem

Hi,

I want to know how to copy an image from an excelsheet and save it to the filesystem and whether it's possible with this component.

Kind regards,
Karim


This message was posted using Page2Forum from Aspose.Form - Aspose.Cells for .NET and Java

Hi Karim,

Thanks for considering Aspose.

Yes, copying chart to save as an image file is possible. Please check:

Convert Chart to Images

Sample code:

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();

workbook.Open(@"d:\test\MyBook.xls");

Aspose.Cells.Chart chart = workbook.Worksheets["Sheet1"].Charts[0]; 

Bitmap bitmap = chart.ToImage();

bitmap.Save(@"d:\TestChart_Image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 

Thank you.

Hi Amjad,

It looks to be working, but why is the 3D effect not being copied. I have a chart (bars) with some 3D effect, but when i save it to a file it appears as a flat bar.

Kind regards,
Karim

Hi Karim,

Thanks for considering Aspose.

We will support to convert the 3D charts to image soon.

Thank you.

Hi Karim,

Which version do you use?Please try the Aspose.Cells for .NET (Latest Version)

If you still get the problem,please you post your sample file. We will check it soon.

Hi , I want to read the images and Charts from Excel file and store it local system as image file using java.

Is there any possible to read the charts and images fromExcel using java , if so please give me a sample code to implement.

Regards

Janakiraman

Hi,

Thank you for considering Aspose.

I am afraid, this feature (convert Chart2Image) is currently not supported in Aspose.Cells for Java.

Thank You & Best Regards

Hi,

Thanks for your reply, is there any possiblity to read or copy the Charts in Excel using java.

Actually i want to read the Charts and images from Excel file and export it to PPT using Java

Regards

Janakiraman

Hi,

Thank you for considering Aspose.

We will get back to you soon regarding your requirement.

Thank you,

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

I am afraid exporting charts is not supported currently. For exporting pictures, I think you can save the picture's data into file or stream and then use the file or stream to import pictures into PPT. Following is a sample code for saving pictures:

Workbook wb = new Workbook();

wb.open("Picture.xls");

Picture pic = wb.getWorksheets().getSheet(0).getPictures().get(0);

int type = pic.getImageFormat();

String ext = "bmp";

switch(type)

{

case ImageFormat.BMP:

ext = "bmp";

break;

case ImageFormat.EMF:

ext = "emf";

break;

case ImageFormat.GIF:

ext = "gif";

break;

case ImageFormat.ICON:

ext = "ico";

break;

case ImageFormat.JPEG:

ext = "jpeg";

break;

case ImageFormat.PNG:

ext = "png";

break;

case ImageFormat.WMF:

ext = "wmf";

break;

}

byte[] data = pic.getData();

FileOutputStream fos = new FileOutputStream("pic."+ext);

fos.write(data);

fos.close();

Thank You & Best Regards,

Hi nausherwan.aslam ,

Thanks for your reply.

We are in need to read charts from Excel and export it to PPT .

We have aready carried out the option of reading images from excel,

but the thing is to read Charts from Excel and export to PPT.

Regards

Janakiraman

Hi Janakiraman,

Currently, this feature is not supported in our Java version. But, we are working on this feature and we will provide support for this feature in 2 months time. We will let you know when the feature is released.

Thank you for understanding,

Hi nausherwan.aslam ,

Thanks for your response.

Regards

Jana

Hi aslam,

I have another doubt on chart , assume i have 2 to 3 charts in a sheet , is it possible

to copy the charts from that sheet and write each chart in sepearte sheet.

Regards

Janakiraman

Hi,

Yes, I think you may try to consult the following sample codes for your need.

Sample code:

Workbook wb = new Workbook();
wb.open("e:\\files\\ChartBook.xls");

Worksheets wss = wb.getWorksheets();
Worksheet sheet1 = wss.getSheet(0);
Worksheet sheet2 = wss.addSheet("new copy");

//copy Chart
Chart chart = sheet1.getCharts().getChart(0);
sheet2.getShapes().addCopy(chart.getChartShape());


wb.save("e:\\files\\output.xls");
Thank you.

Hi Team,
I need to copy Pivot Tables from excel and save it to PNG image in my local. How to achieve this.

Regards,
Mamtha.A.C.D

@HAREEM_HCL_COM,

Thanks for your query.

Well, you may devise an approach (as following) to take an image of the pivot table in the worksheet for your needs. You got to refresh and calculate PivotTable data before rendering to image file format. See the following code segment for your reference, please refer to it and write/update your own code accordingly for your needs:
e.g
Sample code:

        PivotTableCollection pivotTables = worksheet.getPivotTables();
  		PivotTable pivotTable = pivotTables.get(0);//Get the first PivotTable
//Add the following lines to refresh data and calculate data.
                                    pivotTable.refreshData();
                                    pivotTable.calculateData(); 
  		CellArea pivotArea = pivotTable.getTableRange1();
  		System.out.println("Area:: pivot table area :: " + pivotArea);
	            //Get the first page row/column.
        int strow = pivotArea.StartRow;
        int stcol = pivotArea.StartColumn;

        //Get the counts of rows/columns upto the end
        int numrows = pivotArea.EndRow - strow;
        int numcols = pivotArea.EndColumn - stcol;

        String sarea = CellsHelper.cellIndexToName(strow, stcol);
        String earea = CellsHelper.cellIndexToName(numrows, numcols);

        //Set the printable area in the PageSetup for the sheet.
        worksheet.getPageSetup().setPrintArea(sarea + ":" + earea);
  			worksheet.getPageSetup().setLeftMargin(0.0);
  			worksheet.getPageSetup().setRightMargin(0.0);
  			worksheet.getPageSetup().setTopMargin(0.0);
  			worksheet.getPageSetup().setBottomMargin(0.0);
  			ImageOrPrintOptions options = new ImageOrPrintOptions();
  				options.setImageFormat(ImageFormat.getPng());
  			SheetRender sr = new SheetRender(worksheet, options);
  			sr.toImage(0, "out1.png");

Hope, this helps a bit.

Hi Team , i tried above code, it just returned the header of the pivot table.
My actual requirement is that, I need the Pivot Chart to be extracted and saved into an image file. Please assist me on this.

Regards,
Mamtha.A.C.D.

@HAREEM_HCL_COM,

To help you in better way with sample code, we need your template file (containing your PivotTable/Pivot chart in it), so we could evaluate your issue and provide better assistance. Please attach the template file (you may zip it prior attaching), we will check it soon.

Hi Team, I have code for fetching the Pivot Chart from Pivot Table from Excel. However, I need assistance for fetching the complete image of the Pivot Chart with all field buttons, legend field buttons, Chart 1.png (2.1 KB)
along with Chart.
I have attached 2 images.
First the chart(Chat1), which I could obtain through code.This is just the chart, it is not bringing any field buttons along with the chart.
Secondly see the image(which i copy and pasted manually to paint as image) bellow. I need the output as this image.

completPivotChart image from Excel.png (10.7 KB)
How to achieve this.

Regards,
Mamtha.A.C.D