我正在使用VB XML文字返回和Excel XML文件。
问题是包含<?xml version="1.0"?>
的第一行没有下载。
以下是代码:
Public Class ReservasController
Function Test()
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=test.xml")
Response.ContentType = "application/vnd.ms-excel"
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8")
Response.Write(GetXML())
''//This works:
''//Response.Write("<?xml version=""1.0""?>" + GetXML().ToString())
Response.End()
Return Nothing
End Function
GetXML方法非常简单:
Private Function GetXML()
Return <?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>Bizcacha Excel Generator</Author>
<LastAuthor>Bizcacha Excel Generator</LastAuthor>
<Created>20100101</Created>
<Company>Bizcacha</Company>
<Version>1</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="title">
<Table x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15">
<Column ss:Width="100"/>
<Column ss:Width="100"/>
<Row ss:AutoFitHeight="0">
<Cell ss:StyleID="Default"><Data ss:Type="String">Hello</Data></Cell>
<Cell ss:StyleID="Default"><Data ss:Type="String">World</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
End Function
End Class
答案 0 :(得分:1)
看一下,它是否与返回使用引号的字符串有关...为什么不用Chr(34)替换那些引号,这是"
的ASCII代码...举个例子:
Const Char DblQuote As String = Chr(34) Private Function GetXML() Return "<?xml version=" & DblQuote & "1.0" & DblQuote & "?>" & vbCrLf _ & "<?mso-application progid=" & DblQuote & "Excel.Sheet" & DblQuote & "?>" & vbCrLf _ and so on...
您怎么看?
希望这有帮助, 最好的祝福, 汤姆。
答案 1 :(得分:-1)
执行XML文字很痛苦,所以我又回到了字符串连接。