天下同道 发表于 2022-5-7 20:18:39

AR15 导出excel字段太长导致自动换行

在AR 15中,字段太长,导致导出的excel出现自动换行的问题,如何可以解决?

这是我的后台代码

public partial class Index : System.Web.UI.Page
    {
      private EmpReport empReport;
      protected void Page_Load(object sender, EventArgs e)
      {
            empReport = new EmpReport();
            empReport.DataSource = this.GetEmpData();
            empReport.Run();
            this.webViewer.Report = empReport;
      }

      private DataTable GetEmpData() {

            var dt = new DataTable();
            dt.Columns.Add("EmpId", typeof(int));
            dt.Columns.Add("EmpName", typeof(string));
            dt.Columns.Add("EmpClient", typeof(string));

            for (int i = 0; i < 10; i++)
            {
                dt.Rows.Add(i, $"emp-{i}",$"client-{i}");
            }
            dt.Rows["EmpClient"] = "very long very longvery long very long";
            return dt;
      }

      protected void btnExport_Click(object sender, EventArgs e)
      {
            empReport = new EmpReport();
            empReport.DataSource = this.GetEmpData();
            empReport.Run();

            XlsExport xlsExport = new XlsExport();
            var stream = new MemoryStream();
            xlsExport.AutoRowHeight = true;
            xlsExport.UseCellMerging = false;
            
            xlsExport.Export(this.empReport.Document, stream);
            stream.Position = 0;

            var guid = Guid.NewGuid().ToString("N");
            var reportBytes = stream.ToArray();
            Response.Clear();
            Response.ContentType = "application/force-download";
            Response.AddHeader("content-disposition", $"attachment; filename=empreport-{guid}.xls");
            Response.BinaryWrite(reportBytes);
            Response.End();
      }
    }

导出的excel 截图

我不想字段自动换行,应该如何设置呢?


Bella.Yuan 发表于 2022-5-7 20:18:40

天下同道 发表于 2022-5-9 21:08
你好,这样的话,报表显示出来的字不全。还有其他方案吗
您好,在导出时设置属性UseCellMerging为true,参考下图,您测试看看效果。

wengMQ 发表于 2022-5-8 10:45:43

你用的导出是过时的导出方法,可以加我QQ546962925沟通下

天下同道 发表于 2022-5-8 12:58:16

wengMQ 发表于 2022-5-8 10:45
你用的导出是过时的导出方法,可以加我QQ546962925沟通下

两种导出都得到一样的结果,已加QQ

天下同道 发表于 2022-5-8 13:33:52

本帖最后由 天下同道 于 2022-5-8 13:44 编辑

更新一下,我用的是区域报表(Section Report - Base on Code)不管是AR viewer自带的导出,还是手动导出的excel都会出现字段太长导致自动换行。这个在AR 11里面不会发生,AR 15里面有什么方法可以解决这个问题?

James.Lv 发表于 2022-5-9 18:15:25

天下同道 发表于 2022-5-8 13:33
更新一下,我用的是区域报表(Section Report - Base on Code)不管是AR viewer自带的导出,还是手动导出的ex ...

您好,这个您可以在不需要换行的文本框设置属性

天下同道 发表于 2022-5-9 21:08:19

James.Lv 发表于 2022-5-9 18:15
您好,这个您可以在不需要换行的文本框设置属性

你好,这样的话,报表显示出来的字不全。还有其他方案吗
页: [1]
查看完整版本: AR15 导出excel字段太长导致自动换行