//AX Retail Data Export to excel without excel addins
using (SaveFileDialog sfdExport = new SaveFileDialog())
{
sfdExport.Filter = "Excel (2003)(.xls)|*.xls";
if (sfdExport.ShowDialog() != DialogResult.Cancel)
{
try
{
DataTable dtExport = new DataTable();
//You can get your data and fill it here
using (DevExpress.XtraGrid.GridControl grExport = new DevExpress.XtraGrid.GridControl())
{
using (DevExpress.XtraGrid.Views.Grid.GridView gvExport = new DevExpress.XtraGrid.Views.Grid.GridView())
{
gvExport.OptionsBehavior.AutoPopulateColumns = true;
gvExport.GridControl = grExport;
grExport.BindingContext = new BindingContext();
grExport.DataSource = dtExport;
grExport.MainView = gvExport;
grExport.ForceInitialize();
gvExport.PopulateColumns();
gvExport.ExportToXls(strExportFilePath);
}
}
}
catch (Exception ex)
{
LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), ex);
throw;
}
}
}
using (SaveFileDialog sfdExport = new SaveFileDialog())
{
sfdExport.Filter = "Excel (2003)(.xls)|*.xls";
if (sfdExport.ShowDialog() != DialogResult.Cancel)
{
try
{
DataTable dtExport = new DataTable();
//You can get your data and fill it here
using (DevExpress.XtraGrid.GridControl grExport = new DevExpress.XtraGrid.GridControl())
{
using (DevExpress.XtraGrid.Views.Grid.GridView gvExport = new DevExpress.XtraGrid.Views.Grid.GridView())
{
gvExport.OptionsBehavior.AutoPopulateColumns = true;
gvExport.GridControl = grExport;
grExport.BindingContext = new BindingContext();
grExport.DataSource = dtExport;
grExport.MainView = gvExport;
grExport.ForceInitialize();
gvExport.PopulateColumns();
gvExport.ExportToXls(strExportFilePath);
}
}
}
catch (Exception ex)
{
LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), ex);
throw;
}
}
}
No comments:
Post a Comment