1、?對Table中的詳細內容,以不同的背景色間隔開相鄰的兩行:
A:選擇Table的Detail行,選擇屬性中的BackgroundColor,值選擇表達式,輸入:=iif(
RowNumber
(Nothing) Mod 2, "White", "Beige")。組內設置不同底色則將Nothing改為相應的組名,如“Table1_Group1”;
2、僅在組的外邊框設置線顏色的方法(縱向合并單元格):
A:設置BorderStyle-Bottom表達式為:=iif(RowNumber("Table1_Group1") = CountRows("Table1_Group1") , "White", "Beige");
3、報表常常需要用到參數起始日期和結束日期,并且需要將起始日期默認為本月第一天,結束日期默認為本月最后一天:
參數OccurDateFrom的默認值設置為表達式=DateAdd("d", 1-Day(Today), Today);參數OccurDateTo的默認值設置為表達式=DateAdd("d", -1, DateSerial(IIf(Month(Today)=12,Year(Today)+1,Year(Today)), IIf(Month(Today)=12,1,Month(Today)+1), 1))就能滿足需求咯;
4、在同一張報表上顯示數據報表和圖表(如直方圖),并且根據“顯示直方圖”參數切換:
新增參數IsShowChart(Boolean型),默認值=false;然后將報表(Table1)和圖表(Chart1)的Location設置為一樣;
Table1的Visibility.Hidden設置為表達式=Parameters!IsShowChart.Value;Chart1的Visibility.Hidden設置為表達式=Not Parameters!IsShowChart.Value就可以實現根據參數切換報表和圖表了;
5、設置每頁顯示Table表頭或表尾:
A:選擇Table Header或Table Footer,將屬性中的RepeatOnNewpage設為True;
6、在每頁都顯示放入的圖片或標題頭等信息:
A:只須在Table Header中加行數,把你要顯示的內容放到單元格中,然后再按第 5 點方式設置后就可以了;
7、報表插入圖片的方法:
A:需要將插入的圖像報表項的Source屬性設置為extern,且將Value設置文件全路徑(且以file://打頭),譬如:
file://E:/VSTS/SSRS/ReportServiceClient/Wave.jpg
;并且需設置reportViewer1.LocalReport.EnableExternalImages = true;
B:對于動態獲取圖片則需要將Source屬性設置為DataBase,Value=System.Convert.FromBase64String(Fields!BarCode.Value),上面示例是按數據源的屬性BarCode(string類型),類屬性代碼見下面:
public string BarCode
{
get
{
BarcodeLib.Barcode b = new BarcodeLib.Barcode();
b.IncludeLabel = true ;
Image img = b.Encode(BarcodeLib.TYPE.CODE39, BillNo);
return Convert.ToBase64String(BitmapToBytes(img as Bitmap));
}
}
private byte [] BitmapToBytes(Bitmap Bitmap)
{
MemoryStream ms = null ;
try
{
ms = new MemoryStream();
Bitmap.Save(ms, ImageFormat.Gif);
byte [] byteImage = new Byte[ms.Length];
byteImage = ms.ToArray();
return byteImage;
}
catch (ArgumentNullException ex)
{
throw ex;
}
finally
{
ms.Close();
}
}
8、
獲取參數列表的方法
首先添加web引用:
http://server/reportserver/reportservice.asmx
????????{
???????????? // 獲取參數的方法之二(不能獲取元數據)
????????????RS2005.ReportingService?rService? = ? new ?RS2005.ReportingService(); // 創建報表服務實例
????????????rService.Credentials? = ?System.Net.CredentialCache.DefaultCredentials; // 設置默認系統憑據
????????????rService.Url? = ?url;
???????????? string ?historyID? = ? null ;
???????????? bool ?forRendering? = ? true ;
????????????RS2005.ParameterValue[]?values? = ? null ;
????????????RS2005.DataSourceCredentials[]?credentials? = ? null ;
????????????RS2005.ReportParameter[]?parameters;
????????????parameters? = ?rService.GetReportParameters(reportPath,?historyID,?forRendering,?values,?credentials);
???????????? return ?parameters;
????????}
?
9、獲取參數及其元數據(如參數的默認值表達式等):
{
????Report?report? = ? null ;
????RS2005.ReportingService?rService? = ? new ?RS2005.ReportingService(); // 創建報表服務實例
????rService.Credentials? = ?System.Net.CredentialCache.DefaultCredentials; // 設置默認系統憑據
????rService.Url? = ?url;
???? byte []?bytes? = ?rService.GetReportDefinition(reportPath);
???? if ?(bytes? != ? null )
????{
????????XmlSerializer?serializer? = ? new ?XmlSerializer( typeof (Report));
???????? using ?(MemoryStream?stream? = ? new ?MemoryStream(bytes))
????????{
????????????report? = ?(Report)serializer.Deserialize(stream);
????????}
????}
????List < ItemsChoiceType37 > ?reportItems? = ? new ?List < ItemsChoiceType37 > (report.ItemsElementName);
???? int ?index? = ?reportItems.IndexOf(ItemsChoiceType37.ReportParameters);
????ReportParametersType?parametersType? = ?report.Items[index]? as ?ReportParametersType;
????Dictionary < string ,? string > ?ps? = ? new ?Dictionary < string ,? string > ();
???? foreach ?(ReportParameterType?item? in ?parametersType.ReportParameter)
????{
????????ps.Add(item.Name,? string .Empty);
????????List < ItemsChoiceType33 > ?rptItems? = ? new ?List < ItemsChoiceType33 > (item.ItemsElementName);
????????index? = ?rptItems.IndexOf(ItemsChoiceType33.DefaultValue);
????????DefaultValueType?dvt? = ?item.Items[index]? as ?DefaultValueType;
????????ValuesType?vt? = ?dvt.Items[ 0 ]? as ?ValuesType;
????????ps[item.Name]? = ?vt.Value[ 0 ];
????}
???? return ?ps;
}
?
10、遍歷報表項的方法:
首先添加web引用:
http://server/reportserver/reportservice.asmx
rService.Credentials? = ?System.Net.CredentialCache.DefaultCredentials; // 默認系統憑據
CatalogItem[]?catalogItems;
catalogItems? = ?rService.ListChildren( " / " ,? true ); // 對根路徑檢索
foreach (CatalogItem?item? in ?catalogItems)
{
???? if (item.Type? == ItemTypeEnum.Folder)
{
// 遍歷報表文件夾
}
}
? foreach (CatalogItem?item? in ?catalogItems)
{
if (item.Type? == ItemTypeEnum.Report)
{
// 遍歷報表
}
}
// 搜索報表
ReportService.SearchCondition[]?condition = new ?SearchCondition[ 1 ];
condition[ 0 ] = new ?SearchCondition();
condition[ 0 ].Name? = " Name " ;
condition[ 0 ].Value? = this .TextBox1.Text?;
catalogItems = rs.FindItems?( " / " ,WebReportSample.ReportService?.BooleanOperatorEnum?.And?,condition);
// 發布報表
byte []?reportData;
System.IO?.FileStream?fs = System.IO?.File.OpenRead?( " c:\\Report1.rdl " );
reportData = new ? byte ?[fs.Length?];
fs.Read?(reportData, 0 ,fs.Length?);
rs.CreateReport?( " New?Report " , " / " , false ,reportData, null );
// 刪除報表
rs.DeleteItem?( " 報表名稱 " );
?11、子報表部署問題:
由于主報表中跳轉到子報表或嵌入子報表時僅設置子報表名稱,所以部署時必須確保子報表與主報表的路徑一致;
12、使用LocalReport.LoadSubreportDefinition 方法應注意的問題是如果主報表是通過ReportPath屬性獲取的則該方法將失效,原因是設置ReportPath的報表通過文件系統獲取報表定義元數據時也一并加載了它需要的子報表定義元數據。可以看看MSDN的備注,換言之,使用該方法前必須使用LocalReport.LoadReportDefinition 方法,且不能設置ReportPath。
原文描述如下:The
ReportViewer
control requires the definitions for all subreports before it can process a report. If the local report was loaded from the file system by specifying the
ReportPath
property, the
ReportViewer
control automatically loads the subreports from the file system. In cases where the local report was not loaded from the file system, these methods may be used to load report definitions for subreports.
13、報表的無會話打印問題,報表定義文件沒有設置“打印方向”的屬性,實際上如果需要打印 橫向 報表需要在創建PrintDocument時設置打印機參數,并且讀取deviecInfo信息時需要將報表定義文件的PageWidth和PageHeight互換下,參考代碼如下:
{
???? private ?EmfPrintDocument(PrinterInfo?printerInfo)
????{
???????? base .PrinterSettings.PrinterName? = ?printerInfo.PrinterName;
???????? base .DefaultPageSettings.Landscape? = ?printerInfo.Landscape;
???????? base .PrinterSettings.DefaultPageSettings.Landscape? = ?printerInfo.Landscape;
????}
???????? public ? static ?EmfPrintDocument?Create(PrinterInfo?printerInfo)
????????{
???????????? if ?( string .IsNullOrEmpty(printerInfo.PrinterName))
????????????{
????????????????printerInfo.PrinterName? = ?Printer.GetDeaultPrinterName();
????????????}
???????????? else
????????????{
???????????????? bool ?founded? = ? false ;
???????????????? foreach ?( string ?pname? in ?PrinterSettings.InstalledPrinters)
????????????????{
???????????????????? if ?(pname.Equals(printerInfo.PrinterName,?StringComparison.CurrentCultureIgnoreCase))
????????????????????{
????????????????????????printerInfo.PrinterName? = ?pname;
????????????????????????founded? = ? true ;
???????????????????????? break ;
????????????????????}
????????????????}
???????????????? if ?( ! founded)
????????????????{
???????????????????? throw ? new ?NotSupportedException( string .Format( " 找不到打印機?{0} " ? + ?printerInfo.PrinterName));
????????????????}
????????????}
???????????? return ? new ?EmfPrintDocument(printerInfo);
????????}
}
ReportPrintService的代碼:

使用實例:

using ?(ReportPrintService?rps? = ? new ?ReportPrintService())
{
????rps.Print(lp,?printerInfo);
}
14、服務器報表的方法SetParameters()?需要注意的問題:
(1)多值參數的類型是StringCollection而不是一個用逗號間隔的串;
(2)傳入的參數值如果在服務器報表的參數數據源中不存在該方法將報錯(報表的所有參數賦默認值);
(3)ReportViewer控件使用過程中如果發現展現出來的報表背景色全部變成了黑色,則需要將承載該控件的WindowsFormsHost設置其Background屬性設置為White;
(4)導出pdf時可能遇到導出的內容為????,需要修改下字體為“宋體”或其他基本字體;如果報表包含子報表則子報表無法導出內容;
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
