0

I have a lambda script that retrieves an email from s3, parses it with MailParser (streaming), transforms attachments to csv if necessary, and stores them in a different bucket. The script handles csv files (no conversion) and zip files, but I can't figure out how to convert xls to csv using streams.

Exceljs looks really good for this, but I can't get it to work for some reason (and I'm really new to streams so that's probably it).

var workbook = new Excel.Workbook();
var xstream = workbook.xlsx.createInputStream();
xstream.on('done', function(data) { 
  // convert to csv and s3.upload
});
attachment.stream
  .pipe(xstream);

I'm getting an error

Error: Unexpected xml node in parseOpen

before the 'done' event so I'm not sure if I'm using createInputStream correctly.

JorgePinon
  • 345
  • 2
  • 9
  • What does the documentation say? – tadman Jan 13 '17 at 19:38
  • _it works perfectly if the attachment is a plain csv_, do you mean it works perfectly int it's current state if you just comment out `.pipe(workbook.xlsx.createInputStream())`? – chrisbajorin Jan 13 '17 at 20:00
  • @cdbajorin I mean the upload function (uploadFromStream) correctly uploads when the input file is a simple csv, meaning it doesn't need transforming. Just pointing out that it's failing in the workbook step before that. – JorgePinon Jan 13 '17 at 20:34
  • @tadman, the docs just say "here's how you pipe from a stream" and "here's how you write to a stream", is what made me just try it the way I did. – JorgePinon Jan 13 '17 at 20:38
  • [Exceljs pipe xlsx from stream](https://github.com/guyonroche/exceljs#reading-xlsx) – JorgePinon Jan 13 '17 at 20:39

0 Answers0