原文:将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); // 创建一个根节点Report
XmlElement 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报表的函数的更多相关文章

  1. 只需2分钟!PC端的报表即可转换成手机报表

    转: 只需2分钟!PC端的报表即可转换成手机报表 手机制作报表,这个大家不知有没有尝试过,虽然我们平时都用电脑做,但是电脑要是不在身边了,手机就可以用来应应急.但其实小编并没有在手机上制作报表的实践经 ...

  2. PHP 数字金额转换成中文大写金额的函数 数字转中文

    /** *数字金额转换成中文大写金额的函数 *String Int $num 要转换的小写数字或小写字符串 *return 大写字母 *小数位为两位 **/ function num_to_rmb($ ...

  3. VB中将INT型转换成STRING和从STRING转换成INT型的函数

    CStr 函数示例本示例使用 CStr 函数将一数值转换为 String. Dim MyDouble, MyStringMyDouble = 437.324   ' MyDouble 为 Double ...

  4. 算法练习-字符串转换成整数(实现atoi函数)

    练习问题来源 https://leetcode.com/problems/string-to-integer-atoi/ https://wizardforcel.gitbooks.io/the-ar ...

  5. 如何将jsp页面的table报表转换到excel报表导出

    假设这就是你的jsp页面: 我们会添加一个“导出到excel”的超链接,它会把页面内容导出到excel文件中.那么这个页面会变成这个样子 在此,强调一下搜索时关键词的重要性,这样一下子可以定位到文章, ...

  6. XE3随笔16:将字符串转换成 UTF8 编码的函数

    这种转换一般用于网页地址; 我不知道 Delphi 是不是有现成的函数, 用到了就写了一个. //函数: function ToUTF8Encode(str: string): string; var ...

  7. SQLSERVER金额转换成英文大写的函数

    CREATE FUNCTION [dbo].[f_num_eng] (@num numeric(15,2)) RETURNS varchar(400) WITH ENCRYPTION AS BEGIN ...

  8. ORACLE金额转换成英文大写的函数

    用法如下:get_capital_money(Currency, Money) Currency: 货币或货币描述,将放在英文大写的前面: Money:金额.支持两位小数点.如果需要更多的小数点,请自 ...

  9. 动态生成RDLC报表

    前段时间,做了RDLC报表,主要是三块功能: 1.从DataGrid提取(包括最新的增删改)的数据,自动生成对应的RDLC报表文件(以流的形式驻存在内存中),用ReportViewer类来展示.打印. ...

随机推荐

  1. jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想)

    jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想) 一.总结 1.多看学习视频:洞悉原理,触类旁通, 2.函数封装:$.post(URL,data,callback); ...

  2. UTC时间与当地时间的转换关系?

    UTC时间与当地时间转换关系? 一.总结 1.UTC +时区差=本地时间 2.UTC是世界统一时间 二.UTC时间是什么 1.UTC时间 协调世界时,又称世界统一时间.世界标准时间.国际协调时间.由于 ...

  3. source insight 添加自定义macro

    打开C:\Documents and Settings\xxxx\My Documents\Source Insight\Projects\Base文件夹下的em文件,可以看到都是由macro定义的一 ...

  4. DOM中Event 对象如何使用

    DOM中Event 对象如何使用 一.总结 一句话总结: 1.将event作为参数传递进来,然后就可以调用event对象的各种属性和方法了. <body onmousedown="wh ...

  5. UITextView的一些事1

    TextView如果只是作为展示文本时,要设置如下属性: //不可编辑(是否弹出键盘) TextView_label.editable=NO; //不可选择(长按不会出现复制.粘贴) TextView ...

  6. push的时候隐藏底部的tabbar

    push的时候隐藏底部的tabbar #import "mainNavigationControllers.h" @interface mainNavigationControll ...

  7. Xcode 4.5( iOS6 SDK)、旧版本号cocos2d,支持iPhone5解析度

    支持iPhone5全屏 1假设没有支持iPhone5是否.直接运行程序可以准备提交.开放iPhone5模拟器,你会发现上面有黑色的程序.没有矩形. 2真正运行该程序时,.你会发现程序回程屏幕高度.它是 ...

  8. SCJP考试题310-025(第二套<4>)92-147/147

    310-025 Leading the way in IT testing and certification tools,QUESTION NO: 92 Given: 1. String foo = ...

  9. Airflow 使用简介

  10. std::string 简单入门

    string的定义原型 typedef basic_string<char, char_traits<char>, allocator<char> > string ...