简体   繁体   English

在使用for循环合并单元格时,出现错误“ Excel在'file.xslx'中发现了不可读的内容”?

[英]while merging cells using for loop, i got an error “Excel found unreadable content in 'file.xslx' ”?

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();
}

I used this code in loop to create a merged cells but unfortunatley I got this error "Excel found unreadable content in 'dkdkd.xlsx' do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes." 我在循环中使用此代码创建了一个合并的单元格,但不幸的是,我收到此错误“ Excel在'dkdkd.xlsx'中发现了不可读的内容,您是否要恢复此工作簿的内容?如果您信任此工作簿的源,请单击“是” ”。

The problem is, that the merged regions overlap. 问题在于,合并区域重叠。 In first iteration you merge cells (1,1) to (1,2). 在第一次迭代中,您将单元格(1,1)合并为(1,2)。 In second (1,2) to (1,3). 在第二(1,2)至(1,3)中。 They overlap in (1,2). 它们在(1,2)中重叠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM