devexpress girdview 转excel求助
我现在有3个gridview要转成EXCEL文件保存,用gridView.ExportToXls,怎么能将3个gridview存到1个excel文件的3个sheet页中?...
我现在有3个gridview要转成EXCEL文件保存,用gridView.ExportToXls,怎么能将3个gridview存到1个excel文件的3个sheet页中?谢谢!
展开
展开全部
只保存键值,不用保存显示的值
#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, "您的系统上无法找到适合打开导出的数据文件的应用程序。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//progressBarControl1.Position = 0;
}
#endregion
#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, "您的系统上无法找到适合打开导出的数据文件的应用程序。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//progressBarControl1.Position = 0;
}
#endregion
2016-05-10
展开全部
设置了CustomColumnDisplayText事件后,GridView导出的数据到Excl是自定义后的数据 ,如何才能导出原始数据?
protected void ASPxGridView1_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
{
for (int i = 0; i < ASPxGridView1.VisibleRowCount; i++)
{
if (e.Column.FieldName == "品名")
{
var v_hash = new Hashtable();
v_hash.Add("p1", e.GetFieldValue("入库单id"));
v_hash.Add("p2", Q_入库日期_1.Date.ToString("yyyy-MM-dd"));
v_hash.Add("p3", Q_入库日期_2.Date.ToString("yyyy-MM-dd"));
v_hash.Add("p4", e.GetFieldValue("数量1"));
v_hash.Add("p5", e.GetFieldValue("金额2"));
string v_str = "<a href='库存台账明细.aspx?%s'>%s<a>";
v_str = Common.FormatEh(v_str,
CommonWebUtil.GetUrlParams(v_hash), e.GetFieldValue("品名"));
e.DisplayText = v_str;
}
}
}
public static void GridExport(string fileName, ASPxGridViewExporter gridExporter)
{
XlsExportOptions ExportOptions = new XlsExportOptions
{
ExportMode = XlsExportMode.SingleFile,
SheetName = "Sheet1",
ShowGridLines = true,
TextExportMode = TextExportMode.Text
};
gridExporter.WriteXlsToResponse(fileName, true, ExportOptions);
}
protected void ASPxMenu1_ItemClick(object source, MenuItemEventArgs e)
{
switch (e.Item.Text)
{
case "查询":
LoadData();
return;
case "清空查询":
CommonWebUtil.清空查询(div查询);
return;
case "导出":
LoadData();
CommonWebUtil.GridExport("库存台账", ASPxGridViewExporter1);
return;
protected void ASPxGridView1_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e)
{
for (int i = 0; i < ASPxGridView1.VisibleRowCount; i++)
{
if (e.Column.FieldName == "品名")
{
var v_hash = new Hashtable();
v_hash.Add("p1", e.GetFieldValue("入库单id"));
v_hash.Add("p2", Q_入库日期_1.Date.ToString("yyyy-MM-dd"));
v_hash.Add("p3", Q_入库日期_2.Date.ToString("yyyy-MM-dd"));
v_hash.Add("p4", e.GetFieldValue("数量1"));
v_hash.Add("p5", e.GetFieldValue("金额2"));
string v_str = "<a href='库存台账明细.aspx?%s'>%s<a>";
v_str = Common.FormatEh(v_str,
CommonWebUtil.GetUrlParams(v_hash), e.GetFieldValue("品名"));
e.DisplayText = v_str;
}
}
}
public static void GridExport(string fileName, ASPxGridViewExporter gridExporter)
{
XlsExportOptions ExportOptions = new XlsExportOptions
{
ExportMode = XlsExportMode.SingleFile,
SheetName = "Sheet1",
ShowGridLines = true,
TextExportMode = TextExportMode.Text
};
gridExporter.WriteXlsToResponse(fileName, true, ExportOptions);
}
protected void ASPxMenu1_ItemClick(object source, MenuItemEventArgs e)
{
switch (e.Item.Text)
{
case "查询":
LoadData();
return;
case "清空查询":
CommonWebUtil.清空查询(div查询);
return;
case "导出":
LoadData();
CommonWebUtil.GridExport("库存台账", ASPxGridViewExporter1);
return;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询