asp中如何将数据库的内容导出到word?

asp中如何将数据库的内容导出到word?,第1张

写一个js,我回去找一下

function AllAreaWord()

{

var oWD = new ActiveXObject("Word.Application")

var oDC = oWD.Documents.Add("",0,1)

var oRange =oDC.Range(0,1)

var sel = document.body.createTextRange()

sel.moveToElementText(PrintA)

sel.select()

sel.execCommand("Copy")

oRange.Paste()

oWD.Application.Visible = true

//window.close()

}

ASP.NET(C#)将数据导出到Word或Excel命名空间:using

System.IO

using

System.Text将DataGrid的数据导出到Excel

string

excelname="excel文件名"

HttpContext.Current.Response.Charset

=

"GB2312"

HttpContext.Current.Response.ContentEncoding

=

Encoding.UTF8

HttpContext.Current.Response.ContentType

=

"application/ms-excel"

HttpContext.Current.Response.AppendHeader("Content-disposition",

"attachmentfilename="

+

excelname

+

".xls")

dr1.Page.EnableViewState

=

false

StringWriter

sw

=

new

StringWriter()

HtmlTextWriter

tw

=

new

HtmlTextWriter(sw)

dr1.RenderControl(tw)

HttpContext.Current.Response.Write(sw.ToString())

HttpContext.Current.Response.End()

将DataGrid的数据导出到Word

string

excelname="word文件名"

HttpContext.Current.Response.Charset

=

"GB2312"

HttpContext.Current.Response.ContentEncoding

=

Encoding.UTF8

HttpContext.Current.Response.ContentType

=

"application/ms-winword"

HttpContext.Current.Response.AppendHeader("Content-disposition",

"attachmentfilename="

+

excelname

+

".doc")

dr1.Page.EnableViewState

=

false

StringWriter

sw

=

new

StringWriter()

HtmlTextWriter

tw

=

new

HtmlTextWriter(sw)

dr1.RenderControl(tw)

HttpContext.Current.Response.Write(sw.ToString())

HttpContext.Current.Response.End()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9930779.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存