1

I have an Excel file of normal cells along with merged cells and a task to store each row in the Excel file to MySQL database. I am able to get data of each cell from Excel file and store in the database except data from merged cells. My java code:

FileInputStream input = new FileInputStream("/Users/test.xlsx");


        Workbook wb = WorkbookFactory.create(input);
        Sheet sheet = wb.getSheetAt(0);
for(i=0;i<no.ofrows;i++)
for(j=0;j<no.ofcolomns;j++)
{
  String var = String.valueOf(sheet.getRow(i).getCell(j));
}
Community
  • 1
  • 1
Labeo
  • 5,831
  • 13
  • 47
  • 77

2 Answers2

2

You may want to check Sheet#getMergedRegions() and Sheet#getMergedRegion(int index) JavaDoc.

izce
  • 189
  • 2
  • 10
  • How to get data from Merged region is it in the normal way or any other way is there – Labeo Oct 26 '15 at 05:59
  • Pardon! Is it a question? Since merged regions are handled differently than the usual cells you may need to develop a solution to read cell and range addresses in order to read the content in the order it is displayed. – izce Oct 26 '15 at 07:25
  • Can you provide any sample code or any resource that can manage (get data from)normal cells as well as merged cells – Labeo Oct 26 '15 at 08:56
  • How do you obtain no.ofrows and no.ofcolumns values in your example? – izce Oct 26 '15 at 09:27
  • Deepika's answer should be working for you. http://stackoverflow.com/a/29673497/4211402 . And yes it works even there is no merged columns. – izce Oct 26 '15 at 09:40
  • That doesnt work for a sheet having both merged cells and normal cells i have tried before – Labeo Oct 26 '15 at 10:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/93371/discussion-between-izce-and-labeo). – izce Oct 26 '15 at 14:18
0

Check out this link; HOW TO READ A NEW EXCEL SHEET for a tutorial to read excel xlsx files.

cdaiga
  • 4,861
  • 3
  • 22
  • 42