Exporting multiple DataTables to existing XLSX file gives error

Posted by: abacrotto on 20 August 2020, 10:54 am EST

  • Posted 20 August 2020, 10:54 am EST

    Hello:

    I am developing a component that uses ActiveReports 11 to export a SectionReport to a XLSX file (the report has colors, multiple pages with subreports, etc,). I want my code to export any and each of the subreports datasources in the same XLSX file. For that matter I use a C1FlexGrid 2.6 in which I assing each datasource and try to export a new Sheet with the subreport’s name. When the code reaches the first dataGrid.SaveExcel, it fails with the error:

    Exception Type:

    System.ArgumentException

    Message:

    Invalid Excel OpenXml file (*.xlsx).

    Source:

    C1.Win.C1FlexGrid.2

    TargetSite:

    Void Œ–(System.String, Boolean)

    StackTrace:

    en e‹.ƒ‹.Œ–(String msg, Boolean badArgument)

    en e‹.Œ.‹™(Boolean condition)

    en e‹.Œ.™(XmlReader reader, String domain)

    en e‹.Œ.(™ zipFile)

    en e‹.Œ.„”(™ zipFile, Boolean fillSheets)

    en e‹.Œ.ƒ”(™ zipFile, Boolean fillSheets)

    en e‹.Œ.ƒ”(String fileName, Boolean fillSheets)

    en e‹.ƒ‹.ƒ”(String fileName, ‹ format, Boolean fillSheets)

    en Š.˜Š.•“(C1FlexGridBase flex, String fileName, String sheetName, FileFlags flags, PrinterSettings ps)

    en C1.Win.C1FlexGrid.C1FlexGridBase.SaveExcel(String fileName, String sheetName, FileFlags flags)

    If I try to open the XLSX file generated by ActiveReports 11, it opens with no problem.

    Can you help me, please, to overcome this problem?

    Thanks in advance from Argentina.

    Ariel.

  • Posted 21 August 2020, 4:41 am EST

    Hello Ariel,

    Sorry, we do not face the issue at our end in exporting the FlexGrid to excel. I have attached a sample which is working fine at our end, please have a look and let me know if you are doing anything else.

    Note: The controls that you are using are of the very old version which is in maintenance mode now so I would recommend you upgrade your controls to the latest version.

    https://www.grapecity.com/forums/winforms-edition/net-framework-20-support-n_5

    Regards,

    Prabhat Sharma.

    ExportToExcelDemoFlexGrid.zip

  • Posted 21 August 2020, 10:22 am EST

    That kind of exportation DOES work in my test too. My problems begin when I try to use a file previously exported with Active Reports 11, from a SectionReport to an XLSX file with the AR Excel Exporter. I try to use that file and add more sheets to it using the c1FlexGrid SaveExcel method. This last operation, always fails.

    Thanks in advance.

    Regards.

    Ariel.

  • Posted 24 August 2020, 4:29 am EST

    Hi Ariel,

    Sorry, but we do not face the issue at our end when saving the FlexGrid to excel in an existing excel file generated via AR, from section report to XLSX.

    I have attached a sample implementing the same, please have a look.

    It will be very helpful for us to assist you in a better way if you could share the excel file with which you are having the issue.

    Regards,

    Prabhat Sharma.

    ExportToExcelDemoFlexGrid_Mod.zip

  • Posted 24 August 2020, 8:52 am EST

    You are not doing exactly what I do. In the first sample you exported from c1FlexGrig only. In the second one, you exported from an Active Reports Section Report only. What I want to do is a mix of both options: First I export the Section Report to a XLSX file (rep.xlsx). Then I try to ADD new sheets to that same file rep.xlsx using the SaveExcel method from the c1FlexGrig class. Those ADDs, always fail.

    Thanks.

    Ariel.

  • Posted 25 August 2020, 5:24 am EST

    Hello Ariel,

    We did not face any kind of error when using the excel file generated via SectionReport but we face another issue that when using the excel file generated via SectionReport, the SaveExcel method of FlexGrid does not append the sheet into the file and creates a new file which deletes the existing sheets.

    We have escalated this to the developers and will let you know once we get any update on this from their end.

    [Internal Tracking ID: 458706]



    Note: The fixes and the enhancements are made in the latest version only so you will have to upgrade your controls once it gets fixed.

    Regards,

    Prabhat Sharma.

Need extra support?

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

Learn More

Forum Channels