找回密码
 立即注册

QQ登录

只需一步,快速开始

天下同道

注册会员

2

主题

9

帖子

25

积分

注册会员

积分
25
  • 95

    金币

  • 2

    主题

  • 9

    帖子

最新发帖
天下同道
注册会员   /  发表于:2022-5-7 20:18  /   查看:1779  /  回复:6
1金币
在AR 15中,字段太长,导致导出的excel出现自动换行的问题,如何可以解决?

这是我的后台代码

  1. public partial class Index : System.Web.UI.Page
  2.     {
  3.         private EmpReport empReport;
  4.         protected void Page_Load(object sender, EventArgs e)
  5.         {
  6.             empReport = new EmpReport();
  7.             empReport.DataSource = this.GetEmpData();
  8.             empReport.Run();
  9.             this.webViewer.Report = empReport;
  10.         }

  11.         private DataTable GetEmpData() {

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

  16.             for (int i = 0; i < 10; i++)
  17.             {
  18.                 dt.Rows.Add(i, $"emp-{i}",$"client-{i}");
  19.             }
  20.             dt.Rows[8]["EmpClient"] = "very long very longvery long very long";
  21.             return dt;
  22.         }

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

  28.             XlsExport xlsExport = new XlsExport();
  29.             var stream = new MemoryStream();
  30.             xlsExport.AutoRowHeight = true;
  31.             xlsExport.UseCellMerging = false;
  32.             
  33.             xlsExport.Export(this.empReport.Document, stream);
  34.             stream.Position = 0;

  35.             var guid = Guid.NewGuid().ToString("N");
  36.             var reportBytes = stream.ToArray();
  37.             Response.Clear();
  38.             Response.ContentType = "application/force-download";
  39.             Response.AddHeader("content-disposition", $"attachment; filename=empreport-{guid}.xls");
  40.             Response.BinaryWrite(reportBytes);
  41.             Response.End();
  42.         }
  43.     }
复制代码


导出的excel 截图

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


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

最佳答案

查看完整内容

您好,在导出时设置属性UseCellMerging为true,参考下图,您测试看看效果。

6 个回复

倒序浏览
最佳答案
最佳答案
Bella.YuanWyn认证
超级版主   /  发表于:2022-5-7 20:18:40
来自 7#
天下同道 发表于 2022-5-9 21:08
你好,这样的话,报表显示出来的字不全。还有其他方案吗

您好,在导出时设置属性UseCellMerging为true,参考下图,您测试看看效果。

本帖子中包含更多资源

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

x
回复 使用道具 举报
wengMQ悬赏达人认证
银牌会员   /  发表于:2022-5-8 10:45:43
2#
你用的导出是过时的导出方法,可以加我QQ546962925沟通下
回复 使用道具 举报
天下同道
注册会员   /  发表于:2022-5-8 12:58:16
3#
wengMQ 发表于 2022-5-8 10:45
你用的导出是过时的导出方法,可以加我QQ546962925沟通下

两种导出都得到一样的结果,已加QQ
回复 使用道具 举报
天下同道
注册会员   /  发表于:2022-5-8 13:33:52
4#
本帖最后由 天下同道 于 2022-5-8 13:44 编辑

更新一下,我用的是区域报表(Section Report - Base on Code)不管是AR viewer自带的导出,还是手动导出的excel都会出现字段太长导致自动换行。这个在AR 11里面不会发生,AR 15里面有什么方法可以解决这个问题?
回复 使用道具 举报
James.Lv讲师达人认证 悬赏达人认证 活字格认证 Wyn认证
超级版主   /  发表于:2022-5-9 18:15:25
5#
天下同道 发表于 2022-5-8 13:33
更新一下,我用的是区域报表(Section Report - Base on Code)不管是AR viewer自带的导出,还是手动导出的ex ...

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

本帖子中包含更多资源

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

x
回复 使用道具 举报
天下同道
注册会员   /  发表于:2022-5-9 21:08:19
6#
James.Lv 发表于 2022-5-9 18:15
您好,这个您可以在不需要换行的文本框设置属性

你好,这样的话,报表显示出来的字不全。还有其他方案吗
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部