我正在尝试使用 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>