Rdlc優點:

  1:Rdlc報表設計簡單

  2: " /> 中文字幕小明,国产精品亚洲一区二区三区在线观看 ,亚洲精品国产综合一线久久

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

ASP.NET中動態控制RDLC報表

  在ASP.NET程序中,可以選擇使用水晶報表,功能確實強大。但是web版的水晶報表好像存在版權的問題。如果所作報表不是復雜的一塌糊涂的話,可以使用微軟自帶的Rdlc報表。

  Rdlc優點:

  1:Rdlc報表設計簡單

  2:結果存成xml,易于控制

  3:導出格式作的很不錯

  這里所說的動態控制報表所指的是:在一些時候,制作了報表之后希望在運行中可以動態的做一些小修改,比如說列的位置,用戶控制顯示那些列等等。

  控制方法,嘗試了這么幾種:

  1:控制微軟提供的報表對象的屬性;

  2:報表全部自動生成

  3:修改報表源文件,然后加載。

  控制微軟提供的報表對象的屬性:基于這個功能需求,一開始我想到的方法是通過控制微軟提供的這些報表對象的屬性來實現。因為這種方法最人道了。但是事與愿違,微軟的ReportViewer對象是用來顯示Report的,自然不行;我使用的report是自己設計的,localReport,找到Report對象,里面方法有這個幾個:report.GetDefaultPageSettings();report.GetDocumentMap()等,第一個是獲取打印紙張德設置,第二個是獲取doc文檔(但是始終出錯),都是只讀屬性;所以,第一種嘗試失敗。

  第二種方法就是報表全部自動生成。可以找到一個完整的例子,在這里:http://www.gotreportviewer.com/DynamicTable.zip
這個例子里面,他把xml結構的rdlc報表寫成一個類ReportDefinition,然后通過自定義這個類的內容來得到一個報表。其實際還是為了自己構造一個報表對象的xml。這是加載自定義報表的過程:win下的代碼 this.reportViewer1.Reset();

this.reportViewer1.LocalReport.LoadReportDefinition(m_rdl);
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("MyData", m_dataSet.Tables[0]));
this.reportViewer1.RefreshReport();這是自動生成xml的代碼:
private MemoryStream GenerateRdl(List<string> allFields, List<string> selectedFields)
{
 MemoryStream ms = new MemoryStream();
 RdlGenerator gen = new RdlGenerator();
 gen.AllFields = allFields;
 gen.SelectedFields = selectedFields;
 gen.WriteXml(ms);
 ms.Position = 0;
 return ms;
}

  這是完全ReportDefinition的一部分定義:

namespace Rdl {
 using System.Xml.Serialization;

 /**//// <remarks/>
 [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
 [System.SerializableAttribute()]
 [System.Diagnostics.DebuggerStepThroughAttribute()]
 [System.ComponentModel.DesignerCategoryAttribute("code")]
 [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
 [System.Xml.Serialization.XmlRootAttribute(Namespace=_
  "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition", IsNullable=false)]
 public partial class Report {
  private object[] itemsField;

  但是幾經考慮之后,這個方案也不讓人滿意,原因是:所有的報表對象都得自己生成,一下子回到了解放前,沒有可視化工具的設計既繁瑣又復雜。特別是如果設計幾個line,然后再來上幾個分組的話,工作量巨大。

  于是乎嘗試第三種方法:ReportVivwer加載報表前在內存中修改報表源文件。這個方法比較狠,其實可以解決很多問題,包括設計自定義的打印紙張等(這里有另外一種設置打印紙張的方法http://waxdoll.cnblogs.com/archive/2006/03/03/342435.html)。

  設計思路是:首先加載rdlc文件到一個XmlDocument對象;然后修改xml內容;把xml序列化成字節流,交給ReportViewer顯示。

  這是這一段代碼:

public MemoryStream GenerateRdlc()
{
 XmlDocument sourceDoc = new XmlDocument();
 string path = AppDomain.CurrentDomain.BaseDirectory + "Test/OrderList.rdlc";
 sourceDoc.Load(path);
 Hashtable reportColumns = GetReportColumns(sourceDoc.LastChild);
 //just remove
 for (int i = 0; i < reportColumns.Count; i++)
 {
  if (!FindReportCoulmns(reportColumns[i].ToString()))
  {
   RemoveColumnFromRdlc(sourceDoc.LastChild, i);
  }
 }

 MemoryStream ms = new MemoryStream();
 XmlSerializer serializer = new XmlSerializer(typeof(XmlDocument));
 serializer.Serialize(ms, sourceDoc);
 ms.Position = 0;
 return ms;
}
  至于如何GetReportColumns和RemoveColumnFromRdlc,那就很簡單了,就是一個操作xml對象的過程。比方說:

private Hashtable GetReportColumns(XmlNode root)
{
 Hashtable cols = new Hashtable();
 //XmlNamespaceManager s=new XmlNamespaceManager(
  XmlNode cells = FindChildNode(root,"Body/ReportItems/Table/Header/TableRows/TableRow/TableCells");
 for (int i = 0; i < cells.ChildNodes.Count; i++)
 {
  XmlNode cell =FindChildNode( cells.ChildNodes[i],"ReportItems/Textbox/DataElementName");
  cols[i] = cell.InnerText;
 }
 return cols;
}
  這是使用這一段的代碼:

this.ReportViewer1.LocalReport.LoadReportDefinition(this.Report.GenerateRdlc());
this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", result.Tables[0]));
this.ReportViewer1.LocalReport.Refresh();
  這個方法終于成功了。

  附:rdlc文件的xml一段結構

  xml結構

1<?xml version="1.0" encoding="utf-8"?>
2<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
3 <DataSources>
4 <DataSource Name="ConnectionString">
5 <ConnectionProperties>
6 <ConnectString />
7 <DataProvider>SQL</DataProvider>
8 </ConnectionProperties>
9 <rd:DataSourceID>073016a7-6cb0-4e06-a6fd-f5882a039188</rd:DataSourceID>
10 </DataSource>
11 </DataSources>
12 <BottomMargin>2.5cm</BottomMargin>
13 <RightMargin>2.5cm</RightMargin>
14 <PageWidth>21cm</PageWidth>
15 <rd:DrawGrid>true</rd:DrawGrid>
16 <InteractiveWidth>21cm</InteractiveWidth>
17 <rd:GridSpacing>0.25cm</rd:GridSpacing>
18 <rd:SnapToGrid>true</rd:SnapToGrid>
19 <Body>
20 <ColumnSpacing>1cm</ColumnSpacing>
21 <ReportItems>
22 <Chart Name="chart1">

AspNet技術ASP.NET中動態控制RDLC報表,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 在线亚洲小视频 | 美女黄的全免费 | 99精品视频在线观看免费播放 | 亚洲精品国产自在久久出水 | 在线免费看污视频 | 色老板视频在线观看 | 美女视频永久黄网站免费观看韩国 | 激情有码 | 激情福利视频 | 国产女视频 | 视频区 图片区 小说区 | 久久精品爱 | 久久久精品久久久久久久久久久 | 91欧美激情一区二区三区成人 | 天天干天天插天天 | 亚洲一区精品中文字幕 | 亚洲午夜视频在线观看 | 日本国产最新一区二区三区 | 涩久久 | 色噜噜噜噜噜 | 久久91综合国产91久久精品 | 在线综合亚洲欧美网站天堂 | 国产一区二区在线播放 | 综合激情文学 | 精品欧美一区二区三区精品久久 | 亚洲文学| 久久精品国产精品亚洲婷婷 | 女人被爽到呻吟娇喘的视频动态图 | 国产精品视频一区二区亚瑟 | 国产精品黄大片观看 | 在线激情小视频 | 激情图片亚洲 | 国产精品大全国产精品 | 久久中文娱乐网 | 久久精品亚洲一级毛片 | 亚洲乱码一二三四区国产 | 五月婷婷狠狠 | 2021国产麻豆剧 | 韩国一区二区三区 | 天天色天天爱 | 精品热久久 |