本文转自: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