public void Download()
{
Random rd = new Random();
string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + rd.Next() + ".doc";
//存储路径
string path = Server.MapPath(fileName);
//创建字符输出流
StreamWriter sw = new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8);
//需要导出的内容
string str = "<html><head><title>无标题文档</title></head><body>这里放从数据库导出的word文档内容</body></html>";
//写入
sw.Write(str);
sw.Close();
Response.Clear();
Response.Buffer = true;
this.EnableViewState = false;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "application/octet-stream";
Response.WriteFile(path);
Response.Flush();
Response.Close();
Response.End();
}
标准word文档的格式微软暂未公布,由此我们可将需要导出的内容转为标准HTML文件储存,后缀名为.doc
也可以将要导出内容转为标准XML格式存储,改后缀为.doc
具体格式随意新建个word文档,输入内容,另存为.XML可见
另外一种导出方式为word导出标准格式,服务器需要安装Microsoft Office word,需要预先设置好一个word文档并在要插入内容的地方设置书签做为模版,导出word文档时需要先遍历模版文件中的所有书签,然后给书签赋值就能实现导出数据了
还有不懂的可以直接百度HI我
是否可以解决您的问题?
asp.net页面导出word后样式问题
要达到这种效果,把生成的简历的内容都放在一个table里,然后用JS导出。
给你个例子参考。表格中可以包括图片等元素,都可以正常导出。
<table width="100%" border="1" id = "PrintA">
<tr>
<td>dfsdfds</td>
<td>&dsfds</td>
<td>&sdf;</td>
<td><img src="1.jpg"/></td>
</tr>
<tr>
<td>dsf</td>
<td>dsfds</td>
<td>fsdfdsfdsf</td>
<td>dsfs</td>
</tr>
<tr>
<td>dsfds</td>
<td>dsf</td>
<td>dsfd</td>
<td>sfds</td>
</tr>
<tr>
<td></td>
<td>sdf</td>
<td>fdsf</td>
<td></td>
</tr>
</table>
<input type="button" onclick="javascript:AllAreaWord();" value="导出页面指定区域内容到Word">
<script type="text/javascript" language="javascript">
//指定页面区域内容导入Word
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();
oWD.ActiveWindow.ActivePane.View.Type=3
oWD.Application.close;
}
</SCRIPT>
</body></html>
asp.net导出word自定义格式
循环(for循环或者foreach)读取数据再插入word,首先在顶端写入会议名称和会议时间,count为15的整倍数时,接着在后面生成分隔符(分页符)
Asp.net操作word 比如读写导出Word文档 请问都有什么方法实现?或插件
PageOffice相对最容易实现你的读写要求,因为它有一套比较简洁的纯C#读写word的对象,不是对word的com接口的简单封装,运行稳定、调用代码简单
asp.net 导出word 文件名怎么确定
Response.Clear();
Response.Buffer = true;
Response.Charset = "gb2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.AppendHeader("content-disposition","attachment;filename=\"" + System.Web.HttpUtility.UrlEncode("中文名称",System.Text.Encoding.UTF8) + ".xls\"");
Response.ContentType = "Application/ms-excel";
asp.net(C#) 导出到word excel [100分]
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", "attachment;filename=" + 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", "attachment;filename=" + 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();
asp.net从数据库中导出数据并生成word问题。
appWord.Selection.TypeParagraph();//换行
appWord.Selection.Font.Bold = 0;//正常体
appWord.Selection.Font.Color = word.WdColor.wdColorBlack;//黑色字体
appWord.Selection.ParagraphFormat.Alignment = word.WdParagraphAlignment.wdAlignParagraphJustify;//两端对齐
这是控制整个文件的吧,我想要某一行格式不同。
asp.net导出Word ,我的导出确实页面,高手帮我看看啊
是不是迅雷自动跳出来帮助下载了?
如果是 需要关闭迅雷的浏览器监视功能
转载请注明出处51数据库 » asp.net导出word模板 asp.net导出word
倒着看世界_