winform下word文件转.mht
来源:互联网 发布:联通大数据有限公司 编辑:程序博客网 时间:2024/06/07 06:43
做项目时有用webBrowser控件显示word文件的需要,但是比较惭愧,没有找到很舒心的方法,于是转而把word文件转换成单文件网页文件.mht来显示。p.s.:webBrowser控件宽度设置成750px比较能还原word文档的显示效果。
using System;using System.Reflection;using System.Text;using System.IO;using System.Collections;using Microsoft.Office.Interop.Word;public class Word2mht{ /// <summary> /// 提取文件绝对路径的文件名部分,并把文件名后缀换成.mht /// </summary> /// <param name="Directory"></param> /// <returns></returns> static public string GetMhtName(string Directory) { int pathLength = Directory.LastIndexOf(Path.DirectorySeparatorChar); string tmp = Directory.Substring(pathLength + 1); int dot = tmp.LastIndexOf('.'); return DateTime.Today+tmp.Substring(0, dot)+".mht"; } /// <summary> /// word转成mht /// </summary> /// <param name="wordFileName"></param> static public string WordToMht(string wordDirectory, string saveFileName) { Application word = new Application(); Type wordType = word.GetType(); Documents wordDocs = word.Documents; //打开Word文件 Type docsType = wordDocs.GetType(); Document doc = (Document)docsType.InvokeMember( "Open", BindingFlags.InvokeMethod, null, wordDocs, new Object[] { (object)(wordDirectory), true, true } ); //转换格式,另存为 Type docType = doc.GetType(); docType.InvokeMember( "SaveAs", BindingFlags.InvokeMethod, null, doc, new object[] { (object)saveFileName, WdSaveFormat.wdFormatWebArchive } ); docType.InvokeMember("Close", BindingFlags.InvokeMethod, null, doc, null); //退出Word wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null); return saveFileName; } }也看得出来吧,用了office的接口,没装office是没法用的。
0 0
- winform下word文件转.mht
- C#实现 mht和word转html文件
- linux下阅读MHT文件
- Linux下阅读MHT文件
- winform下word文件与byte[]互转
- jsp导出word 及mht 转码问题
- java在Windows平台下面把word转mht
- java在Windows平台下面把word转mht
- IE中打开服务器下的MHT文件
- Firefox :命令行下静默打印html/mht文件为pdf
- mht文件简介
- firefox看mht文件
- PHP 处理 mht 文件
- php通过mht文件方式生成带图片的word文档
- HTML文件转为MHT文件
- winform下Dataset转Excel文件
- C# winform 转换word文件文字
- C# winform 获取word文件内容
- oracle 创建用户 导入dmp文件
- 改变学习的三个模式--3月主题总结
- AMD宣布支持DirectX 12 为游戏开发者带来更多福利
- sortedArrayUsingSelector:@selector
- 虚拟机中的mac怎么安装vmare tools
- winform下word文件转.mht
- android gallery 画廊控件示例
- [LeetCode]Same Tree
- 然后相濡以沫
- 运营棋牌游戏平台需注意什么
- 论数字化视频监控的应用
- OpenLayers源码学习(一) 取图算法
- Description Resource Path Location Type Java compiler level does not match the version of the instal
- 误删文件后如何恢复