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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

customize document in Grid Excel Export

Thread ID:

Created:

Updated:

Platform:

Replies:

120092 Aug 29,2015 05:40 PM UTC Sep 1,2015 09:13 AM UTC ASP.NET MVC 3
loading
Tags: Grid
David Elies
Asked On August 29, 2015 05:40 PM UTC

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.

Gowthami V [Syncfusion]
Replied On 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.  


David Elies
Replied On 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

Gowthami V [Syncfusion]
Replied On 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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;