1. 程式人生 > >[轉]簡單的動態修改RDLC報表頁邊距和列寬的方法

[轉]簡單的動態修改RDLC報表頁邊距和列寬的方法

schema serve def name star nbsp http 動態 xpath

本文轉自:http://star704983.blog.163.com/blog/static/136661264201161604413204/

1.修改頁邊距

XmlDocument XMLDoc = new XmlDocument(); XMLDoc.Load(System.Windows.Forms.Application.StartupPath + @"\Report_try-2.rdlc"); XmlNamespaceManager xmn = new XmlNamespaceManager(XMLDoc.NameTable); xmn.AddNamespace("X", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition"); string strXPath; strXPath = "/X:Report/X:Page/X:LeftMargin"; XmlNode Node = XMLDoc.SelectSingleNode(strXPath, xmn).ChildNodes.Item(0); // 讀取左邊距 Node.InnerText = "20mm"; // 左邊距改為20mm XMLDoc.Save(System.Windows.Forms.Application.StartupPath + @"\Report_try-2.rdlc"); // 寫XML 修改右、上、下邊距方法和上述方法一樣,只需要更改 strXPath = "/X:Report/X:Page/X:LeftMargin
"; 2.修改表格列寬 XmlDocument XMLDoc = new XmlDocument(); XMLDoc.Load(System.Windows.Forms.Application.StartupPath + @"\Report_try-2.rdlc"); XmlNamespaceManager xmn = new XmlNamespaceManager(XMLDoc.NameTable); xmn.AddNamespace("X", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition"); string strXPath; strXPath = "/X:Report/X:Body/X:ReportItems/X:Tablix/X:TablixBody"; XmlNodeList NDList = XMLDoc.SelectSingleNode(strXPath, xmn).ChildNodes; XmlNode subNode = NDList.Item(0); /* subNode.ChildNodes.Count即為報表列數 subNode.ChildNodes.Item(X).innerText即為第X列的列寬,X下標從0開始 */ subNode.ChildNodes.Item(0).InnerText = "20mm"; // 修改第一列列寬為20mm XMLDoc.Save(System.Windows.Forms.Application.StartupPath + @"\Report_try-2.rdlc"); // 寫XML

[轉]簡單的動態修改RDLC報表頁邊距和列寬的方法