- Home
- Forum
- ASP.NET MVC
- Export to Excel Format
Export to Excel Format
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
SIGN IN To post a reply.
3 Replies
VN
Vignesh Natarajan
Syncfusion Team
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.
- 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
- 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
LJ
Laura Jordan
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
VN
Vignesh Natarajan
Syncfusion Team
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
- Columns displayed in Grid
|
|
- 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
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
LJ Laura Jordan
- Nov 20, 2018 06:54 PM UTC
- Nov 22, 2018 09:55 AM UTC