BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
[controller]
using Syncfusion.EJ.Export;
using Syncfusion.XlsIO;
using Syncfusion.JavaScript.Models;
public void ExportToExcel(string GanttModel)
{
ExcelExport exp = new ExcelExport();
var DataSource = this.GetEditingDataSource();
GanttProperties obj = ConvertGanttObject(GanttModel);
exp.Export(obj, DataSource, "GanttExport.xlsx", ExcelVersion.Excel2010, new GanttExportSettings() { Theme = ExportTheme.FlatSaffron });
}
private GanttProperties ConvertGanttObject(string gridProperty)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
GanttProperties gridProp = new GanttProperties();
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;
} |
[view]
@(Html.EJ().Gantt("GanttContainer")
.Mappers(mp => mp.ExportToExcelAction("Gantt/ExportToExcel"))
.ToolbarSettings(tool =>
{
tool.ShowToolbar(true);
tool.ToolbarItems(new List<GanttToolBarItems>()
{
GanttToolBarItems.ExcelExport,
});
})
.Datasource(ViewBag.datasource)
)@(Html.EJ().ScriptManager()) |
[chtml]
@(Html.EJ().Gantt("GanttContainer")
//…
// Call server method from client side
.Mappers(mp => mp.ExportToExcelAction("Gantt/ExportToExcel")
.ExportToExcelAction("Gantt/ExportToPdf"))
.ToolbarSettings(tool =>
{
tool.ShowToolbar(true);
tool.ToolbarItems(new List<GanttToolBarItems>()
{
GanttToolBarItems.ExcelExport,
GanttToolBarItems.PdfExport
}); |
[CS]
// For Excel export server side method
public void ExportToExcel(string GanttModel)
{
ExcelExport exp = new ExcelExport();
// Please ensure with given parameter order
exp.Export(obj, DataSource, "GanttExport.xlsx", ExcelVersion.Excel2010, new GanttExportSettings() { Theme = ExportTheme.FlatSaffron });
}
// PDF export server side method
public void PdfExport(string GanttModel,bool isFitToWidth)
{
PdfExport exp = new PdfExport();
//…
exp.Export(obj, DataSource, settings, "Gantt");
} |
|
private GanttProperties ConvertGanttObject(string gridProperty)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
GanttProperties gridProp = new GanttProperties();
foreach (KeyValuePair<string, object> ds in div)
{
var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (ds.Key == "resources")
property.SetValue(gridProp, GetResourceCollection(), null);
else 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;
} |
Tried to implement the way you suggested. Still getting error :
Thanks for the response. We've resolved this issue as of now.However, the columns which are added from client events are not getting exported. Code to add the columns are as below:
.......
<script type="text/x-jsrender" id="columnPriority">
{{if #data.item.Priority}}
<div style="text-align:right">
{{:#data.item.Priority}}
</div>
{{/if}}
</script>
.......
Request you to resolve this at the earliest as we are running short of time for delivery.
public void PdfExport(string GanttModel, bool isFitToWidth)
{
PdfExport exp = new PdfExport();
//…
GanttPdfExportSettings settings = new GanttPdfExportSettings();
settings.IncludeTemplateColumn = true;
exp.Export(obj, DataSource, settings, "Gantt");
} |
function load(args) {
var columns = this.getColumns();
var priority = {
field: "Priority",
headerText: "Priority",
textAlign: "right",
isTemplateColumn: true,
templateID: "columnPriority",
mappingName: "Priority",
};
columns.splice(2, 0, priority);
} |