How to do export to excel for my flex-grid source

Posted by: ramu on 12 October 2017, 10:45 pm EST

    • Post Options:
    • Link

    Posted 12 October 2017, 10:45 pm EST

    Hi,

    I have used Wijmo 5.20171.282 version.

    I want to export all the data into excel in my angular 2 application.

    exportExcel() {

    wijmo.grid.xlsx.FlexGridXlsxConverter.save(this.flexGrid, { includeColumnHeaders: this.includeColumnHeader, includeCellStyles: false }, ‘FlexGrid.xlsx’);

    }

    The above function only export current paging data, not taking whole data. (i.e. Paging enabled my flex grid)

    Ex: I have 100 records, Set to page size is 10. So above function it returns only 10 records not 100 records.

    Is any other option to pass the source into this method??

    Thanks,

    Ramu

  • Posted 15 October 2017, 6:29 pm EST

    Hi,

    There are a couple of ways to accomplish this

    1. Before Export just set the Paging to False and turn it back again after Export Method is called.

    2. You could add another instance of FlexGrid which does not have have paging and make sure its hidde, The Items source for both Grid’s would be same and then call the Export Method on the the Hidden Grid,

    Thanks,

    Abhishek

  • Posted 15 October 2017, 11:53 pm EST

    Thanks Abhishek.

    It works fine.

    this.cv.pageSize = 0;

    wijmo.grid.xlsx.FlexGridXlsxConverter.save(this.flexGrid, { includeColumnHeaders: this.includeColumnHeader, includeCellStyles: false }, ‘FlexGrid.xlsx’);

    this.cv.pageSize = 10;

  • Posted 7 December 2017, 6:18 pm EST

    Hi Abhishek,

    I needed export to excel functionality, I have just implemented it in my project, but the problem is that exported file does not show data which was bound as an object. and shows [object Object] instead, in all of the cell of that column.

    Could you please point me to a solution for this?

  • Posted 10 December 2017, 10:24 pm EST

    Hi Rishabh,

    It seems you have nested data. In this case, you need to bind the each column to the nested property not to the shallow property. For example, we have following structured data:

    var data=[
    	{
    		id:100,
    		name:{
    				first: "John",
    				last: "Ivan"
    			    },
    		country:"US"
    	},
    	{
    		id:101,
    		name:{
    				first: "Bella",
    				last: "Castilho"
    			    },
    		country:"US"
    	}
    ]
    

    In this, if any column bound to the name property, it will show [object Object] and do not export correctly. For this, you need to bind column like “name.first”. Please refer to the following code snippet for the same:

    var grid= new wijmo.grid.FlexGrid("#grid",{
    	itemsSource:data,
    	autoGenerateColumns:false,
    	columns:[
    		{binding:"id", header:"ID"},
    		{binding:"name.first", header:"First Name"},
    		{binding:"name.last", header:"Last Name"},
    		{binding:"country", header:"Country"},
    	]
    });
    

    ~Manish

  • Posted 2 April 2019, 2:08 am EST

    Hi Team,

    My Issue is, I am showing multiple records in one grid column. It is not one value, it is multiple values and I have to use wjFlexGridCellTemplate to display the records. Now, I want to use formatItems(e) function which is given by the framework. I need to get the reference of this custom cell So that i can format it as needed.

    Please let me know how to do it.

  • Posted 2 April 2019, 6:54 pm EST

    In the fomatItem event, two parameters are passed, one is the reference to the grid itself and another one is event data, which is an instance of FormatItemEventArgs class.

    This event data has a property “cell” which is the reference to the cell currently being formatted. Please refer to the sample below:

    https://stackblitz.com/edit/angular-duzxfn

    API Reference:

    formatItem

    https://demos.wijmo.com/5/Angular/WijmoHelp/WijmoHelp/topic/wijmo.grid.FlexGrid.Class.html#formatItem

    FormatItemEventArgs

    https://demos.wijmo.com/5/Angular/WijmoHelp/WijmoHelp/topic/wijmo.grid.FormatItemEventArgs.Class.html

  • Posted 3 April 2019, 6:51 am EST

    Hi Team,

    I was talking about the download to excel functionality. During the download, If we need to format any cell, we use formatItems(e) function.

    Do you know if there is any additional parameter in this function as well. I need to get data object.

  • Posted 3 April 2019, 10:16 pm EST

    When we are formatting the cell using the formatItem method, an instance of XlsxFormatItemEventArgs class is passed to the method. This class has a property known as “xlsxCell”. It contains the reference to the current cell that is being exported to excel. We can use this to format the content as we like.

    Also, remember to set the “includeCellStyles” property to true while exporting the grid. Otherwise, the xlsxCell will be null.

    Please refer to the sample below:

    https://stackblitz.com/edit/angular-gnxlpp?file=src/app/app.component.ts

    API Reference:

    https://demos.wijmo.com/5/Angular/WijmoHelp/WijmoHelp/topic/wijmo.grid.xlsx.XlsxFormatItemEventArgs.Class.html#xlsxCell

Need extra support?

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

Learn More

Forum Channels