簡體   English   中英

如何防止HTML代碼出現在導出的Excel工作簿的末尾

[英]How to prevent html code from appearing at end of exported excel workbook

我正在嘗試使用vb.net將數據從SQL Server數據庫導出到網頁上的excel工作簿。

我正在使用streamwriter方法,這是我的代碼的格式:

Dim x As StreamWriter
Dim fileName As String = "test.xls"
Dim output As String = "C:/...."
tWriter = New StreamWriter(output)
For Each row As DataRow In datatable.Rows
tWriter.Write(....)
...
Next

tWriter.Flush()
tWriter.Dispose()
tWriter.Close()

Response.Clear()
Response.ContentType = "application/vnd.xls"
Response.AppendHeader("Content-Disposition", "attachment; filename=" & fileName)
Response.WriteFile(output)
Response.Flush()
Response.End()

我遇到的問題是該網頁的html代碼出現在xls文件的末尾。 我不清楚這是為什么還是如何擺脫它。

該網頁在按下按鈕時生成excel文件,並將其作為附件發送到瀏覽器。

有人有什么想法嗎? 我嘗試了多種內容類型,它們都產生相同的結果。

謝謝

我有一個類似的問題,以下更改已為我解決:

1st我將Response.AppendHeader更改為Response.AddHeader ,並將Response.WriteFile(output)更改為Response.Write(output)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM