如何在 netBeans 的现有项目中使用 Aspose.Cells?

How to use Aspose.Cells in existing project in netBeans?

我想将 excel sheet 数据转换为图像,目前我正在使用 awt 的二维图形,但它没有给我想要的结果。我读过 aspose.cells 可用于转换为图像,但是当我尝试实现它时会出现这样的错误 -

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)

我写的转换文件的代码是-

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;  
 }  
}

我已经包含 aspose.cells 7.0 jar,但仍然无法正常工作...请提前提供帮助和感谢。

Aspose Cells for Java 7.0 已经过时了。目前有18.7版。可能是版本 7.0 与您的 JDK 版本不兼容。请尝试使用最新版本的Aspose Cells,看看问题是否解决。