java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19739026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject Error
提问by user2942227
I am getting following error
我收到以下错误
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject at OrderBook.WriteToExcelSheet.CreateOutPutFile(WriteToExcelSheet.java:20) at OrderBook.MainMethod.main(MainMethod.java:71)
线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject at OrderBook.WriteToExcelSheet.CreateOutPutFile(WriteToExcelSheet.java:20) at OrderBook.MainMethod.main(MainMethod.java:71)
I looked for the reasons for this error online but couldn't find why I am getting it.
我在网上查找了此错误的原因,但找不到我收到此错误的原因。
I have included the following jar files
我已经包含了以下 jar 文件
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
Code:
代码:
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();
}
}
}
采纳答案by Jhanvi
You have to include one more jar.
你必须再包括一个罐子。
xmlbeans-2.3.0.jar
Add this and try.
添加这个并尝试。
Note:It is required for the files with .xlsx formats only, not for just .xls formats.
注意:仅 .xlsx 格式的文件需要它,而不仅仅是 .xls 格式的文件。
回答by MouseLearnJava
When trying to translate Excel file with .xlsx suffix, you need to add additional jar, xmlbeansxxx.jar. xxxxis version, such as xmlbeans-2.3.0.jar
尝试翻译带有 .xlsx 后缀的 Excel 文件时,您需要添加额外的 jar,xmlbeansxxx.jar。xxxx是版本,如xmlbeans-2.3.0.jar
回答by emreturka
For all that you add xmlbeans-2.3.0.jar and it is not working,you must use HSSFWorkbook instead of XSSFWorkbook after add jar.For instance;
对于所有添加 xmlbeans-2.3.0.jar 但它不起作用的情况,您必须在添加 jar 后使用 HSSFWorkbook 而不是 XSSFWorkbook。例如;
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();
}
回答by Amit baderia
You need to include xmlbeans-xxx.jar and if you have downloaded the POI binary zip, you will get the xmlbeans-xxx.jar in ooxml-lib folder (eg: \poi-3.11\ooxml-lib)
您需要包含 xmlbeans-xxx.jar,如果您已经下载了 POI 二进制 zip,您将在 ooxml-lib 文件夹中获得 xmlbeans-xxx.jar(例如:\poi-3.11\ooxml-lib)
This jar is used for XML binding which is applicable for .xlsx files.
此 jar 用于 XML 绑定,适用于 .xlsx 文件。
回答by Arslan Ahmad
you have to include two more jar files.
您必须包含另外两个 jar 文件。
xmlbeans-2.3.0.jar and dom4j-1.6.1.jar Add try it will work.
xmlbeans-2.3.0.jar 和 dom4j-1.6.1.jar 添加试试就行了。
Note: It is required for the files with .xlsx formats only, not for just .xlt formats.
注意:仅 .xlsx 格式的文件需要它,而不仅仅是 .xlt 格式的文件。
回答by Rashmi A
I faced a similar situation, so i replaced all the external jar files(poi-bin-3.17-20170915
) and make sure you add other jar
files present in lib and ooxml-lib
folders.
我遇到了类似的情况,所以我替换了所有外部 jar 文件(poi-bin-3.17-20170915
)并确保添加jar
了 lib 和ooxml-lib
文件夹中存在的其他文件。
Hope this helps!!!:)
希望这可以帮助!!!:)