# Export report in csv

**URL:** <https://forum.inductiveautomation.com/t/export-report-in-csv/5906>\
**Category:** Ignition\
**Created:** [February 21, 2013, 6:58pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906 "2013-02-21T18:58:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnguyen](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gnguyen](https://forum.inductiveautomation.com/u/gnguyen)\
**Post date:** [February 21, 2013, 6:58pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/1 "2013-02-21T18:58:11Z")

</div>

Hi,

is it possible to export a Report in csv ?

Regards

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 22, 2013, 5:25pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/2 "2013-02-22T17:25:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gnguyen](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gnguyen](https://forum.inductiveautomation.com/u/gnguyen)\
**Post date:** [February 22, 2013, 5:35pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/3 "2013-02-22T17:35:10Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 22, 2013, 8:25pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/4 "2013-02-22T20:25:55Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![gnguyen](https://avatars.discourse-cdn.com/v4/letter/g/41988e/32.png) [@gnguyen](https://forum.inductiveautomation.com/u/gnguyen)\
**Post date:** [February 22, 2013, 8:42pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/5 "2013-02-22T20:42:01Z")

</div>

Thanks Travis. I knew the Magician would have a magic java call for that.  
 ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:")

---

<div class="post-metadata">

**Author:** ![drinaldi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drinaldi/32/32068_2.png) [@drinaldi](https://forum.inductiveautomation.com/u/drinaldi)\
**Post date:** [January 27, 2020, 4:02pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/6 "2020-01-27T16:02:13Z")

</div>

> [@Travis.Cox](#):
>
> 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)`

Is this still usable in Version 8.0?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [January 27, 2020, 4:15pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/7 "2020-01-27T16:15:28Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![drinaldi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drinaldi/32/32068_2.png) [@drinaldi](https://forum.inductiveautomation.com/u/drinaldi)\
**Post date:** [January 27, 2020, 6:45pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/8 "2020-01-27T18:45:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 19, 2021, 6:08pm UTC](https://forum.inductiveautomation.com/t/export-report-in-csv/5906/9 "2021-02-19T18:08:24Z")

</div>

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:

```auto
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.
