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命名空间:usingSystem.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()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)