javaexcelapache-poisaxparser

<mergeCell> dont exist after parsing, even though there are merge cells in xlsx file


I'm using apache.poi to read .xlsx and .xlsm files in java. I started stucking with the familiar problem XSSFWorkbook wb = XSSFWorkbookFactory.createWorkbook(pkg) which takes several minutes to load single simple file, I tried solutions in all forms...then I moved to use XSSFReader and SAX parser, and it seems to be exactly what I've looked for. The Problem poped up again when I relized I need to get value from merged cells.

I saw in this post how to get the list of merge cells from the file, its seems to work fine with new files that I create, but when I parse the real file that was given to me- it doesn't have <mergeCells>/<mergeCell> at all!

I suspected that the file somehow doesn't have merge cells (even though it seems to have). I checked it with the traditional way (XSSFWorkbook- which takes tons of time) and sheet.getMergedRegions() returns ArrayList of 14 items.. i.e. it has merge cells...

What can I do? Whats the problem with my file? and how can I handle with it?


Solution

  • This is indeed as sily as it sounds, but my problem was... that I used code that processed only the first sheet.. and the sheet that contained the merge cells was the third one in the workbook..

    I leave the answer here for someone stuck with the same problem.