C#Word转Html的类
来源:互联网 发布:犀牛软件破解版下载 编辑:程序博客网 时间:2024/05/18 03:02
C#Word转Html的类
/**//********************************************************************
created: 2007/11/02
created: 2:11:2007 23:13
filename: D:C#程序练习WordToChmWordToHtml.cs
file path: D:C#程序练习WordToChm
file base: WordToHtml
file ext: cs
author: 凌剑 Bujiwu
purpose: 将Word文件转化为Html文件
*********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace CreateWordToHtmlFileSpace
...{
class WordToHtml
...{
public static void CreateWordToHtmlFile(string WordFileDir)
...{
DealWithWordFile(WordFileDir);
}
//搜索WordFileDir在的*.doc文件
private static void DealWithWordFile(string WordFileDir)
...{
//创建数组保存源文件夹下的文件名
string[] strFiles = Directory.GetFiles(WordFileDir, "*.doc");
for (int i = 0; i < strFiles.Length; i++)
...{
WordToHtmlFile(strFiles[i]);
}
DirectoryInfo dirInfo = new DirectoryInfo(WordFileDir);
//取得源文件夹下的所有子文件夹名称
DirectoryInfo[] ZiPath = dirInfo.GetDirectories();
for (int j = 0; j < ZiPath.Length; j++)
...{
//获取所有子文件夹名
string strZiPath = WordFileDir + "/" + ZiPath[j].ToString();
//把得到的子文件夹当成新的源文件夹,从头开始新一轮的搜索
DealWithWordFile(strZiPath);
}
}
//转化
private static void WordToHtmlFile(string WordFilePath)
...{
try
...{
Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
// 指定原文件和目标文件
object Source = WordFilePath;
string SaveHtmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) + "html";
object Target = SaveHtmlPath;
// 缺省参数
object Unknown = Type.Missing;
//为了保险,只读方式打开
object readOnly = true;
// 打开doc文件
Microsoft.Office.Interop.Word.Document doc = newApp.Documents.Open(ref Source, ref Unknown,
ref readOnly, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
// 指定另存为格式(rtf)
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
// 转换格式
doc.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
// 关闭文档和Word程序
doc.Close(ref Unknown, ref Unknown, ref Unknown);
newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
}
catch(Exception e)
...{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
}
}
created: 2007/11/02
created: 2:11:2007 23:13
filename: D:C#程序练习WordToChmWordToHtml.cs
file path: D:C#程序练习WordToChm
file base: WordToHtml
file ext: cs
author: 凌剑 Bujiwu
purpose: 将Word文件转化为Html文件
*********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace CreateWordToHtmlFileSpace
...{
class WordToHtml
...{
public static void CreateWordToHtmlFile(string WordFileDir)
...{
DealWithWordFile(WordFileDir);
}
//搜索WordFileDir在的*.doc文件
private static void DealWithWordFile(string WordFileDir)
...{
//创建数组保存源文件夹下的文件名
string[] strFiles = Directory.GetFiles(WordFileDir, "*.doc");
for (int i = 0; i < strFiles.Length; i++)
...{
WordToHtmlFile(strFiles[i]);
}
DirectoryInfo dirInfo = new DirectoryInfo(WordFileDir);
//取得源文件夹下的所有子文件夹名称
DirectoryInfo[] ZiPath = dirInfo.GetDirectories();
for (int j = 0; j < ZiPath.Length; j++)
...{
//获取所有子文件夹名
string strZiPath = WordFileDir + "/" + ZiPath[j].ToString();
//把得到的子文件夹当成新的源文件夹,从头开始新一轮的搜索
DealWithWordFile(strZiPath);
}
}
//转化
private static void WordToHtmlFile(string WordFilePath)
...{
try
...{
Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
// 指定原文件和目标文件
object Source = WordFilePath;
string SaveHtmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) + "html";
object Target = SaveHtmlPath;
// 缺省参数
object Unknown = Type.Missing;
//为了保险,只读方式打开
object readOnly = true;
// 打开doc文件
Microsoft.Office.Interop.Word.Document doc = newApp.Documents.Open(ref Source, ref Unknown,
ref readOnly, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
// 指定另存为格式(rtf)
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
// 转换格式
doc.SaveAs(ref Target, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
// 关闭文档和Word程序
doc.Close(ref Unknown, ref Unknown, ref Unknown);
newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
}
catch(Exception e)
...{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
}
}
杨航收集技术资料,分享给大家
- C#Word转Html的类
- C#Word转Html的类
- 把Word转为简洁html的若干方法 清理 拷贝 word 垃圾 代码 ,word 转 html
- C#.NET Word 转成 Html
- 【word | html】word(doc | docx) 转 html
- word转html格式的方法
- 清除Word转html的垃圾代码
- word 2007转html的Java实现
- java word转HTML
- Java Word转Html
- html转word
- HTML 转 Word
- poi word转html
- Java Word转Html
- java word转html
- php word 转 html
- word 转html
- HTML2DOC html转word
- 浅谈JSP自定义标签实现过程
- python os 命令
- JPA关系映射
- 递归下降方法和LL(1)实现计算器C++
- crazy messy study going
- C#Word转Html的类
- 游戏相关链接
- JAVA 代理模式(Proxy)
- Domino的java代理优化(移出jar包的配置)(jco)
- 能力要求
- jsp页面获取参数 执行sql查询数据库
- c++11标准带来的最显著变化(及为何该引起你的注意)
- mysql error 1129 错误
- 标准差(Standard Deviation) 和 标准误差(Standard Error)