We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

customize document in Grid Excel Export

How do I customize the excel document from a grid export?  Specifically, I want to add a document title in the first row, and maybe some footer information after the table.

3 Replies

GV Gowthami V Syncfusion Team August 31, 2015 01:04 PM UTC

Hi David,

Thanks for contacting Syncfusion support.

Before proceeding with your requirement we need below details for achieve your requirement.

1.       Document title means what you expect to display?

2.       Are you using Single export/ Multiple export.

3.       What kind of footer information you need to display in the excel sheet.

4.       Please share us the screenshot of your requirement.

The provided information will help us to analyze the issue and provide you the response as early as possible.

Regards,
Gowthami V.  



DE David Elies August 31, 2015 04:54 PM UTC

The grid we are displaying and exporting is a "report" for our higher-ups.  The title I mentioned is the title of the report, like "Methodologies for the Typical Unification of Access Points and Redundancy".  We are using whatever the default export is, whether single or multiple.  Can you explain the difference, please? The footer I was imagining was maybe a copyright notice and security message -- "This report is for the Deputy Senior VP in charge of things that don't really matter. If this is not you, please destroy and notify the intended recipient immediately".


Attachment: export_screenshot_4d89e831.7z


GV Gowthami V Syncfusion Team September 1, 2015 09:13 AM UTC

Hi David,
We have created a sample and the same can be downloaded from the following link.
Sample Link: MvcApplication12_(2)
In the above sample we have set the “multiExport” parameter as true for the “Export” method for returning the excel workbook.
Then we got the ActiveSheet by using “ActiveSheet” property of the “IWorkBook” class and then set the Range for the title using “Range” property and then added the title using “Text” property of the Range.
And also we have set the footer information by using “SetValue” method of the ActiveSheet.
Please refer the below example code.

GridFeatures.cshtml

 

@(Html.EJ().Grid<MvcApplication12.OrdersView>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

. . . .

. . . .

.ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>

                    {

                        items.AddTool(ToolBarItems.ExcelExport);  }))

)


GridController.cs


public void ExportToExcel(string GridModel)

        {

            ExcelExport exp = new ExcelExport();

            ExcelEngine excel = new ExcelEngine();

            IApplication application = excel.Excel;

            var DataSource = new NorthwindDataContext().OrdersViews.ToList();

            GridProperties obj = ConvertGridObject(GridModel);

            IWorkbook workbook = application.Workbooks.Create(2);

            //Setting multiExport as true and export the document and assigned to workbook

            workbook = exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "default-theme",true);

            //Inserted new row for adding title

            workbook.ActiveSheet.InsertRow(1);

            //Merging the sheet from Range A1 to D1 for adding title space

            workbook.ActiveSheet.Range["A1:D1"].Merge();

            //Adding the title using Text property

            workbook.ActiveSheet.Range["A1"].Text = "Methodologies for the Typical Unification of Access Points and Redundancy";

            //Adding the footer information using SetValue method of the ActiveSheet

            workbook.ActiveSheet.SetValue(workbook.ActiveSheet.Rows.Length + 2, workbook.ActiveSheet.Columns.Length - 3, "This report is for the Deputy Senior VP in charge of things that don't really matter. If this is not you, please destroy and notify the intended recipient immediately");

            //Downloading the document

            workbook.SaveAs("Export.xls", HttpContext.ApplicationInstance.Response,ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2010);

         

        }


Query: We are using whatever the default export is, whether single or multiple.  Can you explain the difference, please?
We can achieve exporting in below two ways.
1. Single Exporting
2. Multiple exporting
Single exporting is the default exporting which is used to export the single grid at a time.
Please refer the below online demo link for more clarification single exporting.
http://mvc.syncfusion.com/demos/web/grid/exportinggrid
Multiple exporting is used to export the multiple grids at a time which are present in the same page.
Please refer the below online demo link for multiple exporting.
http://mvc.syncfusion.com/demos/web/grid/multipleexporting
Please try the above snippet and let us know if you have any queries.
Regards,
Gowthami V.

Loader.
Live Chat Icon For mobile
Up arrow icon