导出到Excel(默认文件类型 - Excel) [英] Export to Excel (Default File Type - Excel)
问题描述
以下代码用于将HTML导出为excel。
HttpContext.Current.Response.ContentType =" application / vnd.ms-excel"
HttpContext.Current.Response.AddHeader(" content-disposition",
" attachment; filename = ABC.xls")
HttpContext.Current .Response.Write(strHTML)
HttpContext.Current.Response.End()
页面(* .htm; * .html)
我们如何将默认文件类型更改为Excel
The following piece of code is being used to export HTML to excel.
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=ABC.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
However when the user tries to save it the Default File Type is Web
Page(*.htm; *.html)
How do we change the Default File Type to Excel
推荐答案
尝试在代码块的开头放置一条Response.Clear()行。
-
我希望这有助于,
Steve C. Orr,MCSD,MVP
http:// SteveOrr .net
" Hemant Sipahimalani" < Hemant Si**********@discussions.microsoft.com >在消息新闻中写道:
:C0 ********************************** @ microsof t.com ...
Try putting a Response.Clear() line at the beggining of your code block.
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Hemant Sipahimalani" <Hemant Si**********@discussions.microsoft.com> wrote
in message news:C0**********************************@microsof t.com...
以下代码用于将HTML导出为excel。
HttpContext.Current.Response.ContentType =" application / vnd。 ms-excel"
HttpContext.Current.Response.AddHeader(" content-disposition",
" attachment; filename = ABC.xls")
HttpContext.Current.Response.Write( strHTML)
HttpContext.Current.Response.End()
然而,当用户试图保存它时,默认文件类型是Web
页面(* .htm; * .html )
我们如何将默认文件类型更改为Excel
The following piece of code is being used to export HTML to excel.
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=ABC.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
However when the user tries to save it the Default File Type is Web
Page(*.htm; *.html)
How do we change the Default File Type to Excel
史蒂夫,
感谢您的快速回复。 Response.Clear虽然没有帮助。
列出完整的代码以便更清晰。
Dim strFileName As String
Dim strHTML As String
Dim strAddInfo As String
HttpContext.Current.Response.Clear()
HttpContext.Current。 Response.ContentType =" application / vnd.ms-excel"
strReportName =" EXPORT REPORT"
strFileName =" ABC.xls"
strAddInfo =" Additional Info"
strHTML = GetGHTML()''这是负责以HTML格式获取报告
HttpContext.Current.Response.AddHeader( " content-disposition",
" attachment; filename ="& strFileName)
HttpContext.Current.Response.Charset =""
HttpContext.Current.Response.Write("< h4>"& strReportName&"< / h4>")
HttpContext.Current.Response。写(strAddInfo)
HttpContext.Current.Response.Write("< br>< br>")
HttpContext.Current.Response.Write(strHTML)
HttpContext .Current.Response.End()
Hemant
" Steve C. Orr [MVP,MCSD]"写道:
Steve,
Thank you for the prompt reply. Response.Clear does not help though.
Listing out the full piece of code for better clarity.
Dim strFileName As String
Dim strHTML As String
Dim strAddInfo As String
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
strReportName = "EXPORT REPORT"
strFileName = "ABC.xls"
strAddInfo = "Additional Info"
strHTML = GetGHTML() ''This is responsible for getting report in HTML format
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=" & strFileName)
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.Write("<h4>" & strReportName & "</h4>")
HttpContext.Current.Response.Write(strAddInfo)
HttpContext.Current.Response.Write("<br><br>")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
Hemant
"Steve C. Orr [MVP, MCSD]" wrote:
尝试在代码块的开头放置一条Response.Clear()行。
-
我希望这有帮助,
Steve C. Orr,MCSD,MVP
http://SteveOrr.net
" Hemant Sipahimalani" < Hemant Si**********@discussions.microsoft.com >在消息新闻中写道
:C0 ********************************** @ microsof t.com。 ..
Try putting a Response.Clear() line at the beggining of your code block.
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Hemant Sipahimalani" <Hemant Si**********@discussions.microsoft.com> wrote
in message news:C0**********************************@microsof t.com...
以下代码用于将HTML导出到Excel。
HttpContext.Current.Response.ContentType =" application / vnd.ms-excel"
HttpContext.Current.Response.AddHeader(" content-disposition",
" attachment; filename = ABC.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
然而,当用户试图保存它时,默认文件类型是Web
Page(* .htm; * .html)>我们如何将默认文件类型更改为Excel
The following piece of code is being used to export HTML to excel.
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=ABC.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
However when the user tries to save it the Default File Type is Web
Page(*.htm; *.html)
How do we change the Default File Type to Excel
我们使用了以下代码:
objHttpContext.Response.Clear()
objHttpContext.Response.Buffer = True
objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
objHttpContext.Response.ContentType =" application / vnd.ms-excel
objHttpContext.Response.AddHeader(" Content-disposition",
" attachment; filename = export.xls")
objHttpContext.Response.Charset =""
" Hemant Sipahimalani" < Hemant Si**********@discussions.microsoft.com >在消息新闻中写道:
:C0 ********************************** @ microsof t.com ...
We have used this code:
objHttpContext.Response.Clear()
objHttpContext.Response.Buffer = True
objHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8
objHttpContext.Response.ContentType = "application/vnd.ms-excel"
objHttpContext.Response.AddHeader("Content-disposition",
"attachment;filename=export.xls")
objHttpContext.Response.Charset = ""
"Hemant Sipahimalani" <Hemant Si**********@discussions.microsoft.com> wrote
in message news:C0**********************************@microsof t.com...
以下代码用于将HTML导出为excel。
HttpContext.Current.Response.ContentType =" application / vnd。 ms-excel"
HttpContext.Current.Response.AddHeader(" content-disposition",
" attachment; filename = ABC.xls")
HttpContext.Current.Response.Write( strHTML)
HttpContext.Current.Response.End()
然而,当用户试图保存它时,默认文件类型是Web
页面(* .htm; * .html )
我们如何将默认文件类型更改为Excel
The following piece of code is being used to export HTML to excel.
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=ABC.xls")
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.End()
However when the user tries to save it the Default File Type is Web
Page(*.htm; *.html)
How do we change the Default File Type to Excel
这篇关于导出到Excel(默认文件类型 - Excel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!