Export report in csv

Hi,

is it possible to export a Report in csv ?

Regards

You can export the dataset properties of the report to CSV but not the actual report. You can only export the report to PDF, PNG or HTML.

Yes, I know that but thought it should be possible with some Java magic…Reportmill as some api for that but can’t seehow to use it.
We have reports with totals, summary, groups…and export only dataset is not an option.
Export to html should be an option, but the html format is not well formed for Excel. It renders well in web browser but not in excel.

Is it possible to use something like the following (source:RM support) ?

[quote]// Get template and generate report as normal
RMDocument template = new RMDocument(aSource);
RMDocument report = template.generateReport(myJavaDataset, false);

// Now get Excel or CSV bytes
byte excelBytes[] = report.getBytesExcel();
byte csvBytes[] = report.getBytesCSV();

// Or simply write Excel or CSV to a file String
report.writeExcel(“MyReport.xls”);
report.writeCSV(“MyReport.csv”);[/quote]

I see. We don’t expose a function to get the CSV bytes but it is possible to call that function:report = event.source.parent.getComponent('Report Viewer') csvBytes = report.getComponent(0).getViewport().getView().getDocument().getBytesCSV() system.file.writeFile("Path/to/test.csv", csvBytes)

1 Like

Thanks Travis. I knew the Magician would have a magic java call for that.
:prayer:

Is this still usable in Version 8.0?

Yes, that should still work in 8. I would recommend using our new function that would export data directly from the report to CSV:

csvBytes = system.report.executeReport(path="My Path", project="MyProject", parameters={}, fileType="csv")

Travis, that worked, but if the report is > 1 page, it reproduces the header over and over:

header
data
header
data
etc…

Is there a way to have it export all the data with only the header in the top row?
Thanks

But if you already have your report on report viewer and performing a .executeReport, maybe via button, will cause to execute again and this is not efficient.
If data could be stored after a report is generated in csvBytes, like pdfBytes, may be better.
Note:
I was trying to run:

report = event.source.parent.getComponent('Report Viewer') 
csvBytes = report.getComponent(0).getViewport().getView().getDocument().getBytesCSV()

but got exception at getViewport() in version 7.9.13.
I may ask, is there a way to convert pdfByte to csvByte with Ignition? the enconding utf8 seems not to be compatible.