| @(Html.EJ().Grid<OrdersView>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.ExcelExport); items.AddTool(ToolBarItems.PrintGrid); })) .AllowPaging() .Columns(col => { ... }) ) 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,"none"); } public void QueryCellInfo(object currentCell) { IRange range = (IRange)currentCell; if (range.Column == 3) { range.CellStyle.Color = Color.Red; //pass string value to assign the color } if (range.Column == 5) { range.CellStyle.Font.Bold = true; range.CellStyle.Font.Italic = true; } } |
| <label id="lblHeader" class="header" style="display:none;"><b>Syncfusion</b></label> <img src="../../Images/download.png" class="image" style="display:none;" /> <br /> <div id = "ControlRegion"> @(Html.EJ().Grid<OrdersView>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.ExcelExport); items.AddTool(ToolBarItems.PrintGrid); })) .AllowPaging() .Columns(col => { ... }) .ClientSideEvents(eve => eve.BeforePrint("beforePrint")) ) </div > <script type="text/javascript" > function beforePrint(args) { $("#lblHeader").css('display', 'block'); $(".image").css('display', 'block'); args .element.prepend($(".header")); args .element.prepend($(".image")); } </script> |
Hi
Manisankar. Thanks for the prompt reply. I had seen that code in your/Syncfusion's various replies to other queries.
It's sort of OK for a specific case. My question was for something more generic. Like one parameter is the ejGrid and the second parameter is the ExcelGrid object. And I see now that I would probably need the data list as well.
Yeah! Well. That was my idea. But its sort of based on C#/VB6 'thinking'.
Perhaps something in Javascript?
The problem is not new. It existed well before MVC. In VB6 and grid printing for instance.
Making it a parameter, 'ExportWithFormatting=true/false', on the GridModel, would be very much a value added feature.
OK Manisankar. I can see that we are at a dead end using inbuilt public void ExportToExcel(string GridModel). Which is a pity. I have only small reports from tables with no more than 90 rows and less than 20 columns. So performance is not something that I would suffer from.
But. I still want a generic way to generate formatted reports as they appear on-screen to the client, With/without multiple headers etc.
The code that you supplied below is not feasible. It just doesn't compile.
obj.ServerExcelQueryCellInfo = QueryCellInfo; doesn't 'mix' with public void QueryCellInfo(object currentCell)
How do I 'supply' the function with 'object currentCell'. There has to be a loop somewhere. Or that the 'event' has its 'row' and 'column' parameter and is activated whenever a cell is filled with a value.
Anyway, too many hour spent puzzling it out with no online help to resolve the issue.
Now. What about Syncfusion ReportWriter. Reading about it looks good. But then so did ' public void ExportToExcel(string GridModel)'
If I build the required reports using c# code, and including full formatting, into an RDL formated document using Syncfusion ReportWriter, (a generic function), can they be easily converted to .docx, .xlsx and .pdf format without me writing complex code. (I write with many bugs). Do you have ready prepared functions to do this?
Before I start to invest a lot of work in it only to find that only the data is exported without the visually attractive formatting.
| I can see that we are at a dead end using inbuilt public void ExportToExcel(string GridModel). Which is a pity. I have only small reports from tables with no more than 90 rows and less than 20 columns. So performance is not something that I would suffer from. But. I still want a generic way to generate formatted reports as they appear on-screen to the client, With/without multiple headers etc. The code that you supplied below is not feasible. It just doesn't compile. obj.ServerExcelQueryCellInfo = QueryCellInfo; doesn't 'mix' with public void QueryCellInfo(object currentCell) How do I 'supply' the function with 'object currentCell'. There has to be a loop somewhere. Or that the 'event' has its 'row' and 'column' parameter and is activated whenever a cell is filled with a value. Anyway, too many hour spent puzzling it out with no online help to resolve the issue. | By default, the ServerExcelQueryCellInfo which is trigger from our export source while creating each cell and it is passed the current cell details as a parameter. Please refer to the below documentation link. |
| Now. What about Syncfusion ReportWriter. Reading about it looks good. But then so did ' public void ExportToExcel(string GridModel)' If I build the required reports using c# code, and including full formatting, into an RDL formated document using Syncfusion ReportWriter, (a generic function), can they be easily converted to .docx, .xlsx and .pdf format without me writing complex code. (I write with many bugs). Do you have ready prepared functions to do this? Before I start to invest a lot of work in it only to find that only the data is exported without the visually attractive formatting. | We can achieve your requirement by using ReportWriter control to export the report into PDF, Excel, Word, PPT and HTML directly. We have prepared a sample and it can be downloaded from below location, Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ReportWriterSample-1945151575.zip Please find the below UG documents for more detail, You can obtain the complete ASP.NET MVC ReportWriter sample in below build installed location, %userprofile%\AppData\Local\Syncfusion\EssentialStudio\version\ MVC\Samples\web |