REPORTVIEW导出

来源:互联网 发布:人工智能电影国语 编辑:程序博客网 时间:2024/06/07 00:50

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