找回密码
 立即注册

QQ登录

只需一步,快速开始

leo.wei

初级会员

18

主题

64

帖子

202

积分

初级会员

积分
202
leo.wei
初级会员   /  发表于:2017-5-9 09:01  /   查看:3862  /  回复:9
如题 新建区域报表如何加载?见一下示例代码:SectionReport report = new SectionReport();

StringWriter w = new StringWriter();
            XmlTextWriter xmlWriter = new XmlTextWriter(w)
            {
                Formatting = Formatting.Indented,
                Indentation = 1,
                IndentChar = '\t'
            };
            report.SaveLayout(xmlWriter);
            string rpt = w.ToString();
            byte[] data = Encoding.UTF8.GetBytes(rpt);
            MemoryStream reportStream= new MemoryStream(data);

reportStream.Position = 0;
            reportDesigner.LoadReport(XmlReader.Create(reportStream), DesignerReportType.Section);



这样加载不了 请问该怎么用代码处理呢?

9 个回复

倒序浏览
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2017-5-9 10:35:28
沙发
参考博客:http://blog.gcpowertools.com.cn/post/enduserdesigner.aspx
  1. public static void BuildSectionReportLayout(Design.Designer designer)
  2.         {
  3.             // 空白区域报表
  4.             string rpx = "<?xml version="1.0" encoding="utf-8"?> <ActiveReportsLayout Version="3.2" PrintWidth="9360" DocumentName="ActiveReports Document" ScriptLang="C#" MasterReport="0"> <StyleSheet> <Style Name="Normal" Value="font-family: Arial; font-style: normal; text-decoration: none; font-weight: normal; font-size: 10pt; color: Black; text-align: left; vertical-align: top; ddo-char-set: 1" />    <Style Name="Heading1" Value="font-family: Arial; font-size: 16pt; font-style: normal; font-weight: bold" />                                <Style Name="Heading2" Value="font-family: Times New Roman; font-size: 14pt; font-style: italic; font-weight: bold" />                                <Style Name="Heading3" Value="font-family: Arial; font-size: 13pt; font-style: normal; font-weight: bold" />                              </StyleSheet>                              <Sections>                                <Section Type="PageHeader" Name="PageHeader1" Height="360" BackColor="16777215" />                                <Section Type="Detail" Name="Detail1" Height="2880" BackColor="16777215" />                                <Section Type="PageFooter" Name="PageFooter1" Height="360" BackColor="16777215" />                              </Sections>                              <ReportComponentTray />                              <PageSettings />                              <Parameters />                            </ActiveReportsLayout>";
  5.             // 区域报表数据源结构
  6.             System.Data.DataTable dt = new System.Data.DataTable();
  7.             dt.Columns.Add("Col1");
  8.             dt.Columns.Add("Col2");
  9.             dt.Columns.Add("Col3");
  10.             designer.Report = null;
  11.             // 加载区域报表到设计器
  12.             designer.LoadReport(XmlReader.Create(LayoutBuilder.CovertStringToStream(rpx)), DesignerReportType.Section);
  13.             // 设置区域报表数据源
  14.             SectionReport sr2 = designer.Report as SectionReport;
  15.             sr2.DataSource = dt;
  16.         }
复制代码




回复 使用道具 举报
leo.wei
初级会员   /  发表于:2017-5-9 10:54:46
板凳
Lenka.Guo 发表于 2017-5-9 10:35
参考博客:http://blog.gcpowertools.com.cn/post/enduserdesigner.aspx

LayoutBuilder是哪个类库下的,代码能具体点吧 类似我发出的代码 可以直接用的
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2017-5-9 10:59:55
地板
上面给的博客链接中有源码下载,您可以看看。LayoutBuilder 是自定义类
回复 使用道具 举报
leo.wei
初级会员   /  发表于:2017-5-9 11:12:41
5#
Lenka.Guo 发表于 2017-5-9 10:59
上面给的博客链接中有源码下载,您可以看看。LayoutBuilder 是自定义类

byte[] data = Encoding.UTF8.GetBytes(rpt);
            MemoryStream reportStream= new MemoryStream(data);
工具类只是写了这个而已 问题是我这么获取layout字符串;
StringWriter w = new StringWriter();
            XmlTextWriter xmlWriter = new XmlTextWriter(w)
            {
                Formatting = Formatting.Indented,
                Indentation = 1,
                IndentChar = '\t'
            };
            report.SaveLayout(xmlWriter);
            string rpt = w.ToString();
这样获取字符串会一直在加载 请问正确的写法是什么?
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2017-5-9 12:02:49
6#
您是想把已经创建好的区域报表读到设计器当中?
  1. public static SectionReport AddDataSectionSetDataSource()
  2.         {
  3.             SectionReport report = new SectionReport();
  4.            

  5.             report.LoadLayout("..\\..\\SectionReport2.rpx");
  6.             Data.OleDBDataSource ds = new Data.OleDBDataSource();
  7.             ds.ConnectionString = Properties.Resources.ConnectionString;
  8.             ds.SQL = Constants.cmdText;
  9.             report.DataSource = ds;
  10. System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter("..\\..\\SectionReport2.rpx", null);
  11.             report.SaveLayout(xtw);
  12.             return report;
  13.         
  14.         }


  15. ......

  16. .....

  17. ...

  18. SectionReport sr = LayoutBuilder.AddDataSectionSetDataSource();
  19.             reportDesigner.LoadReport(new FileInfo("..\\..\\SectionReport2.rpx"));
  20.             sr.Dispose();  
复制代码


回复 使用道具 举报
leo.wei
初级会员   /  发表于:2017-5-9 12:04:18
7#
Lenka.Guo 发表于 2017-5-9 12:02
您是想把已经创建好的区域报表读到设计器当中?

解决了 谢了
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2017-5-9 12:08:54
8#
OK, Thanks your feedback
回复 使用道具 举报
leo.wei
初级会员   /  发表于:2017-5-9 17:42:50
9#
Lenka.Guo 发表于 2017-5-9 12:08
OK, Thanks your feedback

ar9 区域报表怎么实现表格 动态行和动态列 以及单元格的边框
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2017-5-9 17:45:19
10#
新问题发新帖
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部