Writing to an Existing Excel File

后端 未结 1 1557
执笔经年
执笔经年 2020-12-31 23:22
 package jexcel.jxl.nimit;

    import java.awt.Label;  
    import java.io.File;  
    import java.io.IOException;

    import jxl.Cell;   
    import jxl.CellType;         


        
相关标签:
1条回答
  • 2021-01-01 00:10

    LabelCell is just an interface with only one method i.e getString() you can learn more about it here

    You should use jxl.write.Label instead.
    What you should exactly do is as follows
    You should import the following file

    import jxl.write.Label
    

    Then following is the code for adding a cell at desired location to an excel file

    Workbook existingWorkbook = Workbook.getWorkbook(new File(fileToEdit.getAbsolutePath()));
    WritableWorkbook workbookCopy = Workbook.createWorkbook(new File("output.xls"), existingWorkbook);
    WritableSheet sheetToEdit = workbookCopy.getSheet(sheetName);
    WritableCell cell;
    Label l = new Label(currentColumn, currentRow, value);
    cell = (WritableCell) l;
    sheetToEdit.addCell(cell);
     workbookCopy.write();
     workbookCopy.close();
     existingWorkbook.close();
    

    currentColumn and currentRow define the index and value contains the String to be placed in that cell.

    Hope it helps

    0 讨论(0)
提交回复
热议问题