asp.net 导出到 Excel 在回车符之前将 [?] 保留在行结尾处

发布于 2024-10-07 16:37:17 字数 553 浏览 0 评论 0原文

我有一些代码将数据从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毅然前行 2024-10-14 16:37:17

发现于 蛋头咖啡馆

CellValue.Replace(Environment.NewLine, "\n")

Excel只需要换行而不需要回车。另外我认为我在“[//r]”和“\r”之间遇到了一些困惑

Found on egghead cafe

CellValue.Replace(Environment.NewLine, "\n")

Excel only requires the line feed not the carriage return. Also I think I've been suffering some confusion between "[//r]" and "\r"

舟遥客 2024-10-14 16:37:17

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", "");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文