2010-12-14 50 views
0

我有一些代码可以将数据从SQL数据库导出到Excel电子表格。asp.net导出到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(不带[])?

+0

你试过ASCII 13 + ASCII 10吗? – Fionnuala 2010-12-14 14:45:18

+0

@Remou谢谢你的建议,但我不知道该怎么做,你能举个例子吗? – Ali 2010-12-14 15:32:50

+0

显然,某些输入可能只是'lf',而一些'crlf'(http://stackoverflow.com/questions/4019928/carriage-return-ascii-chr-13-is-missing-from-textbox-postback-值 - 何时使用)。 Excel会期望cr(ascii 13)和lf(ascii 10)。也许你可以单独替换/ r&n以最终得到一个,然后用Environment.NewLine替换它?恐怕我只是从Excel的角度来讲话,因此是笔记而不是回答。 – Fionnuala 2010-12-14 15:57:42

回答

0

实测值上egghead cafe

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

Excel中只需要换行不回车。此外,我觉得我已经患上 “[// R]” 和 “\ r”

0

cell.Text = “你的firstlineyour二线” 之间的一些混乱;

如果你正在从DB则文本:

cell.Text = textfromDB.Replace( “\ n”, “”);