Asp.net Report动态生成
2024-08-26 22:08:42
rdlc报表实质上是一个xml文件,如果要实现动态报表,就需要动态生成rdlc文件,实质上就是读写xml文件:
protected XmlDocument GenerationAddReportColumn(IList<ReportColumn> columnList,
string fromRdlcPath, string toRdlcPath)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath(fromRdlcPath)); XmlNodeList fileds = xmlDoc.GetElementsByTagName("Fields");
XmlNodeList tablixColumns = xmlDoc.GetElementsByTagName("TablixColumns");
XmlNodeList tablixMembers = xmlDoc.GetElementsByTagName("TablixColumnHierarchy");
XmlNodeList tablixRows = xmlDoc.GetElementsByTagName("TablixRows"); foreach (var item in columnList)
{
//添加Field节点
XmlNode filedNode = fileds.Item().FirstChild.CloneNode(true);
if (!fileds.Item().ChildNodes.Cast<XmlNode>().Any(c=>c.Attributes["Name"].Value==item.Field))
{
filedNode.Attributes["Name"].Value = item.Field;
filedNode.FirstChild.InnerText = item.Field;
filedNode.ChildNodes[].InnerText = string.IsNullOrWhiteSpace(item.FieldType) ? "System.String" : item.FieldType;
fileds.Item().AppendChild(filedNode);
} //添加TablixColumn
XmlNode tablixColumn = tablixColumns.Item().FirstChild;
XmlNode newtablixColumn = tablixColumn.CloneNode(true);
newtablixColumn.FirstChild.InnerText = item.Width;
tablixColumns.Item().AppendChild(newtablixColumn); //TablixMember
XmlNode tablixMember = tablixMembers.Item().FirstChild.FirstChild;
XmlNode newTablixMember = tablixMember.CloneNode(true);
tablixMembers.Item().FirstChild.AppendChild(newTablixMember); var tablixRowsRowCells1 = tablixRows.Item().FirstChild.ChildNodes[];
XmlNode tablixRowCell1 = tablixRowsRowCells1.FirstChild;
XmlNode newtablixRowCell1 = tablixRowCell1.CloneNode(true);
var textBox1 = newtablixRowCell1.FirstChild.ChildNodes[];
textBox1.Attributes["Name"].Value = "Textbox_"+item.Field; var paragraphs = textBox1.ChildNodes.Cast<XmlNode>().Where(c => c.Name == "Paragraphs").FirstOrDefault();
paragraphs.FirstChild.FirstChild.FirstChild.FirstChild.InnerText = item.ColumnName;
var defaultName1 = textBox1.ChildNodes.Cast<XmlNode>().Where(c => c.Name == "rd:DefaultName").FirstOrDefault().InnerText = "Textbox_" + item.Field; tablixRowsRowCells1.AppendChild(newtablixRowCell1); var tablixRowsRowCells2 = tablixRows.Item().ChildNodes[].ChildNodes[];
XmlNode tablixRowCell2 = tablixRowsRowCells2.FirstChild;
XmlNode newtablixRowCell2 = tablixRowCell2.CloneNode(true);
var textBox2 = newtablixRowCell2.FirstChild.ChildNodes[];
textBox2.Attributes["Name"].Value = item.Field; var paragraphs2 = textBox2.ChildNodes.Cast<XmlNode>().Where(c => c.Name == "Paragraphs").FirstOrDefault();
paragraphs2.FirstChild.FirstChild.FirstChild.FirstChild.InnerText = "=Fields!" + item.Field + ".Value";
var defaultName2 = textBox2.ChildNodes.Cast<XmlNode>().Where(c => c.Name == "rd:DefaultName").FirstOrDefault().InnerText = item.Field; tablixRowsRowCells2.AppendChild(newtablixRowCell2); } xmlDoc.Save(Server.MapPath(toRdlcPath));
return xmlDoc; }
/// <summary>
/// 报表列描述
/// </summary>
public class ReportColumn
{
public string Field { get; set; } public string ColumnName { get; set; } public string Width { get; set; } public string FieldType { get; set; }
}
最新文章
- IaaS、PaaS、SaaS 之间的区别
- 【译】About the Java Technology
- linux mount 硬盘挂载和卸载
- 19.fastDFS集群理解+搭建笔记
- DLL分类
- Asp.Net MVC 路由
- Silverlight 读取配置文件
- Cocos2d-android (02) 添加一个精灵对象
- Mysql 分页语句Limit用法
- MyEclipse server窗口 Could not create the view: An unexpected exception was thrown 错误解决
- Activity被回收导致fragment的getActivity为null的解决办法
- MySQL基础----动态SQL语句
- JavaWeb开发环境搭建Eclipse配置Tomcat
- 什么是Zookeeper?
- 正态分布-python建模
- Net中应用 Redis 扩展类
- pycharm 的操作1
- 模拟界面请求到web服务器
- js比较两个String字符串找出不同,并将不同处高亮显示
- Asm 常用资源
热门文章
- Xamarin图表开发基础教程(1)
- flutter PopupMenuButton弹出式菜单列表
- pytorch 计算图像数据集的均值和标准差
- Laya的资源加载
- 报错:(未解决)Opening socket connection to server master/192.168.52.26:2181. Will not attempt to authenticate using SASL (unknown error)
- PngOptimizer PNG压缩工具
- Docker:学习笔记(1)——基础概念
- robot:List变量的使用注意点
- 干货 | 20多门AI网络课程资源(附链接+PDF)
- php面向对象(文件操作)