调用Reports10生成Excel 但是必须给Label 一个Left值 导致每一列中间都有一个空白的列,有没有办法叫他自适应每一列的宽,比如他的文本过长就会把这一行撑大而不是折行或截掉?
下面是我现在的代码,求高手帮忙
- private string CreateTXTOrExcelFlexReportByDetailXml(DetailXml detailXml, string eReportType, DataTable dt)
- {
- SectionReport m_arReport = new SectionReport();
- m_arReport.DataSource = dt;
- if (detailXml.Table != null)
- {
-
- m_arReport.Document.Name = detailXml.Table.Name;
- ReportHeader m_oReportHeader = new ReportHeader();
- m_oReportHeader.Name = "ReportHeader";
- m_oReportHeader.Height = 0.2f;
- m_arReport.Sections.Add(m_oReportHeader);
- var m_oPageHeader = new PageHeader();
- m_oPageHeader.Name = "PageHeader";
- m_arReport.Sections.Add(m_oPageHeader);
- var m_oPageDetail = new GrapeCity.ActiveReports.SectionReportModel.Detail();
- m_oPageDetail.Name = "Detail";
- m_arReport.Sections.Add(m_oPageDetail);
- var m_oPageFooter = new PageFooter();
- m_oPageFooter.Name = "PageFooter";
- m_arReport.Sections.Add(m_oPageFooter);
- var m_oReportFooter = new ReportFooter();
- m_oReportFooter.Name = "ReportFooter";
- m_arReport.Sections.Add(m_oReportFooter);
- float nLeft = 0;
- foreach (DetailXmlColumn column in detailXml.Table.Columns)
- {
- if (column.IsVisible)
- {
- Label lblLable = new Label();
- //lblLable.Height = 0.18f;
- lblLable.Name = "lbl" + column.Name;
- lblLable.Text = column.Heading.Text;
- lblLable.Left = nLeft;
- //lblLable.Width = FIELD_WIDTH;
- //lblLable.Height = FIELD_HEIGHT;
- lblLable.Style = getFontStyle(column.Heading.style);
- m_oReportHeader.Controls.Add(lblLable);
- TextBox txtBox = new TextBox();
- txtBox.Name = "txt" + column.Name;
- txtBox.DataField = column.Name;
- txtBox.CanShrink = true;
- txtBox.Top = 0;
- txtBox.Left = nLeft;
- txtBox.CanGrow = true;
- txtBox.MultiLine = false;
- //txtBox.Width = FIELD_WIDTH;
- //txtBox.Height = FIELD_HEIGHT;
- txtBox.Style = getFontStyle(column.Table_cell.style);
- m_oPageDetail.Controls.Add(txtBox);
- nLeft += FIELD_WIDTH;
- }
- }
- m_arReport.PrintWidth = nLeft;
- }
- m_arReport.Run();
- string fileName = "";
- switch (eReportType)
- {
- case "TXT":
- {
- fileName = "C:\\reports\\new" + Guid.NewGuid().ToString() + ".TXT";
- GrapeCity.ActiveReports.Export.Xml.Section.TextExport TxtExport = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport();
- TxtExport.Export(m_arReport.Document, fileName);
- }
- break;
- case "EXCEL":
- {
- fileName = "C:\\reports\\new" + Guid.NewGuid().ToString() + ".xlsx";
- GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsxExport = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
- XlsxExport.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
- XlsxExport.Export(m_arReport.Document, fileName);
- }
- break;
- }
- return fileName;
- }
复制代码
现在的EXCEL效果是这样:
我需要的效果是这样的:
求高手帮忙看一下,不胜感激。 |