旧系统使用Excel 2003,因此我无法使用任何较新的第三方产品,因为它们适用于2007及更高版本,并且已经留下了传统的XML电子表格创建系统。
我现在需要修改Excel中的单元格格式,以便数字是数字,日期是日期等等......因为当前所有内容都在Excel格式化为常规。
我已经扫描了网页,并在局部视图中尝试了以下编码,以获得样式和工作簿部分:
<ss:Style ss:ID="MyTime">
<NumberFormat ss:Format="Long Time" />
</ss:Style>
<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="General Number" />
</ss:Style>
这在XML outfile中表示,即
<Cell ss:StyleID='MyNumber'><Data ss:Type='Number'>419,717,200</Data></Cell>
这是在主视图中创建的,并使用以下方式逐行构建:
private static IHtmlString ToXmlColumn(string columnContent, string ssType, string ssFormat)
{
return MvcHtmlString.Create(string.Format("<Cell ss:StyleID='{2}'><Data ss:Type='{1}'>{0}</Data></Cell>", SecurityElement.Escape(columnContent), ssType, ssFormat));
}
下载使用application / vnd.ms-excel
的基础public ExcelActionResult(string fileName, TModel model, ControllerContext context, string viewName = null)
: base("application/vnd.ms-excel")
{
_context = context;
_model = model;
_viewName = viewName ?? (string)_context.RouteData.Values["action"];
FileDownloadName = fileName;
}
但是,当我下载xls并在Excel 2003中重新打开它时,所有单元格格式仍为常规格式。
我错过了什么或我做错了什么?
此代码在系统中无处不在,因此我正在寻找修复或解决方法,而不是需要重写它或使用XML输出来创建XSD并映射,因为截止日期对我来说太紧张了。< / p>
因为我可以在底部正式回答我自己的问题,所以答案是:
如果其他人需要找到类似的东西,我会自己回答。
在这里查看要使用的自定义代码:
http://office.microsoft.com/en-gb/excel-help/number-format-codes-HP005198679.aspx
但我会考虑更换这个:
<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在自定义而不是一般
中显示为12,000.00<ss:Style ss:ID="MyNumber">
<NumberFormat ss:Format="#,##0.00" />
</ss:Style>
我花了一整天的时间在互联网上搜索以上内容,所以我会在任何XML Spreadsheet查询中回答这个问题,因为它很难找到并且很难找到。
答案 0 :(得分:1)
Don't have Excel 2003, but Excel 2013 can save it as "XML Spreadsheet 2003(*.xml)" It comes out as below XML file.
This style will display as no decimal, no thousand ",".
<Style ss:ID="s64">
<NumberFormat ss:Format="0"/>
</Style
Style ID should link to Column tag like <Column ss:StyleID="s64" ss:Width="61.5"/>
This style will display as 2 decimal places with "," as 1000 separator.
<Style ss:ID="s66">
<NumberFormat ss:Format="Standard"/>
</Style>
And this one should be long date time format:
<NumberFormat ss:Format="m/d/yy\ h:mm;@"/>
Hope this is the right direction for you. Good luck!
<?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>