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