最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

Export data from Retail POS to Excel without installing Microsoft Excel

网络文摘 William 677浏览 0评论

If you want to export data from Retail POS to Excel without installing Microsoft Excel, you can use one of DevExpress features to achieve this.
Here is my sample code :

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;
		}
	}
}

You can fill the data table or use other type of datasource.


发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址