我有一些代码可以将数据从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