ReportView
1、dll:
Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.DataVisualization.dll
Microsoft.ReportViewer.ProcessingObjectModel.DLL
Microsoft.ReportViewer.WebForms.DLL
可以通过reportview.exe安装,dll可以通过shell获取。
cmd cd C:\WINDOWS\assembly dir cd gac_msil dir *reportview* /s copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.Common\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.Common.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.Common.resources\10.0.0.0_zh-CHS_b03f5f7f11d50a3a\Microsoft.ReportViewer.Common.resources.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.Design\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.Design.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.Design.resources\10.0.0.0_zh-CHS_b03f5f7f11d50a3a\Microsoft.ReportViewer.Design.resources.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.ProcessingObjectModel\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.ProcessingObjectModel.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebDesign\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebDesign.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebDesign.resources\10.0.0.0_zh-CHS_b03f5f7f11d50a3a\Microsoft.ReportViewer.WebDesign.resources.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms.resources\10.0.0.0_zh-CHS_b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.resources.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WinForms\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WinForms.dll C:\ copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WinForms.resources\10.0.0.0_zh-CHS_b03f5f7f11d50a3a\Microsoft.ReportViewer.WinForms.resources.dll C:\ @XCOPY /I /Y %SYSTEMDRIVE%\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.DataVisualization\10.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.DataVisualization.dll C:\
2、config:
放在根目录,当前系统有三个程序集WebGPS、WebGPS.UI.BasicInfo、WebGPS.BasicInfo,UI层和WebGPS都有webconfig,虽然report在UI层,但是WebGPS是根目录,所以config还是要配置在WebGPS层。
<system.webServer>下<handlers>配置
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<system.web>下<httpHandlers>配置
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false" />
3、打印只显示PDF
protected void rptViewer_PreRender(object sender, EventArgs e) { RenderingExtension[] resut = ReportViewer1.LocalReport.ListRenderingExtensions(); foreach (RenderingExtension item in ReportViewer1.LocalReport.ListRenderingExtensions()) { // item 具有Visable属性,但是这个属性是只读属性,不能修改,所以通过反射进行了修改 if (item.Name.ToUpper() == "EXCEL") { // 显示excel2003格式导出按钮 FieldInfo fi = item.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); fi.SetValue(item, false); } if (item.Name.ToUpper() == "WORD") { // 显示word2003导出按钮 FieldInfo fi = item.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); fi.SetValue(item, false); } if (item.Name.ToUpper() == "EXCELOPENXML") { // 不显示excel2003以上版本的格式 FieldInfo fi = item.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); fi.SetValue(item, false); } if (item.Name.ToUpper() == "WORDOPENXML") { // 不显示word以上版本的格式 FieldInfo fi = item.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); fi.SetValue(item, false); } } }
4、手机端PDF打印,会话已过期,可以加个按钮自己导出
/// <summary> /// PDF导出 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnPDF_Click(object sender, EventArgs e) { Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = string.Empty; //ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportViewer1.LocalReport.ReportPath = "UI/BasicInfo/Report/Contract_ProductSalues.rdlc"; SetParameters(); byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); Response.Buffer = true; Response.Clear(); Response.ContentType = mimeType; Response.AddHeader("content-disposition", "attachment; filename=" + "20170907版产品销售合同" + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + extension); Response.BinaryWrite(bytes); Response.Flush(); } /// <summary> /// 设置参数 /// </summary> private void SetParameters() { ReportViewer1.LocalReport.SetParameters(new ReportParameter("para_GSBA", "2017-09-07")); ReportViewer1.LocalReport.SetParameters(new ReportParameter("para_No", "XRJT-XSFW")); ReportViewer1.LocalReport.SetParameters(new ReportParameter("para_KHDW", "杭州市QWE有限公司")); ReportViewer1.LocalReport.SetParameters(new ReportParameter("para_QYSJ", "2018-7-10")); //DataTable dt = GetData(); //ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt); //ReportViewer1.LocalReport.DataSources.Clear(); //ReportViewer1.LocalReport.DataSources.Add(rds); }
5、数据源动态,不需要外在数据集
<rd:DataSetInfo> <rd:DataSetName>ProductOrderSource</rd:DataSetName> <rd:TableName>ProductOrderDetail</rd:TableName> <rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod> </rd:DataSetInfo>
去掉 <rd:SchemaPath>D:\ERP编程\海纳管理软件\KAIERP\FDataSet1.xsd</rd:SchemaPath>