最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ASP.NET实现word文档在线预览功能代码
时间:2010-07-12 编辑:简简单单 来源:一聚教程网
using system;
using system.collections;
using system.configuration;
using system.data;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.htmlcontrols;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using word = microsoft.office.interop.word;
public partial class test : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
wordtohtml("d:\yijian.doc");
}
///
/// word转成html
///
///
private string wordtohtml(object wordfilename)
{
//在此处放置用户代码以初始化页面
word.applicationclass word = new word.applicationclass();
type wordtype = word.gettype();
word.documents docs = word.documents;
//打开文件
type docstype = docs.gettype();
word.document doc = (word.document)docstype.invokemember("open", system.reflection.bindingflags.invokemethod, null, docs, new object[] { wordfilename, true, true });
//转换格式,另存为
type doctype = doc.gettype();
string wordsavefilename = wordfilename.tostring();
string strsavefilename = wordsavefilename.substring(0, wordsavefilename.length - 3) + "html";
object savefilename = (object)strsavefilename;
doctype.invokemember("saveas", system.reflection.bindingflags.invokemethod, null, doc, new object[] { savefilename, word.wdsaveformat.wdformatfilteredhtml });
doctype.invokemember("close", system.reflection.bindingflags.invokemethod, null, doc, null);
//退出 word
wordtype.invokemember("quit", system.reflection.bindingflags.invokemethod, null, word, null);
return savefilename.tostring();
}
}
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10