I am trying to put a title in cell (0,0) and then use a for()
loop to add file paths into each following row. However, I am only able to add one line of code; after the title, no other cells in the Excel document are modified.
Here's where I create the file:
private void chooseSheetActionPerformed(java.awt.event.ActionEvent evt) {
sheetNum = chooseSheet.getSelectedIndex() - 1;
try {
WritableWorkbook workbook = Workbook.createWorkbook(newXls);
workbook.createSheet("Sheet1", 0);
workbook.write();
workbook.close();
writeXls();
} catch (Exception ex) {
Logger.getLogger(NewScore.class.getName()).log(Level.SEVERE, null, ex);
}
}
And here's where I try to write to it:
public void writeXls() throws Exception {
Workbook wb = Workbook.getWorkbook(newXls);
WritableWorkbook copy = Workbook.createWorkbook(newXls, wb);
WritableSheet ws = copy.getSheet(sheetNum);
WritableCell cell;
// Body Part - Title
Label lab = new Label(0,0,partName);
cell = (WritableCell) lab;
ws.addCell(cell);
copy.write();
// Image Info
int i = 1;
for (File file : imageArray(dir)) {
Label label = new Label (0,i,"test" + i);
cell = label;
ws.addCell(cell);
copy.write();
i++;
}
copy.close();
}
Is there a way to make my for()
loop work, or do I need to go about this a different way?
Thanks!