导出到Excel中使用文本超过300个字符不工作 [英] Export To Excel with Text more than 300 Characters not working

查看:423
本文介绍了导出到Excel中使用文本超过300个字符不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我称之为场我DataTable中备注里面有几条记录超过255 characters.When我们出口使用低于code中的数据表到Excel,数据被推到Excel,但注释字段中记录有超过255个字符重叠其他单元格Excel和下一列记录推到下一行。

I have field called "Comments" in my DataTable which has few records more than 255 characters.When we export the DataTable to Excel using the below code, the data is pushed into Excel but the Comments field record which has more than 255 characters overlaps other cells in Excel and the next column record is pushed to next row.

code:

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=XXXXXX.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
foreach (DataRow dr in dt.Rows){
tab = "";
for (int i = 0; i < dt.Columns.Count; i++){
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();

你们能帮帮

推荐答案

使用 EPPlus 练成库并创造真正的Excel文件,它是自由和开放源码和作品真的很好。

Use EPPlus excel library and create real excel files, it's free and open source and works really well.

我测试了这一局面,填补文本单元长度超过4096字节,它的工作原理确定,但与2010年Excel和XSLX格式。

I tested this scenario and fill cell with text longer than 4096 bytes, and it works OK, but with excel 2010 and xslx format.

下面是例子code:

  ExcelPackage ePack = new ExcelPackage(new FileInfo("c:\\temp\\temp.xlsx"));
  ExcelWorksheet ws = ePack.Workbook.Worksheets.Add("Sheet1");
  string longText = "Lorem ipsum ..... <snipped>";
  ws.Cells[1, 1].Value = longText;
  ePack.Save();

BTW。你可以在这里找到例如如何导出数据表到excel文件:

btw. you can find here example how to export DataTable to excel file :

http://stackoverflow.com/a/9569827/351383

这篇关于导出到Excel中使用文本超过300个字符不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆