2

For some time I've wondered if/when this module could get some introspection abilities, beyond just hacking on the object.

For example:

Once a sheet has been written, how can I know query the sheet object to know things like how many rows and columns it has?

What I want to do is write a number of sheets, then go back to each and write more rows to them. I could keep track of last row/column on my own, but before I do that I'm wondering if I can get that data from the already-written objects, before the final workbook->close.

I think I could count the number of keys in a sheet object's _table hash, but that may be too close to the metal to be "official." I remember John saying not to do that somewhere in the CPAN docs.

tomatoguy
  • 31
  • 1
  • welcome :) could you please add some of the code you already tried to enrich and clarify your question? – Bilel Feb 25 '20 at 00:34
  • See also [Spreadsheet::ParseXLSX](https://metacpan.org/pod/Spreadsheet::ParseXLSX) – Håkon Hægland Feb 25 '20 at 08:26
  • The author is very communicative and often answers questions here too. If you have concrete questions like this, you can actually just email him. He's very open to discourse in my experience. – simbabque Feb 25 '20 at 12:12
  • My code would be simple: create and write a sheet. Then later, add more rows to the sheet, by asking the sheet how many rows it has (rather than tracking rows manually). Ii can be done with die 'Last row is: ' . ( 1 + ( sort{ $a <=> $b } keys %{ $sheet->{ _table } } )[ -1 ] ). "\n"; but that's getting intimate. I've had good luck with messages to John in the last, but I thought I'd ask here first. – tomatoguy Feb 25 '20 at 21:20

1 Answers1

2

I could keep track of last row/column on my own, but before I do that I'm wondering if I can get that data from the already-written objects, before the final workbook->close.

No. That isn't possible. Excel::Writer::XLSX doesn't provide any tools for introspecting the data once it crosses the APIs. This is a deliberate design decision. You should treat an Excel::Writer::XLSX object as a black box and not some sort of database.

The best way to do what you want is to track the range data in your program.

jmcnamara
  • 38,196
  • 6
  • 90
  • 108
  • Fair enough about the black box, but why not at least a couple of "official" methods to get this kind of data, being that it's so trivial to do? – tomatoguy Mar 02 '20 at 18:06
  • No addition to the APIs is trivial. It all takes code and tests and docs and some forethought. Which takes time and effort that could be spent on features that the users can't implement in their own application. – jmcnamara Mar 03 '20 at 09:03
  • OK. When the time comes I'm happy to volunteer with what I've developed for making the spreadsheets I need to make. – tomatoguy Mar 04 '20 at 17:25