Export hidden columns

Posted by: parmarkinjalk on 11 May 2020, 11:09 pm EST

  • Posted 11 May 2020, 11:09 pm EST

    Hi team,

    I have a grid which has columns that are always hidden. When I export this grid to Excel I want the hidden columns to be exported as well without changing the grid(showing hidden columns). I also want to not export some visible columns. is there a way I can choose which columns to export. Thanks

    FYI -I am using below code to export

    export(grid) {
        const view = grid.collectionView;
          let oldPgSize = view.pageSize,
            oldPgIndex = view.pageIndex;
          grid.beginUpdate();
          view.pageSize = 0;
          gridXlsx.FlexGridXlsxConverter.saveAsync(
            grid,
            {
              includeCellStyles: true,
              includeColumnHeaders: true
            },
            this.dataService.companyName+'_'+this.dataService.companyNr+'_'+"Account"+".xlsx",
            saved => {
              view.pageSize = oldPgSize;
              view.moveToPage(oldPgIndex);
              grid.endUpdate();
            },
            null
          );
      }
    
  • Posted 12 May 2020, 3:02 am EST

    Hi Kinjalk,

    While exporting the grid to excel, you can use the includeColumns callback to provide which column can be exported and which cannot.

    https://www.grapecity.com/wijmo/api/interfaces/wijmo_grid_xlsx.iflexgridxlsxoptions.html#includecolumns

    Regards,

    Ashwin

  • Posted 12 May 2020, 6:26 pm EST

    Thanks for the reply Ashwin,

    I tried the includeColumns callback and it is working. But only issue I have is the hidden columns are exported as hidden in excel. I want to show them as normal columns and not hidden.

    HTML

    <wj-flex-grid-column
                    [width]="'0.4*'"
                      header="Date"
                      binding="modifiedDateExcel" [isReadOnly]="true" [wordWrap]="true" [visible] = "exportHiddenColumn">
                    </wj-flex-grid-column>
    

    I tried to change the [visible] property to true(below) before exporting. still it is exported as a hidden column with 0 width.

    export(grid) {
        this.exportHiddenColumn = true;
        const view = grid.collectionView;
          let oldPgSize = view.pageSize,
            oldPgIndex = view.pageIndex;
          grid.beginUpdate();
          view.pageSize = 0;
          gridXlsx.FlexGridXlsxConverter.saveAsync(
            grid,
            {
              includeCellStyles: true,
              includeColumnHeaders: true,
              includeColumns: function(column) {
                return column.binding == 'documentNm' || column.binding == 'subtype' || column.binding == 'fileExtension' || column.binding == 'modifiedBy' || column.binding == 'modifiedDateExcel' || column.binding == 'clientReadyIn' || column.binding == 'Excelstatus';
             }
            },
            this.dataService.companyName+'_'+this.dataService.companyNr+'_'+"Account"+".xlsx",
            saved => {
              view.pageSize = oldPgSize;
              view.moveToPage(oldPgIndex);
              this.exportHiddenColumn = false;
              grid.endUpdate();
            },
            null
          );
      }
    

    I am using latest wijmo with angular 8.

    Let me know how I can export hidden columns as not hidden in excel. Thanks

  • Posted 13 May 2020, 3:36 am EST

    Hi Kinjalk,

    You can convert the FlexGrid to Workbook instance without downloading it. After it has been saved to Workbook, you can iterate over each column of the Workbook and set its visibility to true and then use the saveAsync method to Workbook class to save it. Also, the processing you have done in the onSaved callback of FlexGridXlsxConverter class can be moved to the onSaved callback of the Workbook class.

    Refer to the sample below:

    https://stackblitz.com/edit/angular-1fdqzn-mevfhz

    ~regards

Need extra support?

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

Learn More

Forum Channels