1
votes
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."

1
That does not look like excel-vba code. Check your tags.Ron Rosenfeld

1 Answers

0
votes

The problem is, that the merged regions overlap. In first iteration you merge cells (1,1) to (1,2). In second (1,2) to (1,3). They overlap in (1,2).