I have an existing excel sheet and I am trying to read it and put it in my list. But, there are merged cells so i wanted to unmerge before storing it in my list. I tried the removeMergedRegion() method but it didn't work. when i open the excel sheet after the process i wanted the cells to be unmerged. And if possible after the unmerge the empty cell should be deleted.
public void newone(){
//calling my existing excel file
File file = new File("C:\\Users\\daisy\\Downloads\\What.xlsx");
FileInputStream fis;
try {
fis = new FileInputStream(file);
Workbook workbook = new XSSFWorkbook(fis);
// Iterate through all merged region in the sheet
Sheet sheet = workbook.getSheet("Sheet1");
for(int i=0; i < sheet.getNumMergedRegions(); i++)
{
// Delete the region
sheet.removeMergedRegion(i);
System.out.println("Unmerged successfully");
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}