C#中如何把reportViewer的导出功能添加到button上
我利用reportviewer生成了LocalReport,而且reportViewer本身也有导出功能,但是我想把它的导出到excel的功能也放在新建的button上,...
我利用reportviewer生成了LocalReport,而且reportViewer本身也有导出功能,但是我想把它的导出到excel的功能也放在新建的button上,请问如何做?
private void button1_Click(object sender, EventArgs e)
{
//如何将reportviewer的导出功能引用到这里?
} 展开
private void button1_Click(object sender, EventArgs e)
{
//如何将reportviewer的导出功能引用到这里?
} 展开
1个回答
推荐于2016-05-14 · 知道合伙人软件行家
关注
展开全部
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);
}
追问
对不起,我要粗鲁点了了。
他奶奶的在网上找这么久没有一个管用的,哥们给的直接就能用,我靠,你咋这么牛逼!!!
我爱你!加分!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询