excelcsvcoldfusion

How can I iterate through all cells in a ColdFusion spreadsheet object?


I have a spreadsheet object created with SpreadsheetNew(...), and I'm trying to convert it to CSV. But since there doesn't seem to be any way to do so automatically, I'll have to iterate through all rows and columns of the spreadsheet to construct the CSV manually.

However, I can't find any information on how to either loop through a spreadsheet or how to get the row/column counts — the little information I can find seems to be outdated, and I can't find anything relevant in the documentation.

How can I:

  1. get the row and column counts so that I can get all the cell values with SpreadsheetGetCellValue;
  2. iterate through all rows and columns of the spreadsheet in some other way; or
  3. convert the spreadsheet to CSV without having to do it manually.

I'm running ColdFusion 2021, version 2021,0,13,330286.


Solution

  • I solved — or rather, circumvented — the issue by changing the code that generates the Spreadsheet to create a 2D array instead (ArrayNew(2)), which can then easily be converted to either a Spreadsheet or a CSV, depending on what is needed.