export excel style and bootstrap icon

Hi,

I need export to excel with grid's cell style and cell icons.

I try pass cssClass property, but the style and icon is not exported.

I attach an example

Thanks


Attachment: GridExportStyle_21e8525d.zip

5 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 20, 2017 08:48 AM UTC

Hi Manolo,  
 
Thanks for contacting Syncfusion Support.  
 
We have already discussed about the formatting Grid rows and cells in the following Help Document section using the AutoFormat Class. 
 
 
If you would like to customize the rows/cells based on the data binding to them using the respective server events which has been discussed in the following Help Document.  
 
 
Regards,  
Seeni Sakthi Kumar S. 
 



MA Manolo October 20, 2017 10:12 AM UTC

Ok, but I've a problem.

I set conditional formatting in function of differents columns, some of this are hidden.

So, in ServerExcelRowInfo event, I haven't this values for colour formatting.

I like pass the css style of each cell for not repeat the function of conditional formatting.

If, it isn't posible.... how can I set the colours in excel when it depends of hidden columns?

I've modified the example. I hide Freight column, and when it's value is superior than 40, I set red colour in ship city. How can I set this colours in excel export?


Attachment: GridExportStyle_9d9bffef.zip


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 23, 2017 01:33 PM UTC

Hi Manolo,  
 
We can use the ServerExcelQueryCellInfo event access the cell details and its data values where you can change the background color of the respective cell. Refer to the following code example.  
 
        public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            obj.ServerExcelQueryCellInfo = queryCellInfo; 
            exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 
        public void queryCellInfo(object currentCell) 
        { 
            IRange range = (IRange)currentCell; 
            if (range.Column == 3) 
            {// here 3 is the index of Freight columns 
                if (int.Parse(range.Value.ToString()) > 40) 
                    range.CellStyle.Color = Color.LightGreen; 
            } 
        } 
 
Regards,  
Seeni Sakthi Kumar S. 



MA Manolo October 24, 2017 07:40 AM UTC

Sorry, it don't work for me (and for my english _:)

I try explain my problem better:

In my grid, Freight column is hidden, and I set the colour of ShipCity in function of Freight column. I need this colour in excel exportation.

In your last example, you change fright column colour, but I dont wan't show this column, and I need set the colour of Ship City.

In my last attach, I put an example

Thanks

Thanls



RS Renjith Singh Rajendran Syncfusion Team October 25, 2017 12:38 PM UTC

Hi Manolo, 

We have analyzed your query and we found that you would like to change the color for the cell based on hidden column value while exporting to excel. To achieve this we suspect that you couldn’t get the value of the hidden column at server side during exporting. So we suggest you to get the value for the hidden column from the dataSource to set the background color for another column cell. Please refer the code example below, 

        IEnumerable<OrdersView> currentData = null;  
 
        public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList(); 
            currentData = DataSource; 
            GridProperties obj = ConvertGridObject(GridModel); 
            obj.ServerExcelQueryCellInfo = queryCellInfo; 
           exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 
        public void queryCellInfo(object currentCell) 
        { 
            IRange range = (IRange)currentCell; 
            if (range.Column == 4) //Here it checks for the ShipCity Column where 4 is the index of shipCity column            { 
                foreach (OrdersView currentval in currentData) 
                { 
                    if (currentval.Freight > 40) //Here it checks the value of Hidden column "Freight(Hidden column)"                    { 
                        range.CellStyle.Color = Color.LightGreen; 
                        ... 
                    } 
                } 
            } 
        } 


 
Please refer the documentation link below, 
 
Regards, 
Renjith Singh Rajendran. 


Loader.
Up arrow icon