我正在尝试使用xml模板导出到Excel。每次我运行它,它在代码行“</ss:Row>
”给我一个解析器错误,foreach循环中的那个,如果我正在评论foreach循环它工作正常。有人知道是否应该添加一些设置吗?
@model PBD_DealerConsole.Models.ExportData
@{
Layout = null;
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Model.FileName);
//Content-Disposition is defined in RFC-2183
var rows = Model.DetailsGrid.Count + 1;
}
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<ss: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">
<ss:Worksheet ss:Name="Datagrid">
<ss:Table ss:ExpandedColumnCount="17" ss:ExpandedRowCount="@rows" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="20">
<ss:Row ss:AutoFitHeight="0">
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Part #</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Description</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Cost</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Core</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Source</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">12 Mo Sales</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Mo No Sale</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">QOH</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">QOO</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Qty Avail</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Qty Req</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Avg Mo Supply</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Stocking Status</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Bin</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Last Sale Date</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Last Received Date</Data>
</ss:Cell>
<ss:Cell ecProperty="">
<ss:Data ss:Type="String">Pkg of</Data>
</ss:Cell>
</ss:Row>
@foreach (var row in Model.DetailsGrid)
{
<ss:Row>
<ss:Cell>
<ss:Data ss:type="String">@row.PartNumber</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.Description</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.Cost</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.Core</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerSource</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerTwelveMonthSales</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerMonthsNoSale</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerQOH</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerQOO</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.SellerQtyAvail</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.QtyReq</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerAvgMonthSupply</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerStockingStatus</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerBin</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerLastSale</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.BuyerLastReceived</Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:type="String">@row.PackageQty</Data>
</ss:Cell>
</ss:Row>
}
</ss:Table>
</ss:Worksheet>
</ss:Workbook>
答案 0 :(得分:0)
我发现解决方案在foreach循环的单元格部分看起来只是一个错字:
<ss:Data ss:type="String">@row.QtyReq</Data>
ss:type应以大写字母开头:
<ss:Data ss:Type="String">@row.QtyReq</Data>
现在工作正常。