我有一些代碼可以將數據從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(不帶[])?
你試過ASCII 13 + ASCII 10嗎? – Fionnuala 2010-12-14 14:45:18
@Remou謝謝你的建議,但我不知道該怎麼做,你能舉個例子嗎? – Ali 2010-12-14 15:32:50
顯然,某些輸入可能只是'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