C# 使用MVC将XML电子表格转换为Excel,单元格格式始终通用,如何更改?
旧版系统使用Excel 2003,因此我无法使用任何较新的第三方产品,因为它们适用于2007年及更高版本,并且保留了旧版XML电子表格创建系统 我现在需要修改Excel中的单元格格式,使数字就是数字,日期就是日期,等等。。。因为所有内容当前都在Excel中格式化为常规格式 我已经扫描了web,并在部分视图中尝试了以下编码,以便只显示样式和工作簿部分:C# 使用MVC将XML电子表格转换为Excel,单元格格式始终通用,如何更改?,c#,xml,asp.net-mvc,C#,Xml,Asp.net Mvc,旧版系统使用Excel 2003,因此我无法使用任何较新的第三方产品,因为它们适用于2007年及更高版本,并且保留了旧版XML电子表格创建系统 我现在需要修改Excel中的单元格格式,使数字就是数字,日期就是日期,等等。。。因为所有内容当前都在Excel中格式化为常规格式 我已经扫描了web,并在部分视图中尝试了以下编码,以便只显示样式和工作簿部分: <ss:Style ss:ID="MyTime"> <NumberFormat ss:Format="Long Time" /&
<ss:Style ss:ID="MyTime">
<NumberFormat ss:Format="Long Time" />
</ss:Style>
<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="General Number" />
</ss:Style>
然而,当我下载xls并在Excel2003中重新打开它时,所有的单元格格式仍然是通用的
我错过了什么或者我做错了什么
这段代码在系统中无处不在,因此我正在寻找修复或解决方法,而不需要重写它或使用XML输出来创建XSD和映射,因为截止日期对我来说太紧了
因为我可以在底部正式回答我自己的问题,以下是答案:
如果其他人需要找到类似的东西,我会自己回答
请在此处查找要使用的自定义代码:
但我会考虑替换这个:
<ss:Style ss:ID="MyTime">
<NumberFormat ss:Format="Long Time" />
</ss:Style>
<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="General Number" />
</ss:Style>
如果想要一个数字,请使用以下选项
<ss:Style ss:ID="MyTime">
<NumberFormat ss:Format="HH:MM:SS" />
</ss:Style>
<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="0" />
</ss:Style>
如果希望12000在自定义而非常规中显示为12000.00,则为或更低
<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="#,##0.00" />
</ss:Style>
我花了一整天的时间在互联网上寻找上述内容,因此我会在我发现的任何XML电子表格查询中回答这个问题,因为查找起来很烦人,也很困难。没有Excel 2003,但Excel 2013可以将其另存为“XML电子表格2003(*.XML)” 其结果如下XML文件所示 此样式将显示为无小数,无千“,”
你的名字
你的名字
2015-06-25T18:25:51Z
15
9195
17280
0
0
假的
假的
我的时间
我的号码
1899-12-31T12:12:34.000
123213
600
600
3.
1.
C2
假的
假的
谢谢!你的回答()对我很有用。为了记录在案,我认为你实际上可以为你自己的问题发布一个答案。
<ss:Style ss:ID="MyTime">
<NumberFormat ss:Format="Long Time" />
</ss:Style>
<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="General Number" />
</ss:Style>
<ss:Style ss:ID="MyTime">
<NumberFormat ss:Format="HH:MM:SS" />
</ss:Style>
<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="0" />
</ss:Style>
<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="#,##0.00" />
</ss:Style>
<Style ss:ID="s64">
<NumberFormat ss:Format="0"/>
</Style
<Style ss:ID="s66">
<NumberFormat ss:Format="Standard"/>
</Style>
<NumberFormat ss:Format="m/d/yy\ h:mm;@"/>
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>YourName</Author>
<LastAuthor>YourName</LastAuthor>
<Created>2015-06-25T18:25:51Z</Created>
<Version>15.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>9195</WindowHeight>
<WindowWidth>17280</WindowWidth>
<WindowTopX>0</WindowTopX>
<WindowTopY>0</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s63">
<NumberFormat ss:Format="[h]:mm:ss;@"/>
</Style>
<Style ss:ID="s64">
<NumberFormat ss:Format="0"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="15">
<Column ss:StyleID="s63" ss:AutoFitWidth="0"/>
<Column ss:StyleID="s64" ss:Width="60"/>
<Row>
<Cell><Data ss:Type="String">My Time</Data></Cell>
<Cell><Data ss:Type="String">My Number</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="DateTime">1899-12-31T12:12:34.000</Data></Cell>
<Cell><Data ss:Type="Number">123213</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Header x:Margin="0.3"/>
<Footer x:Margin="0.3"/>
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
</PageSetup>
<Print>
<ValidPrinterInfo/>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveCol>1</ActiveCol>
<RangeSelection>C2</RangeSelection>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>