Hello Deasun,
It is possible to export RadGridView from a console application. There are two important steps in order to be able to export the document. The first one is to set the BindingContext, as Ivan Petrov mentioned in the previous post. The second - is to call the LoadElementTree of the control, because, the control is not added to a Form and no visual elements are created.
I am adding a code sample below:
static void Main(string[] args)
{
RadGridView grid = new RadGridView();
grid.Size = new System.Drawing.Size(500, 500);
grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
grid.BindingContext = new System.Windows.Forms.BindingContext();
grid.DataSource = GetData();
grid.LoadElementTree();
GridViewSpreadExport export = new GridViewSpreadExport(grid);
export.ExportVisualSettings = true;
export.RunExport(@"..\..\Exported-file", new SpreadExportRenderer());
}
static DataTable GetData()
{
DataTable table = new DataTable();
table.Columns.Add("Id", typeof(int));
table.Columns.Add("First Name", typeof(string));
table.Columns.Add("Last Name", typeof(string));
table.Columns.Add("Age", typeof(int));
for (int i = 1; i <= 50; i++)
{
table.Rows.Add(i, "Andrew", "Fuller", i + 20);
}
return table;
}
I hope this information is useful.
Regards,
Todor Vyagov
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.