How to Convert an Excel Chart to Image inside Android Applications
This technical tip show how developers can convert an excel chart to an image in their android applications using Aspose.Cell for Android. Charts are visually appealing and make it easy for users to see comparisons, patterns, and trends in data. For instance, rather than analyzing columns of worksheet numbers, a chart shows at a glance whether sales are falling or rising, or how actual sales compare to projected sales. People are frequently asked to present statistical and graphical information in an easy to understand and an easy to maintain manner. A picture helps. Sometimes, charts are needed in an application or web pages. Or it might be needed for a Word document, a PDF file, a PowerPoint presentation or some other application. In each case, you want to render the chart as an image so that you can use it elsewhere. Aspose.Cells for Android has supported converting charts in Excel files to image files since release 1.1.0.
//your code here...
// Converting an Excel Chart to Image
String sdCardPath = Environment.getExternalStorageDirectory().getPath()+ File.separator;
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
//Adding some sample value to cells
Cells cells = sheet.getCells();
Cell cell = cells.get("A1");
cell.setValue(50);
cell = cells.get("A2");
cell. setValue (100);
cell = cells.get("A3");
cell.setValue(150);
cell = cells.get("B1");
cell.setValue(4);
cell = cells.get("B2");
cell.setValue(20);
cell = cells.get("B3");
cell.setValue(50);
ChartCollection charts = sheet.getCharts();
//Adding a chart to the worksheet
int chartIndex = charts.add(ChartType.PYRAMID,5,0,15,5);
Chart chart = charts.get(chartIndex);
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
SeriesCollection serieses = chart.getNSeries();
serieses.add("A1:B3", true);
//Get the Chart image
ImageOrPrintOptions imgOpts = new ImageOrPrintOptions();
imgOpts.setImageFormat(ImageFormat.getEmf());
//Save the chart image.
chart.toImage(new FileOutputStream(sdCardPath + "MyChartImage.emf"), imgOpts);
Url: http://www.aspose.com/java/excel-component.aspx
Language: Java | User: Sheraz Khan | Created: Jan 21, 2015 | Tags: Convert Excel Chart to Image render chart as an image Excel Chart to Image in Android converting charts in Excel files to image Android Excel API Android Excel library