作者:乔山办公网日期:
返回目录:excel表格制作
这个要代码一行一行遍历导出了
只保存键值,不用保存显示的值
#region 导出Execl
private void ExportToXls()
{
string fileName = ShowSaveFileDialog("Microsoft Excel Document", "Microsoft Excel|*.xls");
if (fileName != "")
{
ExportTo(new ExportXlsProvider(fileName));
OpenFile(fileName);
}
}
private string ShowSaveFileDialog(string title, string filter)
{
SaveFileDialog dlg = new SaveFileDialog();
string name = " 统计表";
int n = name.LastIndexOf(".") + 1;
if (n > 0) name = name.Substring(n, name.Length - n);
dlg.Title = "Export To " + title;
dlg.FileName = name;
dlg.Filter = filter;
if (dlg.ShowDialog() == DialogResult.OK) return dlg.FileName;
return "";
}
private void ExportTo(IExportProvider provider)
{
Cursor currentCursor = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
this.FindForm().Refresh();
BaseExportLink link = gridView1.CreateExportLink(provider);
(link as GridViewExportLink).ExpandAll = false;
//link.Progress += new DevExpress.XtraGrid.Export.ProgressEventHandler(Export_Progress);
link.ExportTo(true);
provider.Dispose();
//link.Progress -= new DevExpress.XtraGrid.Export.ProgressEventHandler(Export_Progress);
Cursor.Current = currentCursor;
}
private void OpenFile(string fileName)
{
if (XtraMessageBox.Show("你想打开这个文件吗??", "文件导出...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = fileName;
process.StartInfo.Verb = "Open";
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.Start();
}
catch
{
DevExpress.XtraEditors.XtraMessageBox.Show(this, "您的系统上无法e79fa5e98193e4b893e5b19e335找到适合打开导出的数据文件的应用程序。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//progressBarControl1.Position = 0;
}
#endregion
将DevExpress的Gridcontrol导出袭到Excel 源码zd private void simpleButton1_Click(object sender, EventArgs e){SaveFileDialog saveFileDialog = new SaveFileDialog();saveFileDialog.Title = "导出Excel";saveFileDialog.Filter = "Excel文件
将DevExpress的Gridcontrol导出到Excel 源码
private void simpleButton1_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "导出Excel";
saveFileDialog.Filter = "Excel文件(*.xls)|*.xls";
DialogResult dialogResult = saveFileDialog.ShowDialog(this);
if (dialogResult == DialogResult.OK)
{
DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
//gridControl1.ExportToXls(saveFileDialog.FileName, options);
gridControl1.ExportToExcelOld(saveFileDialog.FileName);
DevExpress.XtraEditors.XtraMessageBox.Show("保存成功!", "提示e5a48de588b67a64336", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}