Reputation: 35
I have a Excel template which I want to open, modify and save it like a normal book of Excel when I click in a button in a Jframe.
This is the code:
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
InputStream inp;
try {
inp = new FileInputStream("plantilla.xlt");
XSSFWorkbook wb = new XSSFWorkbook(inp);
XSSFSheet sheet = (XSSFSheet) wb.getSheetAt(1);
XSSFRow row = sheet.getRow(3);
XSSFCell cell1 = row.getCell(1);
XSSFCell cell2 = row.getCell(2);
cell1.setCellValue(0);
cell2.setCellValue(10000);
//FileOutputStream fileOut = new FileOutputStream("plantilla.xlt");
//wb.write(fileOut);
//fileOut.close();
} catch (IOException ioe) {
Logger.getLogger(DonnéesFE.class.getName()).log(Level.SEVERE, null,ioe);
}
}
This is new for me so I have a couple questions:
I have to put the whole file path to get the FileInputStream
? Is the extension .xlt
correct? Right now it doesn't find the file. I have tried with the normal .xlsx
extension and it finds it (I don't think it found the good file either) but I get this error on the definition of the workbook that I don't understand:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException.`
When I finish editing the Excel template how do I save it as a new Excel book? Everybody uses a new file to save the output but I think that won't work here.
Upvotes: 0
Views: 451