【问题标题】:while merging cells using for loop, i got an error "Excel found unreadable content in 'file.xslx' "?使用 for 循环合并单元格时,出现错误“Excel 在 'file.xslx' 中发现不可读的内容”?
【发布时间】:2014-10-27 20:56:44
【问题描述】:
Workbook book=new XSSFWorkbook();
    Sheet sheet=book.createSheet("my");
    for (int i = 0; i < 10; i++) {

            sheet.createRow(1).createCell(i);
            sheet.addMergedRegion(new CellRangeAddress(1,(short)1,i,(short)i+1));


    }
     FileOutputStream out = new FileOutputStream("D:\\CIT\\Library\\mysample.xlsx");
        book.write(out);
        out.close();
}

我在循环中使用此代码创建合并单元格,但不幸的是,我收到此错误“Excel 在 'dkdkd.xlsx' 中找到不可读的内容,是否要恢复此工作簿的内容?如果您信任此工作簿的来源,单击是。”

【问题讨论】:

  • 这看起来不像 excel-vba 代码。检查你的标签。

标签: excel vba


【解决方案1】:

问题是,合并的区域重叠。在第一次迭代中,您将单元格 (1,1) 合并到 (1,2)。在第二(1,2)到(1,3)。它们在 (1,2) 中重叠。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 2011-03-11
    • 1970-01-01
    • 2017-01-02
    • 2014-01-23
    相关资源
    最近更新 更多