找回密码
 立即注册

QQ登录

只需一步,快速开始

lovezixue

高级会员

3

主题

7

帖子

1629

积分

高级会员

积分
1629
最新发帖
lovezixue
高级会员   /  发表于:2015-12-24 15:13  /   查看:7071  /  回复:5
调用Reports10生成Excel 但是必须给Label 一个Left值 导致每一列中间都有一个空白的列,有没有办法叫他自适应每一列的宽,比如他的文本过长就会把这一行撑大而不是折行或截掉?
下面是我现在的代码,求高手帮忙

  1.         private string CreateTXTOrExcelFlexReportByDetailXml(DetailXml detailXml, string eReportType, DataTable dt)
  2.         {
  3.             SectionReport m_arReport = new SectionReport();

  4.             m_arReport.DataSource = dt;

  5.             if (detailXml.Table != null)
  6.             {
  7.                
  8.                 m_arReport.Document.Name = detailXml.Table.Name;

  9.                 ReportHeader m_oReportHeader = new ReportHeader();
  10.                 m_oReportHeader.Name = "ReportHeader";
  11.                 m_oReportHeader.Height = 0.2f;
  12.                 m_arReport.Sections.Add(m_oReportHeader);

  13.                 var m_oPageHeader = new PageHeader();
  14.                 m_oPageHeader.Name = "PageHeader";
  15.                 m_arReport.Sections.Add(m_oPageHeader);

  16.                 var m_oPageDetail = new GrapeCity.ActiveReports.SectionReportModel.Detail();
  17.                 m_oPageDetail.Name = "Detail";
  18.                 m_arReport.Sections.Add(m_oPageDetail);

  19.                 var m_oPageFooter = new PageFooter();
  20.                 m_oPageFooter.Name = "PageFooter";
  21.                 m_arReport.Sections.Add(m_oPageFooter);

  22.                 var m_oReportFooter = new ReportFooter();
  23.                 m_oReportFooter.Name = "ReportFooter";
  24.                 m_arReport.Sections.Add(m_oReportFooter);

  25.                 float nLeft = 0;

  26.                 foreach (DetailXmlColumn column in detailXml.Table.Columns)
  27.                 {
  28.                     if (column.IsVisible)
  29.                     {
  30.                         Label lblLable = new Label();
  31.                         //lblLable.Height = 0.18f;
  32.                         lblLable.Name = "lbl" + column.Name;
  33.                         lblLable.Text = column.Heading.Text;
  34.                         lblLable.Left = nLeft;
  35.                         //lblLable.Width = FIELD_WIDTH;
  36.                         //lblLable.Height = FIELD_HEIGHT;
  37.                         lblLable.Style = getFontStyle(column.Heading.style);
  38.                         m_oReportHeader.Controls.Add(lblLable);

  39.                         TextBox txtBox = new TextBox();
  40.                         txtBox.Name = "txt" + column.Name;
  41.                         txtBox.DataField = column.Name;
  42.                         txtBox.CanShrink = true;
  43.                         txtBox.Top = 0;
  44.                         txtBox.Left = nLeft;
  45.                         txtBox.CanGrow = true;
  46.                         txtBox.MultiLine = false;
  47.                         //txtBox.Width = FIELD_WIDTH;
  48.                         //txtBox.Height = FIELD_HEIGHT;
  49.                         txtBox.Style = getFontStyle(column.Table_cell.style);
  50.                         m_oPageDetail.Controls.Add(txtBox);

  51.                         nLeft += FIELD_WIDTH;
  52.                     }
  53.                 }
  54.                 m_arReport.PrintWidth = nLeft;
  55.             }

  56.             m_arReport.Run();
  57.             string fileName = "";
  58.             switch (eReportType)
  59.             {
  60.                 case "TXT":
  61.                     {
  62.                         fileName = "C:\\reports\\new" + Guid.NewGuid().ToString() + ".TXT";

  63.                         GrapeCity.ActiveReports.Export.Xml.Section.TextExport TxtExport = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport();
  64.                         TxtExport.Export(m_arReport.Document, fileName);
  65.                     }
  66.                     break;
  67.                 case "EXCEL":
  68.                     {
  69.                         fileName = "C:\\reports\\new" + Guid.NewGuid().ToString() + ".xlsx";
  70.                         GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsxExport = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
  71.                         XlsxExport.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
  72.                         XlsxExport.Export(m_arReport.Document, fileName);
  73.                     }
  74.                     break;
  75.             }

  76.             return fileName;
  77.         }
复制代码


现在的EXCEL效果是这样:


我需要的效果是这样的:



求高手帮忙看一下,不胜感激。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

5 个回复

倒序浏览
frank.zhang
社区贡献组   /  发表于:2015-12-24 17:35:00
沙发
您好,

这个问题下图所示的位置换行导致的。




建议您在一行显示,或者使用RDL报表。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
lovezixue
高级会员   /  发表于:2015-12-29 08:57:00
板凳
回复 2楼frank.zhang的帖子

怎么显示在一行??给它宽度要不就是截取 要不还是会换行。
回复 使用道具 举报
frank.zhang
社区贡献组   /  发表于:2015-12-29 13:40:00
地板
您好,

设置以下属性看是否能够解决问题


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
lovezixue
高级会员   /  发表于:2015-12-29 13:40:00
5#
回复 4楼frank.zhang的帖子

好的 我试一下 谢谢~~
回复 使用道具 举报
frank.zhang
社区贡献组   /  发表于:2015-12-29 16:32:00
6#
不客气
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部