asp.net 导出到 Excel 在回车符之前将 [?] 保留在行结尾处
我有一些代码将数据从 SQL 数据库导出到 Excel 电子表格。
数据是通过网站输入的,其中一些包含多行信息。
我需要保留多行,但 excel 2007 继续在每行末尾添加 [?]。
这是我到目前为止所得到的,
CellValue.ToString() // this returns [?][?] at the end of each line for excel 2007
// and a single [?] in excel 2010
CellValue.Replace("[//r]","") // this works correctly for 2010 but still leaves a [?] for 2007
Cellvalue.Replace(Environment.NewLine, "") // this removes all the line breaks.
我可以用什么替换Environment.NewLine,以便在Excel 2007和2010中仍然有换行符(没有[?])?
I have an some code to export data form an SQL database to an Excel spread sheet.
the data is entered via a web site and some of it contains multiple lines of information.
I need to preserve the multiple lines but excel 2007 continues to put an [?] at the end of each line.
Here's what I got so far
CellValue.ToString() // this returns [?][?] at the end of each line for excel 2007
// and a single [?] in excel 2010
CellValue.Replace("[//r]","") // this works correctly for 2010 but still leaves a [?] for 2007
Cellvalue.Replace(Environment.NewLine, "") // this removes all the line breaks.
what can I replace the Environment.NewLine with in order to still have line breaks in both excel 2007 and 2010 (with no [?]) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发现于 蛋头咖啡馆
Excel只需要换行而不需要回车。另外我认为我在“[//r]”和“\r”之间遇到了一些困惑
Found on egghead cafe
Excel only requires the line feed not the carriage return. Also I think I've been suffering some confusion between "[//r]" and "\r"
cell.Text = "你的第一行你的第二行";
如果您从数据库获取文本,则:
cell.Text = textfromDB.Replace("\n", "");
cell.Text = "your firstlineyour secondline";
if you are getting the text from DB then:
cell.Text = textfromDB.Replace("\n", "");