C#中如何把reportViewer的导出功能添加到button上
答案:1 悬赏:20
解决时间 2021-01-25 09:55
- 提问者网友:佞臣
- 2021-01-24 11:35
C#中如何把reportViewer的导出功能添加到button上
最佳答案
- 二级知识专家网友:愁杀梦里人
- 2021-01-24 12:20
Microsoft.Reporting.WinForms.Warning[] Warnings;
string[] strStreamIds;
string strMimeType;
string strEncoding;
string strFileNameExtension;
byte[] bytes = this.reportViewer1.LocalReport.Render("Excel", null, out strMimeType, out strEncoding, out strFileNameExtension, out strStreamIds, out Warnings);
string strFilePath = "";
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "excel97(*.xls)|*.xls";
if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
strFilePath = sfd.FileName;
using (System.IO.FileStream fs = new FileStream(strFilePath, FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
if (MessageBox.Show("报表打印: \r\n成功导出Excel文件!" + strFilePath + "\r\n要现在打开文件" + strFilePath + "吗?",
"", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
System.Diagnostics.Process.Start(strFilePath);
}
追问:对不起,我要粗鲁点了了。
他奶奶的在网上找这么久没有一个管用的,哥们给的直接就能用,我靠,你咋这么牛逼!!!
我爱你!加分!
string[] strStreamIds;
string strMimeType;
string strEncoding;
string strFileNameExtension;
byte[] bytes = this.reportViewer1.LocalReport.Render("Excel", null, out strMimeType, out strEncoding, out strFileNameExtension, out strStreamIds, out Warnings);
string strFilePath = "";
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "excel97(*.xls)|*.xls";
if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
strFilePath = sfd.FileName;
using (System.IO.FileStream fs = new FileStream(strFilePath, FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
if (MessageBox.Show("报表打印: \r\n成功导出Excel文件!" + strFilePath + "\r\n要现在打开文件" + strFilePath + "吗?",
"", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
System.Diagnostics.Process.Start(strFilePath);
}
追问:对不起,我要粗鲁点了了。
他奶奶的在网上找这么久没有一个管用的,哥们给的直接就能用,我靠,你咋这么牛逼!!!
我爱你!加分!
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯