小编Mih*_*ail的帖子

使用apache poi 3.7多次写入xlsx文档时出现异常

尝试.xlsx使用Apache POI 编写文件时,我收到以下异常:org.apache.xmlbeans.impl.values.XmlValueDisconnectedException

看来问题是第二次使用write()方法.使用HSSFWorkbook时,不会出现此问题.

这是代码:

public class SomeClass{

XSSFWorkbook workbook;

public SomeClass() throws IOException{
    File excelFile = new File("workbook.xlsx");

    InputStream inp = new FileInputStream(excelFile);
    workbook = new XSSFWorkbook(inp);
    inp.close();
}

void method(int i) throws InvalidFormatException, IOException {

    XSSFSheet sheet = workbook.getSheetAt(0);
    XSSFRow row = sheet.getRow(i);
    if (row == null) {
        row = sheet.createRow(i);
    }
    XSSFCell cell = row.getCell(i);
    if (cell == null)
        cell = row.createCell(i);
    cell.setCellType(Cell.CELL_TYPE_STRING);
    cell.setCellValue("a test");

    // Write the output to a file
    FileOutputStream fileOut …
Run Code Online (Sandbox Code Playgroud)

java excel apache-poi

19
推荐指数
2
解决办法
3万
查看次数

标签 统计

apache-poi ×1

excel ×1

java ×1