cfsimplicity / spreadsheet-cfml

Standalone library for working with spreadsheets and CSV in CFML
MIT License
126 stars 35 forks source link

Illegal characters #365

Closed Daemach closed 6 months ago

Daemach commented 6 months ago

holdings_template (1).xlsx

Using the following code with the attached spreadsheet, we're seeing an odd error. Can you replicate? Oddly, I cannot find : when searching in excel.

Illegal char <:> at index 3: ram://temp13681.csv

  function spreadsheetToCSV( filePath, outputFile ) {
    var xls = getspreadsheet().read( expandPath( filePath ) );
    return getspreadsheet().writeToCsv( xls, outputFile );
  }
cfsimplicity commented 6 months ago

That's because you're trying to use a CFML virtual file system path (i.e. ram://temp13681.csv) for the CSV output. The CSV functionality uses Apache Commons CSV, so you need to use a physical path that java's BufferedWriter can work with.

cfsimplicity commented 6 months ago

If you can't avoid using a RAM path, then you could just generate the CSV string and then write it out yourself using CFML:

function spreadsheetToCSV( filePath, outputFile ) {
  var data = getspreadsheet().read( filePath, "query" );
  var csv = getspreadsheet().writeCsv().fromData( data ).execute();
  return FileWrite( outputFile, csv );
}
Daemach commented 6 months ago

Thanks, Julian!