将RDL报表转换成RDLC报表的函数
生活随笔
收集整理的這篇文章主要介紹了
将RDL报表转换成RDLC报表的函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:將RDL報表轉換成RDLC報表的函數
近日研究RDLC報表,發現其不能與RDL報表兼容,尤其是將RDL報表轉換成RDLC報表。網上的資料貼出的的轉換方式復雜且不切實際,遂決定深入研究。經研究發現,RDL報表與RDLC報表的XML格式有些差異,將RDL報表的XML格式改成與RDLC報表的XML格式相同,發現轉換成功! 如需轉換123.rdl文件,只需RDLConvertRDLC("123.rdl"),即可轉換成123.rdlc文件。由于本人對帶命名空間的XML文件操作不熟悉,不能將除根節點意外的其他節點的xmlns屬性只去掉,如有高手,歡迎指教! private void RDLConvertRDLC(string strFile){if(File.Exists(strFile)){try{XmlDocument xmlBak;XmlNamespaceManager nsMgrBak;XmlNodeList Reports;// 打開需轉換的XML文件try{xmlBak = new XmlDocument();xmlBak.Load(strFile);nsMgrBak = new XmlNamespaceManager(xmlBak.NameTable);nsMgrBak.AddNamespace("nsBak", "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition");Reports = xmlBak.SelectSingleNode("/nsBak:Report", nsMgrBak).ChildNodes;}catch{File.Move(strFile, strFile + "c");return;}// 創建新的XML文件XmlDocument xmlDoc = new XmlDocument();XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);xmlDoc.AppendChild(dec);// 創建一個根節點ReportXmlElement root = xmlDoc.CreateElement("Report");root.SetAttribute("xmlns:rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");root.SetAttribute("xmlns", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition");xmlDoc.AppendChild(root);// 拷貝節點數據到新XML文件for (int i = 0; i < Reports.Count; i++){if (Reports[i].Name != "AutoRefresh"){if (Reports[i].Name == "ReportSections"){XmlNodeList ReportSections = xmlBak.SelectSingleNode("/nsBak:Report/nsBak:ReportSections/nsBak:ReportSection", nsMgrBak).ChildNodes;for (int j = 0; j < ReportSections.Count; j++){XmlElement newElement = (XmlElement)xmlDoc.ImportNode(ReportSections[j], true);newElement.SetAttribute("xmlns", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition");root.AppendChild(newElement);}}else{XmlElement newElement = (XmlElement)xmlDoc.ImportNode(Reports[i], true);newElement.SetAttribute("xmlns", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition");root.AppendChild(newElement);}}}xmlDoc.Save(@strFile + "c");File.Delete(strFile);}catch (System.Exception ex){MessageBox.Show(ex.Message.ToString(), "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information);}}else{MessageBox.Show("文件"+strFile+"不存在!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information);}}}
總結
以上是生活随笔為你收集整理的将RDL报表转换成RDLC报表的函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android电话拨号器的使用
- 下一篇: 50条经典爱情观