Export to Excel not working?

Stimulsoft Reports.JS discussion
Naico
Posts: 39
Joined: Wed Feb 21, 2018 9:52 am

Export to Excel not working?

Post by Naico »

We have a problem since one of the last Updates with exporting reports to excel.
Last time it worked was around 23.04.2018.
Now if we try to export from the JS webviewer the file 0kb large and if we try to open it
we get an error "The file 'Report.xlsx' can not be opened by Excel because the file format or file extension is invalid. Verify that the file is corrupted and that the file extension matches the file format."
If we Export to Csv or other formats it is working only with excel it wont work.

Here is the Code with which we try to export:

_export: function (type) {
var self = this,
format = Stimulsoft.Report.StiExportFormat.Pdf,
mimeType = 'application/pdf',
extension = 'pdf',
service = new Stimulsoft.Report.Export.StiPdfExportService(),
settings = new Stimulsoft.Report.Export.StiPdfExportSettings();

switch (type) {
case 'excel':
format = Stimulsoft.Report.StiExportFormat.Excel2007;
mimeType = 'application/ms-excel';
extension = 'xlsx';
service = new Stimulsoft.Report.Export.StiExcel2007ExportService(),
settings = new Stimulsoft.Report.Export.StiExcel2007ExportSettings();
settings.excelType = Stimulsoft.Report.Export.StiExcelType.ExcelXml;
break;
case 'csv':
format = Stimulsoft.Report.StiExportFormat.Csv;
mimeType = 'text/comma-separated-values';
extension = 'csv';
service = new Stimulsoft.Report.Export.StiCsvExportService(),
settings = new Stimulsoft.Report.Export.StiCsvExportSettings();
break;
}

var id = guid(),
stream = new Stimulsoft.System.IO.MemoryStream(),
//result = self.report.exportDocument(format/*, settings*/),
fileName = self.report.reportName + '.' + extension;

service.exportTo(self.report, stream, settings);
var result = stream.toArray();

$(self.element[0]).downloader({}).downloader('addDocument', id, fileName, result.length, mimeType, 'test', {});
$(self.element[0]).downloader({}).downloader('addChunk', id, 0, result.length, result);
Naico
Posts: 39
Joined: Wed Feb 21, 2018 9:52 am

Re: Export to Excel not working?

Post by Naico »

As additional information: The report is rendered on a server and send to client as JSON string.
Displaying on the client is working.
Lech Kulikowski
Posts: 6266
Joined: Tue Mar 20, 2018 5:34 am

Re: Export to Excel not working?

Post by Lech Kulikowski »

Hello,

Please send us a sample project which reproduces the issue for analysis on support@stimulsoft.com

Thank you.
Naico
Posts: 39
Joined: Wed Feb 21, 2018 9:52 am

Re: Export to Excel not working?

Post by Naico »

I am unable to send a sample project because of customer data.
If we open the file with the stimulsoft viewer it is empty except the headers
since the dataSet isnt filled. There does the export work only with the web
viewer it doesnt work even if we dont use our own button and function, but
also if we use the save button of the web viewer.
Lech Kulikowski
Posts: 6266
Joined: Tue Mar 20, 2018 5:34 am

Re: Export to Excel not working?

Post by Lech Kulikowski »

Hello,

To say something about the issue and fix it we need sample which reproduces it.
You can make necessary changes in one of our samples that issue will reproducible and send us for analysis.
https://github.com/stimulsoft/Samples-JS

Thank you.
Naico
Posts: 39
Joined: Wed Feb 21, 2018 9:52 am

Re: Export to Excel not working?

Post by Naico »

The problem is not with the report.
If we open the report with the installed viewer and export (DataSet is empty so all you can see is the base structure)
it is working. The problem is only with the JS WebViewer Export.
I dont know how to reproduce a sample since the program structure is not the same.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Export to Excel not working?

Post by HighAley »

Hello.

It seems that our scripts crash because of an error.
We don't see code where you load and render the report.
Could you try to call the render() method and save the report document.
Do you get the right report?

Please, try to use the async methods.
In some cases async methods are used during report rendering and exporting.

Code: Select all

report.renderAsync(function () {
     var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
     var service = new Stimulsoft.Report.Export.StiPdfExportService();
     var stream = new Stimulsoft.System.IO.MemoryStream();
     for (var index = 1; index <= report.renderedPages.count; ++index) {
          settings.pageRange = new Stimulsoft.Report.StiPagesRange(Stimulsoft.Report.StiRangeType.Pages, index.toString());
          service.exportTo(report, stream, settings);
          var data = stream.toArray();
          var fileName = index;
          Object.saveAs(data, fileName + ".pdf", "application/pdf");
     }
});
Thank you.
Naico
Posts: 39
Joined: Wed Feb 21, 2018 9:52 am

Re: Export to Excel not working?

Post by Naico »

Here is the full script. we render the Report in the _create function.
only part I deleted for this post is the key for Stimulsoft.Base.StiLicense.key = "";
we will try it with the async methods.
The web viewer is showing the loaded report correctly.

Code: Select all

(function ($, undefined) {
  $.widget('ui.reportviewer', {
    options: {
      data: null,
      exportEnabled: true,
      exportFormats: ['pdf', 'excel']
    },
    _create: function () {
      var self = this,
        $self = $(self.element[0]),
        options = this.options,
        report = (this.report = null),
        viewer = (this.viewer = null),
        init = function () {
          $self.addClass(self._css.container);
          title = $(document).attr(self._tags.title);

          try {
            Stimulsoft.Base.StiLicense.key = "";

            var viewerOptions = new Stimulsoft.Viewer.StiViewerOptions();
            viewerOptions.showExportDialog = true;
            //viewerOptions.toolbar.visible = false;
            viewerOptions.toolbar.viewMode = Stimulsoft.Viewer.StiWebViewMode.Continuous;

            self.viewer = new Stimulsoft.Viewer.StiViewer(viewerOptions, 'StiViewer', false);
            $shadow.hide();
            self.viewer.renderHtml($self[0].id);
            self.viewer.showProcessIndicator();

            self.report = new Stimulsoft.Report.StiReport();
            self.report.loadDocument(options.data);

            self.viewer.report = self.report;

            self.report.pages[0];

            $('.stiJsViewerReportPanel').css('overflow', 'auto');

            if (options.exportEnabled) {
              var $commandBar = $(self._tags.div)
                .addClass(self._css.commandBar)
                .prependTo($self),
                $exportExcel = $(self._tags.div)
                  .addClass(self._css.command)
                  .addClass(self._css.export)
                  .addClass(self._css.excel)
                  .attr(self._tags.title, 'als Excel-Datei speichern')
                  .on('click', function () { self._export('excel'); })
                  .appendTo($commandBar);
            }

            self.viewer.hideProcessIndicator();
          } catch (e) {
            logManager.error('Fehler beim Laden des Report-Designers', e);
          }
        };

      $.extend(this, widgetBase, {
        _css: {
          container: options.css && options.css.container ? options.css.container : 'ui-reportviewer',
          commandBar: options.css && options.css.commandBar ? options.css.commandBar : 'commandBar',
          command: options.css && options.css.command ? options.css.command : 'command',
          export: options.css && options.css.export ? options.css.export : 'form-icon',
          excel: options.css && options.css.excel ? options.css.excel : 'excel',
          shadow: options.css && options.css.shadow ? options.css.shadow : 'shadow',
          loading: options.css && options.css.loading ? options.css.loading : 'loading'
        }
      });

      var $shadow = $(self._tags.div).addClass(self._css.loading).appendTo($(self._tags.div).addClass(self._css.shadow).appendTo($self));
      registerAPI('/Scripts/Report/stimulsoft.reports.js', function () {
        registerAPI('/Scripts/Report/stimulsoft.viewer.js', init);
      });
    }, 
    _destroy: function () {
      $.Widget.prototype.destroy.call(this);
    },
    _export: function (type) {
      var self = this,
        format = Stimulsoft.Report.StiExportFormat.Pdf,
        mimeType = 'application/pdf',
        extension = 'pdf',
        service = new Stimulsoft.Report.Export.StiPdfExportService(),
        settings = new Stimulsoft.Report.Export.StiPdfExportSettings();

      switch (type) {
        case 'excel':
          format = Stimulsoft.Report.StiExportFormat.Excel2007;
          mimeType = 'application/ms-excel';
          extension = 'xlsx';
          service = new Stimulsoft.Report.Export.StiExcel2007ExportService(),
          settings = new Stimulsoft.Report.Export.StiExcel2007ExportSettings();
          settings.excelType = Stimulsoft.Report.Export.StiExcelType.ExcelXml;
          break;
        case 'csv':
          format = Stimulsoft.Report.StiExportFormat.Csv;
          mimeType = 'text/comma-separated-values';
          extension = 'csv';
          service = new Stimulsoft.Report.Export.StiCsvExportService(),
          settings = new Stimulsoft.Report.Export.StiCsvExportSettings();
          break;
      }

      var id = guid(),
        stream = new Stimulsoft.System.IO.MemoryStream(),
        //result = self.report.exportDocument(format/*, settings*/),
        fileName = self.report.reportName + '.' + extension;

      service.exportTo(self.report, stream, settings);
      var result = stream.toArray();

      $(self.element[0]).downloader({}).downloader('addDocument', id, fileName, result.length, mimeType, 'test', {});
      $(self.element[0]).downloader({}).downloader('addChunk', id, 0, result.length, result);
    }
  });
}(jQuery));
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Export to Excel not working?

Post by HighAley »

Hello.

There two possible cases.

One is that the report could not be rendered or exported in time.
So you get the zero file.

Another one is that the rendering or exporting is crashed.

Please, try the async methods at first.

Thank you.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Export to Excel not working?

Post by HighAley »

Hello.

There was an issue with the images.
Please, try to our next build that will be available in a few days.

Thank you.
Post Reply