public static void main(String [] args){
String excelFilePath = "D:\\JavaBooks.xls";
try {
FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0);
Object[][] bookData = {
{"The Passionate Programmer", "Chad Fowler", 16},
{"Software Craftmanship", "Pete McBreen", 26},
{"The Art of Agile Development", "James Shore", 32},
{"Continuous Delivery", "Jez Humble", 41},
};
int rowCount = sheet.getLastRowNum();
for (Object[] aBook : bookData) {
Row row = sheet.createRow(++rowCount);
int columnCount = 0;
Cell cell = row.createCell(columnCount);
cell.setCellValue(rowCount);
for (Object field : aBook) {
cell = row.createCell(++columnCount);
if (field instanceof String) {
cell.setCellValue((String) field);
} else if (field instanceof Integer) {
cell.setCellValue((Integer) field);
}
}
}
inputStream.close();
FileOutputStream outputStream = new FileOutputStream("D:\\JavaBooks.xls");
workbook.write(outputStream);
workbook.close();
outputStream.close();
} catch (IOException | EncryptedDocumentException
ex) {
ex.printStackTrace();
}
}
}
При выполнении этого кода возникает ошибка Exception в потоке «main» java .lang.NoClassDefFoundError: org / apache / commons / math3 / util / ArithmeticUtils в org. apache .poi .poifs.property.RootProperty.setSize (RootProperty. java: 59) в орг. apache .poi.poifs.property.DirectoryProperty. (DirectoryProperty. java: 52) в орг. apache .poi. poifs.property.RootProperty. (RootProperty. java: 31) в орг. apache .poi.poifs.property.PropertyTable. (PropertyTable. java: 58) в орг. apache .poi.poifs. файловая система.POIFSFileSystem. (POIFSFileSystem. java: 102) в орг. apache .poi.poifs.filesystem.POIFSFileSystem. (POIFSFileSystem. java: 274) в орг. apache .poi.ss.usermodel. WorkbookFactory.create (WorkbookFactory. java: 252) в org. apache .poi.ss.usermodel.WorkbookFactory.create (WorkbookFactory. java: 221) в NewClass.main (NewClass. java: 31) Вызвано: java .lang.ClassNotFoundException: org. apache .commons.math3.util.ArithmeticUtils в java. net .URLClassLoader.findClass (URLClassLoader. java: 381) в java .lang.ClassLoader.loadClass (ClassLoader. java: 424) в sun.mis c .Launcher $ AppClassLoader.loadClass (Launcher. java: 335) в java .lang.ClassLoader.loadClass (ClassLoader. java: 357) ... еще 9