我想将数字数据从 C# 导出到 Excel,其中浮点数使用逗号 (',') 代替小数点 ('.')。我通过在 C# 中编写 XML 代码来导出 Excel 文件。
数据已从代码端正确导出,但如果数据类型为“数字”,则 Excel 文件会省略 (',')。当我为英语生成相同的数据时,它会完美生成。
示例:数字 = 65,4 然后在 Excel 文件中显示 654。
示例代码:--xml 代码
<?xml version="1.0" encoding="UTF-8" ?>
<?mso-application progid="Excel.Sheet"?>
<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:html="http://www.w3.org/tr/rec-html40">
<ss:Worksheet ss:Name="test">
<ss:Table>
<ss:Row>
<ss:Cell ss:StyleID="s65"><ss:Data ss:Type="String">123</ss:Data></ss:Cell>
<ss:Cell ss:StyleID="s65"><ss:Data ss:Type="Number">64,3</ss:Data></ss:Cell>
<ss:Cell ss:StyleID="s65"><ss:Data ss:Type="Number">72,0</ss:Data></ss:Cell>
<ss:Cell ss:StyleID="s65"><ss:Data ss:Type="Number">26,0</ss:Data></ss:Cell>
<ss:Cell ss:StyleID="s65"><ss:Data ss:Type="Number">72,0</ss:Data></ss:Cell></ss:Row>
</ss:Table>
</ss:Worksheet></ss:Workbook>
c#代码——
Dim excelXml As String = GetExcelXml(dsInput, filename)
Response.Clear()
Response.AppendHeader("Cache-Control", "cache, must-revalidate")
Response.AppendHeader("Pragma", "public")
Response.AppendHeader("Content-Type", "application/vnd.ms-excel")
' Response.ContentEncoding = System.Text.Encoding.GetEncoding(1252)
Response.Charset = "iso-8859-1"
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.AppendHeader("Content-disposition", "attachment; filename=" &
System.IO.Path.GetFileName(filename))
Response.Write(excelXml)
Response.Flush()
Response.[End]()