Exporting data using the Excel Buffer
NAV contains a wrapper object that allows you to export data to Microsoft Excel. This recipe will show you how to use it in its most common form—exporting a report to Excel.
Getting ready
Microsoft Excel must be installed on the client machine.
How to do it...
Create a new processing-only report based on the
Customer
table.Add values in the
No.
,Name
, andBalance
fields.Add the following global variables:
Name
Type
SubType
ExcelBuf
Record
Excel Buffer
Let's set the property
Temporary
of theExcelBuf
variable toYes
.Now add a function named
MakeExcelInfo
.Add the following code to the function:
ExcelBuf.SetUseInfoSheet; ExcelBuf.AddInfoColumn(FORMAT('Company Name'),FALSE,'',TRUE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text); ExcelBuf.AddInfoColumn(COMPANYNAME,FALSE,'',FALSE,FALSE, FALSE,'',ExcelBuf."Cell Type"::Text); ExcelBuf.NewRow; ExcelBuf.AddInfoColumn(FORMAT('Report Name'), FALSE,'',TRUE,FALSE,FALSE,'',ExcelBuf."Cell Type"::Text); ExcelBuf.AddInfoColumn...