找回密码
 立即注册

QQ登录

只需一步,快速开始

mushroom_aaa

银牌会员

6

主题

9

帖子

2348

积分

银牌会员

积分
2348

活字格认证

mushroom_aaa
银牌会员   /  发表于:2012-7-10 11:55  /   查看:6243  /  回复:4
在将report导出至excel中时,数字类型总是以文本类型显示,即在单元格靠左。请问应该在导出的时候做哪些设置才可以避免这样啊?还是在报表样式上作调整?谢谢!
导出部分代码如下:
  1. ActiveReport rpt = new ActiveReport();

  2.             try
  3.             {
  4.                 rpt.Run(false);
  5.             }
  6.             catch (DataDynamics.ActiveReports.ReportException eRunReport)
  7.             {
  8.                 // Failure running report, just report the error to the user:
  9.                 Response.Clear();
  10.                 Response.Write("<h1>Error running report:</h1>");
  11.                 Response.Write(eRunReport.ToString());
  12.                 return;
  13.             }

  14.             Response.ContentType = "application/vnd.ms-excel";
  15.             Response.AddHeader("content-disposition", "inline; filename=MyXLS.xls");

  16.             // Create the EXCEL export object
  17.             XlsExport xls = new XlsExport();
  18.             // Create a new memory stream that will hold the xls output
  19.             System.IO.MemoryStream memStream = new System.IO.MemoryStream();
  20.             // Export the report to EXCEL:
  21.             xls.Export(rpt.Document, memStream);
  22.             xls.UseCellMerging = true;
  23.             // Write the EXCEL stream out
  24.             Response.BinaryWrite(memStream.ToArray());
  25.             // Send all buffered content to the client
  26.             Response.End();
复制代码

4 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2012-7-10 16:27:00
沙发
回复 1楼mushroom_aaa的帖子

你好,
可以通过 ActiveReport TextBox 下属性 Alignment 来实现:

  1. private void ActiveReport_ReportStart(object sender, EventArgs e)
  2.         {
  3.             this.textBox1.Alignment = TextAlignment.Center;
  4.         }
复制代码
回复 使用道具 举报
mushroom_aaa
银牌会员   /  发表于:2012-7-11 09:40:00
板凳
回复 2楼iceman的帖子

你好,感谢你的回复。
这样设置后数字的确在Excel文件单元格靠右显示,但是仍然不是数字类型,而是Text,无法对这些数字进行求和、求平均值等操作,请问这个该怎么解决?希望报表导出即可正确显示,而不是在Excel文件中再进行调整。谢谢!
回复 使用道具 举报
mushroom_aaa
银牌会员   /  发表于:2012-7-11 14:31:00
地板
在OutputFormat设置一下就可以了,ActiveReports真的是很值得研究的阿!
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-7-11 14:39:00
5#
回复 4楼mushroom_aaa的帖子

:strong:感谢楼主的分享
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部