[Index.cshtml]
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource))
.AllowPaging()
.ToolbarSettings(toolBar => toolBar.ShowToolbar(true).ToolbarItems(items =>
{
items.AddTool(ToolBarItems.ExcelExport);
items.AddTool(ToolBarItems.WordExport);
items.AddTool(ToolBarItems.PdfExport);
}))
.Columns(col =>
{
...
})
)
[controller.cs]
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
string targetFolder = HttpContext.Server.MapPath("") + "\\New folder\\";
var DataSource = OrderRepository.GetAllRecords().ToList();
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron",true, targetFolder); //specify the path which helps to save the excel file in local folder
} |
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
string fileName = String.Format("{0:dd-MM-yyyy}", DateTime.Now) + "_" + name + ".xlsx".ToString();
var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList();
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, DataSource, fileName, ExcelVersion.Excel2010, false, false, "flat-saffron", true, targetFolder);
} |
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
string fileName = String.Format("{0:dd-MM-yyyy}", DateTime.Now) + "_" + name + ".xlsx".ToString();
string targetFolder = HttpContext.Server.MapPath("") + "\\New folder\\";
var DataSource = new NorthwindDataContext().OrdersViews.Take(100).ToList();
GridProperties obj = ConvertGridObject(GridModel);
//Grid properties, dataSource, filename, version of file, include/exclude hidden column, include/exclude template column, theme, enable/disable local save, folder to be saved
exp.Export(obj, DataSource, fileName, ExcelVersion.Excel2010, false, false, "flat-saffron", true/*enable/disable local save, */, targetFolder /*folder to be saved*/);
} |
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
string path = Url.Content("D:\\excel"); //mention the path to store the excel file
string targetFolder = path + "\\New folder\\"; //no need to use server.MapPath
var DataSource = OrderRepository.GetAllRecords().ToList();
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron",true, targetFolder);
} |