您的位置:首页 > Web前端 > HTML

window server2008 word转html iis7配置无法转换问题

2013-03-19 09:34 441 查看
问题描述:刚开始在调试模式下可以转换成功,部署到问win2003 iis6下无法转换,后来设置权限可以转换,但部署到win2008 iis7下 无法转换,发现win2008下没有office组件,但是确实安装了(详见1解决);后来是无法访问上传doc文档,设置站点的asp net用户访问权限,后来读取 Document doc = (Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, (object)docs,
new Object[] { fileName, true, true });doc返回null值(详见2,3)

1.不到 office组件的问题

在运行中 输入 regedit 打开注册表

进行收索“000209FF-0000-0000-C000-000000000046”,你会找到下面这个东东:



将“AppID”修改为“CLSID” 然后保存,如果没有就新建CLSID 值:{00020906-0000-0000-C000-000000000046} 重启服务器

之后查看组件服务应该就会出现了



参考:/article/8892504.html

2.组件服务配置

(1)、 Cmd中输入命令 comexp.msc -32 启动组件服务(启动组件服务 方法 运行 mmc、mmc -32(32) 、DCOMCNFG.exe(64)) 不行一个一个

(2)、 依次双击"组件服务"->"计算机"->"我的电脑"->"DCOM配置";

(3)、 在"DCOM配置"中找到"Microsoft Excel Application",在它上面点击右键,然后点击"属性",弹出"Microsoft Excel应用程序属性"对话框;

(4)、 点击"标识"标签,选择 启动用户(默认选项) ,网上都写修改为交互式(但不知道为什么每次需要用户登录一下才能有效),后来直接指定用户;

(5)、 点击"安全"标签,在以下 三个项目中都选中 “自定义” 添加 ”everyone” 并分配最大权限(全选)

(6) 、设置Web.config文件 在Web.config文件的<system.web>中加入<identity impersonate="true"/> (没有这一步 会报Excel进程无法打开相应的excel文件)。

参考:/article/4888745.html

3.新建个Desktop目录

・Windows 2008 Server x64

Please make this folder.

C:\Windows\SysWOW64\config\systemprofile\Desktop

・Windows 2008 Server x86

Please make this folder.

C:\Windows\System32\config\systemprofile\Desktop

并将访问权限设置为net service

4.检查IIS7的设置

最后确定还需要设置应用程序池的标识,把此网站的AppPool的标识要设置为LocalSystem或者NetworkService

详细出处参考:

参考:/article/5295286.html

http://bbs.csdn.net/topics/360262598

附转换代码

string wordPath = Server.MapPath("/word/1.doc");

string htmlPath = Server.MapPath("/html/1.html");

//上传word文件, 由于只是做示例,在这里不多做文件类型、大小、格式以及是否存在的判断

FileUpload1.SaveAs(wordPath);

#region 文件格式转换

//请引用Microsoft.Office.Interop.Word

ApplicationClass word = new ApplicationClass();

Type wordType = word.GetType();

Documents docs = word.Documents;

// 打开文件

Type docsType = docs.GetType();

object fileName = wordPath;

Document doc = (Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, (object)docs, new Object[] { fileName, true, true });

//判断与文件转换相关的文件是否存在,存在则删除。(这里,最好还判断一下存放文件的目录是否存在,不存在则创建)

if (File.Exists(htmlPath)) { File.Delete(htmlPath); }

//每一个html文件,有一个对应的存放html相关元素的文件夹(html文件名.files)

if (Directory.Exists(htmlPath.Replace(".html", ".files")))

{

Directory.Delete(htmlPath.Replace(".html", ".files"), true);

};

//转换格式,调用word的“另存为”方法

Type docType = doc.GetType();

object saveFileName = htmlPath;

docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, WdSaveFormat.wdFormatHTML });

// 退出 Word

wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐