-
将word转换成其它文件
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <summary>
2
/// 将word文档转换为其它文档
3
/// </summary>
4
/// <param name="SourceFile">源文件</param>
5
/// <param name="DestFile">目标文件</param>
6
/// <param name="FormatType">转换的文件格式(webarchive:mht;html:html网页;rtf;xml)</param>
7
/// <returns></returns>
8
public static string WordToHtml(object SourceFile, object DestFile, string FormatType)
9![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
10
Word.Application app = new Word.Application();
11
//bool isAlert = app.DisplayAlerts;
12
// app.DisplayAlerts = false;
13
string sErr = "ok";
14
object oMissing = System.Reflection.Missing.Value;
15
16
try
17![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
18
object objSaveFormat = Word.WdSaveFormat.wdFormatWebArchive; //单一网页格式
19
switch (FormatType.ToLower())
20![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
21
case "webarchive":
22
objSaveFormat = Word.WdSaveFormat.wdFormatWebArchive;
23
break;
24
case "html":
25
objSaveFormat = Word.WdSaveFormat.wdFormatHTML;
26
break;
27
case "rtf":
28
objSaveFormat = Word.WdSaveFormat.wdFormatRTF;
29
break;
30
case "xml":
31
objSaveFormat = Word.WdSaveFormat.wdFormatXML;
32
break;
33![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
}
35
object objTrue = true;
36
object objFalse = false;
37
object objOpenFormat = Word.WdOpenFormat.wdOpenFormatDocument;
38
object objEncoding = null;
39
object objDirection = Word.WdDocumentDirection.wdLeftToRight;
40
Word.Document doc = app.Documents.Open(ref SourceFile, ref objFalse, ref objFalse
41
, ref objFalse, ref oMissing, ref oMissing, ref objTrue
42
, ref oMissing, ref oMissing, ref objOpenFormat, ref objEncoding, ref objTrue
43
, ref objFalse, ref objDirection, ref objFalse, ref oMissing);
44![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
doc.SaveAs(ref DestFile, ref objSaveFormat, ref objFalse, ref oMissing, ref objFalse, ref oMissing, ref objFalse,
46
ref oMissing, ref objTrue, ref objFalse, ref objFalse, ref objEncoding, ref objFalse, ref objFalse,
47
ref oMissing, ref oMissing);
48
object oSavaType = Word.WdSaveOptions.wdSaveChanges;
49
doc.Close(ref oSavaType, ref oMissing, ref oMissing);
50![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
}
52![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
catch (Exception ex)
54![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
55![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
sErr = "文件转换出错:" + ex.Message;
57![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
}
59![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
finally
61![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
62
object oSavaType = Word.WdSaveOptions.wdDoNotSaveChanges;
63
app.Quit(ref oSavaType, ref oMissing, ref oMissing);
64![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
}
66
return sErr;
67![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
68
}
-
相关阅读:
Repeater自定义翻页 存储过程实现
Redis常用命令
常用的富文本框插件FreeTextBox、CuteEditor、CKEditor、FCKEditor、TinyMCE、KindEditor ;和CKEditor实例
网站转接支付宝解决方案
如何有效抓取SQL Server的BLOCKING信息
SVN 冲突文件详解
JavaScript可否多线程? 深入理解JavaScript定时机制
MS SQL Server:分区表、分区索引详解
支付宝外部商家购物流程
排查数据库性能的常用sql语句
-
原文地址:https://www.cnblogs.com/goldnet/p/1515148.html
Copyright © 2020-2023
润新知