I want to convert excel sheet data to image and currently I was working with graphics 2D of awt but it is not giving me desired result. I have read that aspose.cells can be used for converting to image but when I try to implement it gives me error like this-
Exception in thread "main" java.lang.NoSuchMethodError: sun.font.FontManager.getFontPath(Z)Ljava/lang/String;
at com.aspose.cells.a.c.cf.p(Unknown Source)
at com.aspose.cells.a.c.cf.<init>(Unknown Source)
at com.aspose.cells.eY.<init>(Unknown Source)
at com.aspose.cells.vm.a(Unknown Source)
at com.aspose.cells.SheetRender.<init>(Unknown Source)
at com.boolment.dataentry.ExcelTesting.generateImages(ExcelTesting.java:28)
at com.boolment.dataentry.ExcelTesting.main(ExcelTesting.java:16)
The code I have written for converting file is-
package com.boolment.dataentry;
import com.aspose.cells.ImageFormat;
import com.aspose.cells.ImageOrPrintOptions;
import com.aspose.cells.SheetRender;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import com.aspose.cells.WorksheetCollection;
import java.util.ArrayList;
import java.util.List;
public class ExcelTesting {
public static void main(String s[]) throws Exception{
ExcelTesting et = new ExcelTesting();
String sourcePath = "C:\\Users\\TANISHA AGARWAL\\Downloads\\EXCEL FORMAT.xls";
et.generateImages(sourcePath);
}
public void generateImages(final String sourcePath) {
try {
Workbook workbook = new Workbook(sourcePath);
List<Worksheet> worksheets = getAllWorksheets(workbook);
if (worksheets != null) {
int noOfImages = 0;
for (Worksheet worksheet : worksheets) {
if (worksheet.getCells().getCount() > 0 || worksheet.getCharts().getCount() > 0 || worksheet.getPictures().getCount() > 0) {
String imageFilePath = sourcePath + "_output_" + (noOfImages++) + ".jpeg";
SheetRender sr = new SheetRender(worksheet, getImageOrPrintOptions());
sr.toImage(0, imageFilePath);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private List<Worksheet> getAllWorksheets(final Workbook workbook) {
List<Worksheet> worksheets = new ArrayList<Worksheet>();
WorksheetCollection worksheetCollection = workbook.getWorksheets();
for (int i = 0; i < worksheetCollection.getCount(); i++) {
worksheets.add(worksheetCollection.get(i));
}
return worksheets;
}
private ImageOrPrintOptions getImageOrPrintOptions() {
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(ImageFormat.getJpeg());
imgOptions.setOnePagePerSheet(true);
return imgOptions;
}
}
I have include aspose.cells 7.0 jar but still its not working...Please help and Thanks in advance.