How to export Report to .csv file in NAV 2009 R2

Hello guys

I have a requirement where in all these days report was exported in pdf format but now user needs report to be also exported in .csv file.

I know how to export as excel file as I have worked on such many times. But exporting file as .csv is something new for reports I never worked on exporting as .csv in report but using dataports and xmlports I have done it earlier.

Does exporting as .csv file follows same procedure of exporting as excel file? I mean like assigning values to excel cells in temp excel buffer and defining required values or is there any other way to export as .csv in NAV 2009 R2?

It depends! Let me try to give you an overview.

The DataPort object was more or less build specifically to handle CSV files. NAV 2009 is the last version, where we have the DataPort object, where it only works for the classic clients. If you run it in the RTC, then it starts a classic client session and (while using two user sessions) runs the data port.

For the role tailored client you can use the XMLPort. Here Microsoft changed it, to allow to export CSV files (besides XML). Now you may say that the XMLPort also works in the classic client, which is correct. You just cannot use the CSV file option with the classic client.

If you had a newer version (NAV 2016 and up), then you could use the Data Exchange Framework (DEF) to create data define imports and exports, in a multitude of formats. Very easy to use, if you have first have made you familiar with DEF, which is not that easy.

The Excel Buffer table is just for Excel exports. Unless you want to want to write your own CSV-export function here. If you had a newer version (think it was NAV 2017), then there is also both a CSV Buffer and XML Buffer table, which could be used in the way as the Excel Buffer.

Report objects (and for that matter codeunits or almost any other object in NAV) can be used to write C/AL code which programmatically creates a CSV file. But that’s not some I would recommend, unless you have some very complex requirements.

So no it does not work the same was as exporting an Excel file. It’s generally much easier.

If the report you need to export is designed in a way that it would be difficult to do in an Data/XMLPort (depending on clients), then you could do technically as if you where using the Excel Buffer. Which mean while it creates and shows the report, then it also exports the file. What you need would actually be the CSV Buffer table, which is not available in your version.

An experienced senior NAV developer may be able to “down grade” the CSV Buffer functionality from NAV 2017, to work in NAV 2009. But unless you have done something similar before, then that’s not a journey I like to send you on.

I would recommend to keep it as simple as possible. If the design of the report can easily be turned into a DataPort/XMLPort, then that’s the easiest.