Export into the File (xlsx or csv)

Hi ,

One of my existing reports is this possible can export the output directly into xlsx/csv instead of using 'SaveAs' Export feature.
The reason why the file is too big and once its Save As it's lost the alignment.
I like to write the vbcode/script into Button and simply generate the output in the specified location
Thanks
FArhan

Comments

  • edited 1:24AM
    Any routine or VB code please?
  • Hello!

    Here is a VB.NET code example for a button handler:

    
    Imports FastReport
    Imports FastReport.Export.OoXML
    Imports FastReport.Export.Csv
    
    Private Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click
    Using report As New Report()
    report.Load(«C:\Reports\MyReport.frx»)
    ' report.RegisterData(myDataSet, «MyData»)
    
    report.Prepare()
    
    Using xlsxExport As New Excel2007Export()
    xlsxExport.ShowProgress = False
    xlsxExport.Wysiwyg = True
    xlsxExport.DataOnly = False
    report.Export(xlsxExport, «C:\Output\Report.xlsx»)
    End Using
    
    ' 2. Экспорт в CSV (.csv)
    Using csvExport As New CSVExport()
    csvExport.ShowProgress = False
    csvExport.Separator = «;»
    csvExport.DataOnly = True
    report.Export(csvExport, «C:\Output\Report.csv»)
    End Using
    End Using
    End Sub
     
    
    

    Tip regarding loss of alignment and file size in Excel:

    If the exact appearance is important, leave `xlsxExport.Wysiwyg = True`, and also make sure that the objects in the .frx template are aligned to the common grid (identical `Left`, `Width`, `Top`, and `Height` values without overlapping); otherwise, exporting to Excel will create many small auxiliary columns and rows.

    If you need the file specifically as a flat table for data processing (without extra alignment columns and with minimal size), set `DataOnly = True` (in Excel2007Export or CSVExport).

This discussion has been closed.