mardi 25 janvier 2022

Detecting last column and last row with Xlnt library in a xlsx file

I am trying to use the Xlnt library to create and manipulate some xlsx files.
There are functions in this library that let you know which one it is the last not empty column and the last not empty row?
Here is a code example:

#include <xlnt/xlnt.hpp>
#include <string>
#include <iostream>

int main ()
{
     xlnt::workbook wb;
     xlnt::worksheet ws = wb.active_sheet();
     ws.cell("AB1").value(5);
     ws.cell("B12").value("string data");
     ws.cell("C3").formula("= AB1 + B12");
     wb.save("example.xlsx");
     std::string lastColumn = ws.last_column();     // exists similar function?
     size_t lastRow = ws.last_row();                // exists similar function?
     std::cout << lastColumn << ' ' << lastRow << std::endl;

     return 0;
}

Reading the code it is clear that the last column is "AB" and the last row is 12, but obviously the program does not know which cells have contents of any type.

Aucun commentaire:

Enregistrer un commentaire