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.
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 = cells.get("A2");
cell. setValue (100);
cell = cells.get("A3");
cell = cells.get("B1");
cell = cells.get("B2");
cell = cells.get("B3");
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();
//Get the Chart image
ImageOrPrintOptions imgOpts = new ImageOrPrintOptions();
//Save the chart image.
chart.toImage(new FileOutputStream(sdCardPath + "MyChartImage.emf"), imgOpts);
Overview: Aspose.Cells for Android
Aspose.Cells for Android is a MS Excel spreadsheet component that allows programmer to develop android applications for reading, writing & manipulate Excel spreadsheets (XLS, XLSX, XLSM, SpreadsheetML, CSV, tab delimited) and HTML file formats without needing to rely on Microsoft Excel. It supports robust formula calculation engine, pivot tables, VBA, workbook encryption, named ranges, custom charts, spreadsheet formatting, drawing objects like images, OLE objects & importing or creating charts.
- Homepage of Aspose.Cells for Android
Aspose.Cells for Android