java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject Hatası

Aşağıdaki hatayı alıyorum

"main" iş parçacığında istisna: org/apache/xmlbeans/XmlObject at OrderBook.WriteToExcelSheet.CreateOutPutFile(WriteToExcelSheet.java:20) at OrderBook.MainMethod.main(MainMethod.java:71)

Bu hatanın nedenlerini internette araştırdım ancak neden aldığımı bulamadım.

Aşağıdaki jar dosyalarını ekledim

poi-3.9-20121203.jar, 
poi-excelant-3.9-20121203.jar,
poi-examples-3.9-20121203.jar,
poi-ooxml-3.9-20121203.jar,
poi-ooxml-schemas-3.9-20121203.jar,
poi-scratchpad-3.9-20121203.jar

Kod:

public class WriteToExcelSheet {
    public static Map < Integer, Object[] > data = new TreeMap < Integer, Object[] > ();
    public static void CreateOutPutFile() {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Orderbook Stats");
        //This data needs to be written (Object[])
        //Iterate over data and write to sheet
        Set < Integer > keyset = data.keySet()
        int rownum = 0;
        for (Integer key: keyset) {
            Row row = sheet.createRow(rownum++);
            Object[] objArr = data.get(key);
            int cellnum = 0;
            for (Object obj: objArr) {
                Cell cell = row.createCell(cellnum++);
                if (obj instanceof String) cell.setCellValue((String) obj);
                else if (obj instanceof Integer) cell.setCellValue((Integer) obj);
            }
        }
        try {
            //Write the workbook in file system
            System.out.println("OutPutStats.xlsx writing..............................");
            FileOutputStream out = new FileOutputStream(new File("FileLocation/o.xlxs"));
            workbook.write(out);
            out.close();
            System.out.println("OutPutStats.xlsx written successfully on disk.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}    
Çözüm

Bir kavanoz daha eklemelisiniz.

xmlbeans-2.3.0.jar

Bunu ekle ve dene.

Not: Sadece .xls formatları için değil, sadece .xlsx formatlı dosyalar için gereklidir.

Yorumlar (10)

Excel dosyasını .xlsx sonekiyle çevirmeye çalışırken, xmlbeansxxx.jar adında ek bir jar eklemeniz gerekir. xxxx sürümdür, örneğin xmlbeans-2.3.0.jar

Yorumlar (3)

Xmlbeans-2.3.0.jar eklediğiniz ve çalışmadığı her şey için, jar ekledikten sonra XSSFWorkbook yerine HSSFWorkbook kullanmalısınız;

    Workbook workbook = new HSSFWorkbook();
    Sheet listSheet = workbook.createSheet("Kişi Listesi");

    int rowIndex = 0;
    for (KayitParam kp : kayitList) {
        Row row = listSheet.createRow(rowIndex++);
        int cellIndex = 0;
        row.createCell(cellIndex++).setCellValue(kp.getAd());
        row.createCell(cellIndex++).setCellValue(kp.getSoyad());
        row.createCell(cellIndex++).setCellValue(kp.getEposta());
        row.createCell(cellIndex++).setCellValue(kp.getCinsiyet());
        row.createCell(cellIndex++).setCellValue(kp.getDogumtarihi());
        row.createCell(cellIndex++).setCellValue(kp.getTahsil());
    }

    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        workbook.write(baos);
        AMedia amedia = new AMedia("Kisiler.xls", "xls",
                "application/file", baos.toByteArray());
        Filedownload.save(amedia);
        baos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
Yorumlar (0)