|
public void ExportToExcel(string GridModel)
{
…………………
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "none");
}
|
|
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
ExcelEngine excel = new ExcelEngine();
IApplication application = excel.Excel;
BindDataSource();
var DataSource = order;
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);
}
|

|
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
ExcelEngine excel = new ExcelEngine();
IApplication application = excel.Excel;
GridProperties obj = ConvertGridObject(GridModel);
IWorkbook workbook = application.Workbooks.Create(2);
List<Orders> reports = BindDataSource();
workbook.Worksheets[0].ImportData(reports, 1, 1, false);
workbook.SaveAs("Export.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2010);
} |
|
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
BindDataSource();
var DataSource = order;
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron");
}
private GridProperties ConvertGridObject(string gridProperty)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
GridProperties gridProp = new GridProperties();
foreach (KeyValuePair<string, object> ds in div)
{
var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (property != null)
{
Type type = property.PropertyType;
string serialize = serializer.Serialize(ds.Value);
object value = serializer.Deserialize(serialize, type);
property.SetValue(gridProp, value, null);
}
}
return gridProp;
}
|
|
@using SyncfusionMvcApplication1.Controllers
@{
ViewBag.Title = "Home Page";
}
@(Html.EJ().Grid<Object>("Grid")
----------------------
.Columns(col =>
{
------------------
col.Field("ShipCity").HeaderText("Ship City").Width(110).Priority(2).Add();
})
.ClientSideEvents(eve => eve.ToolbarClick("toolbarclick"))
)
<script type="text/javascript">
function toolbarclick(args) {
var url = null;
var proxy = this;
if (args.itemName == "Excel Export") {
args.cancel = true;
url = "/Home/ExportToExcel";
}
if (args.itemName == "PDF Export") {
args.cancel = true;
url = "/Home/ExportToPDF";
}
if (args.itemName == "Word Export") {
args.cancel = true;
url = "/Home/ExportToWord";
}
if (args.itemName.indexOf("Export") != -1) {
$("#Grid").ejWaitingPopup("show");
var model = $.extend(true, {}, this.model);
if (this.ignoreOnExport) {
for (var i = 0; i < this.ignoreOnExport.length; i++)
delete model[this.ignoreOnExport[i]];
}
$.ajax({
type: "POST",
url: url,
data: { GridModel: JSON.stringify(model) },//pass the grid model
success: function (response) {
proxy.element.ejWaitingPopup("hide");
alert("Grid Exported");
},
error: function (Result) {
alert("Error");
}
});
}
}
</script>
[controller.cs]
public partial class HomeController : Controller
{
. . . . .
. . . .
public ActionResult ExportToExcel(string GridModel)
{
GridProperties gridPropert = (GridProperties)Syncfusion.JavaScript.Utils.DeserializeToModel(typeof(GridProperties),GridModel);
ExcelExport exp = new ExcelExport();
BindDataSource();
var DataSource = order;
exp.Export(gridPropert, (IEnumerable)data, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-lime",true,Server.MapPath("/outPut"));
return Json(new List<string>(), JsonRequestBehavior.AllowGet);
}
. . . . .
}
}
|