mashingan / excelin

Create and read Excel file purely in Nim
MIT License
51 stars 1 forks source link

Is there any 'get last-row' proc ? #6

Closed lanius412 closed 2 years ago

lanius412 commented 2 years ago

Now, I use following script

import excelin

proc getLastRow(sheet: Sheet, col: string):int =
 var rowNum:int = 1

 type tmp = object
 while sizeof(tmp) == 1:
   let value = sheet.row(rowNum).getCell[:string](col)
   if value == "":
     break
   inc(rowNum)
 result = rowNum - 1

if isMainModule:
  let excel = readExcel("src.xlsx")
  let sheet = excel.getSheet(excel.sheetNames()[0])

  let lastRow = sheet.getLastRow("A")
  echo lastRow

but, If there is a blank cell between cells with values, this proc will not work.

mashingan commented 2 years ago

Currently there's no API to get the last row but we can provide it for next version.
However, for the last-cell in particular row, this is quite tricky since internally the Excel holds the information based on row instead of column. After looking at your script, perhaps you might need the last-cell in row too.

lanius412 commented 2 years ago

Yes, I know the last-cell On my sheet, last-row of each col is the same. So I didn't need to consider. Thank you

mashingan commented 2 years ago

Should be added in v0.5.0 . Check the common operations example (before the end) to see how it works.

Since this changes some internal rows/cells, please comment or open new issue if there's regression. Thanks.