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

Export to Excel Format

Thread ID:

Created:

Updated:

Platform:

Replies:

141062 Nov 20,2018 06:54 PM UTC Nov 22,2018 09:55 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Laura Jordan
Asked On November 20, 2018 06:54 PM UTC

Hi,

I am using the Export To Excel method, but when I download the document the names of the columns do not appear...

This is my View code:


And this is my Controller code:


I really appreciate the support,

Thanks

Vignesh Natarajan [Syncfusion]
Replied On November 21, 2018 02:59 PM UTC

  
Hi Laura, 
 
Thanks for using Syncfusion products  
 
Query: “but when I download the document the names of the columns do not appear...” 
 
From your query, we understand that you need to export the Grid with column header. We have analyzed the reported behavior and we are able to reproduce the reported behavior at our end. 
To resolve the issue kindly follow the either one the below methods. 
 
  1.  We have given to support to export the Grid using export method. While exporting through that method, Grid will be exported with column header. Refer our help documentation and online demo for your reference
 
 
 
  1. If you still to wish to export the Grid using workbook.saveAs method, then kindly modify your code as below
 
public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            ExcelEngine excel = new ExcelEngine(); 
            IApplication application = excel.Excel; 
            IWorkbook workbook = application.Workbooks.Create(1); 
 
             
            var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            workbook.Worksheets[0].ImportData(DataSource, 1, 1, true); 
            workbook.SaveAs("Exported.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2010); 
            //exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 
 
  
Note: you have defined the includeHeader property as false while exporting. So the column header is not exported properly. Enable that property to export the grid with column header. 
 
Refer the below screenshot for the output 
 
 
 
 
 
  
Please get back to us if you have further queries. 
 
 
Regards, 
Vignesh Natarajan 


Laura Jordan
Replied On November 21, 2018 04:40 PM UTC

Hi Vignesh,

Thank you for your replay I replaced the bool parameter on the ImportData method and it works as expected.

Just another question: How can I hide columns when exporting?

Appreciate the support,
Laura

Vignesh Natarajan [Syncfusion]
Replied On November 22, 2018 09:55 AM UTC

Hi Laura, 
 
 
Thanks for the update. 
 
Query: “How can I hide columns when exporting?” 
 
From your query, we understand that you need to hide certain column while exporting. We suggest you to achieve your requirement using Export method of ejGrid. Refer the below code example 
 
public void ExportToExcel(string GridModel) 
        { 
            ExcelExport exp = new ExcelExport(); 
            var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList(); 
            GridProperties obj = ConvertGridObject(GridModel); 
            obj.Columns[3].Visible = false;   // define visible property as false while exporting based on column index.  
            exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); 
        } 
 
For your convenience we have prepared a sample which can be downloaded from below link 
 
 
Refer the below screenshot for the output 
 
  1. Columns displayed in Grid
 
 
 
  1. column gets exported to excel
 
 
 
Note: Freight column get hided while exporting. 
 
Refer our help documentation for your reference 
 
 
Please get back to us if you need further assistance     
 
 
Regards, 
Vignesh Natarajan 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

;