Excel Export

Posted by: codemasta on 14 September 2017, 7:05 pm EST

    • Post Options:
    • Link

    Posted 14 September 2017, 7:05 pm EST

    [activereports_archive]I have the following Problem with AR 7.3.7973.0

    I export rdlx Reports as Excel programmatically.

    When I use this:

    [csharp]var xlsExport = new XlsExport();

    xlsExport.PageSettings.PaperSize = GrapeCity.ActiveReports.Export.Excel.Section.PaperSizes.A4;

    // Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.

    xlsExport.FileFormat = FileFormat.Xls97Plus;

    xlsExport.UseCellMerging = true;[/csharp]

    Unfortunatily with this code the Data is being truncated in the exported cells (invisible data is cut off).

    I could solve this using this export code:

    [csharp] ExcelTransformationDevice renderingExtension = new ExcelTransformationDevice();

    MemoryStreamProvider provider = new MemoryStreamProvider();

    Settings settings = new Settings();

                    document.Render(renderingExtension, provider, settings);[/csharp]
    

    But now exporting of Fixed Layout Reports doesnt work anymore. All I get is the excel document you find in the attachment.

    I am somewhat stuck, because either version seems buggy.

    Any help appreciated![/activereports_archive]

    2015/12/Report-3.xls

  • Posted 14 September 2017, 7:05 pm EST

    [activereports_archive]Hello,

    I would like to inform you that the currently observed behavior(Export FPL to Excel using Excel transformation device produces no data document) is by design. ExcelTransformationDevice does not supports FPL Reports.

    The behavior for exporting FPL(now known as PageReports) to Excel has been improved in the later versions of the Product. Considering the latest ActiveReports release, AR10, if using RenderingExtensions to export the same PageReport to Excel, correct excel document is generated.

    AR10 download available at :

    http://activereports.grapecity.com/Downloads/

    Documentation link for more information on RenderingExtensions :

    http://arhelp.grapecity.com/webhelp/AR10/Rendering.html

    Regards,

    Reema[/activereports_archive]

  • Posted 14 September 2017, 7:05 pm EST

    [activereports_archive]Hi I will think about updating the product. Meanwhile is there a chance, I can find out if a Report is FPL or CPL by code? So I could select the appropriate export-behaviour.

    Thank you.[/activereports_archive]

  • Posted 14 September 2017, 7:05 pm EST

    [activereports_archive]Hello,

    You can check if your Report contains a FixedPage or not.

    If the ReportItems[0] returns a FixedPage, then it is an FPL else it is CPL(it returns the first control placed in the report Layout) :

    csharp.Name = “FixedPage1”;[/csharp]

    Hope it helps.

    Regards,

    Reema[/activereports_archive]

  • Posted 14 September 2017, 7:05 pm EST

    [activereports_archive]I could create a workaround with this code (someone may use it)

    When using Fixed Layout Reports I use the XlsExport class, otherwise the ExcelTransformationDevice.

    [csharp]using (var ms = new MemoryStream())

    {

    // If is Fixed Layout Report must render with XLsReport because of a limitation in ExcelTransaformationDevice

    if (report.Report.Body.ReportItems[0] is GrapeCity.ActiveReports.PageReportModel.FixedPage)

    {

    /// ****************** FIXED Page Reports *******************************

    // Export the report in XLSX format.

    var xlsExport = new XlsExport();

    xlsExport.PageSettings.PaperSize = GrapeCity.ActiveReports.Export.Excel.Section.PaperSizes.A4;

    // Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.

    xlsExport.FileFormat = FileFormat.Xls97Plus;

    xlsExport.UseCellMerging = true;

    xlsExport.Export(document, ms);

    ms.Flush();

    }

    else

    {

    /// ****************** STANDARD Page Reports *******************************

    // Set the rendering extension and render the report.

    ExcelTransformationDevice renderingExtension = new ExcelTransformationDevice();

    MemoryStreamProvider provider = new MemoryStreamProvider();

    Settings settings = new Settings();

                            document.Render(renderingExtension, provider, settings);
                            provider.GetPrimaryStream().OpenStream().CopyTo(ms);
                        }
                    
                        HttpContext.Response.AddHeader("content-disposition", string.Format("attachment; filename=Report.xls"));
                        return new FileStreamResult(new MemoryStream(ms.ToArray()), "application/vnd.ms-excel");
                    }[/csharp][/activereports_archive]
    
  • Posted 9 May 2020, 10:15 am EST

    Hi,

    Help to fix issue while export to excel.

    i’m using section report.

    my code is

    GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();

    // Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.

    XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;

    XlsExport1.Export(rpt.Document,“C://Files.xlsx”);

    Error Message:

    error-System.TypeInitializationException: The type initializer for ‘#tLD.#GOw’ threw an exception. —> System.IO.FileLoadException: Could not load file or assembly ‘DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    at #tLD.#GOw…cctor()

    — End of inner exception stack trace —

    at GrapeCity.SpreadBuilder.Workbook.#POw()

    at GrapeCity.SpreadBuilder.Workbook.Save(String filePath)

    at GrapeCity.ActiveReports.Export.Excel.Section.XlsExport.Export(SectionDocument document, String filePath, String pageRange)

    at GrapeCity.ActiveReports.Export.Excel.Section.XlsExport.Export(SectionDocument document, String filePath)

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels