Android Question aPOI lib: how to create a new XLSX sheet row?

peacemaker

Expert
Licensed User
Longtime User
HI, All, and @DonManfred,
Lib v.0.11 (thanks for the lib again !).

Opening .xlsx file is OK, but i'm trying to merge rows and creating the new .xlsx file.
B4X:
    Dim nwb As XSSFWorkbook
    nwb.Initialize2("")
    Dim wrSheet As XLSSheet = nwb.createSheet2("new_sheet")
    Dim rowOUT As XSSFRow = wrSheet.createRow(0)  'HERE ERROR: java.lang.IllegalArgumentException: Invalid row number (-1) outside allowable range (0..1048575)

Row is not created.
Maybe something forgotten to prepare ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Yes, rows index is starting from 1 if to create, but reading is from 0.

Sheets index is starting from 0.
Cells index is starting from 1.
Strange that the created new .xlsx file is 0-sized:

B4X:
    Dim nwb As XSSFWorkbook
    nwb.Initialize2("")
    Dim wrSheet As XLSSheet = nwb.createSheet2("new_sheet_of_new_book")
    Dim rowOUT As XSSFRow = wrSheet.createRow(1)    'zero index is wrong
    Dim wrCell As XSSFCell = rowOUT.createCell(0)
    wrCell.StringCellValue = "hi, B4A XLSX world!"
    nwb.write2(File.DirRootExternal, "created_new_book.xlsx")
    nwb.close

    nwb.Initialize("", File.Combine(File.DirRootExternal, "created_new_book.xlsx"))  'error - 0-sized file cannot be open
    Dim sheet As XLSSheet = nwb.getSheetAt(0)
    Dim row As XSSFRow = sheet.getRow(0)
    Dim cell As XSSFCell = row.getCell(0)
    Log(cell.toString)
 
Last edited:
Upvote 0
Top