zoukankan
html css js c++ java
将word转换成其它文件
Code
1
/**/
///
<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
{
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
{
18
object
objSaveFormat
=
Word.WdSaveFormat.wdFormatWebArchive;
//
单一网页格式
19
switch
(FormatType.ToLower())
20
{
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
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
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
51
}
52
53
catch
(Exception ex)
54
{
55
56
sErr
=
"
文件转换出错:
"
+
ex.Message;
57
58
}
59
60
finally
61
{
62
object
oSavaType
=
Word.WdSaveOptions.wdDoNotSaveChanges;
63
app.Quit(
ref
oSavaType,
ref
oMissing,
ref
oMissing);
64
65
}
66
return
sErr;
67
68
}
查看全文
相关阅读:
poj_1836 动态规划
动态规划——最长上升子序列
poj_3260 动态规划
poj_3628 动态规划
动态规划——背包问题
poj_2559 单调栈
poj_3415 后缀数组+单调栈
poj_2823 线段树
poj_2823 单调队列
poj_3250 单调栈
原文地址:https://www.cnblogs.com/goldnet/p/1515148.html
最新文章
转:MVC 数据验证
jQuery解析AJAX返回的html数据时碰到的问题与解决
Realm学习总结
Perfect-Server-Swift学习记录
Swift小知识点总结
React Native使用Mobx总结
安卓模拟器添加图片
记一次更换手机号的感受
react-native-picke Cannot read property '_init' of undefined
React Native使用react-navigation时,设置navigationOptions中Static中使用this注意点
热门文章
MySQL 如何利用一条语句实现类似于if-else条件语句的判断
列举你所知道的排序方法,请写出快速排序的伪代码
List、Map、Set三个接口,存取元素时,各有什么特点?
详解Oracle DELETE和TRUNCATE 的区别
使用javascript打开链接的多种方法
mybatis13---2级缓存
mybatis12一级缓存
Mybatis中#和$的区别
Compilation failed: internal java compiler error
MyBatis动态代理查询出错
Copyright © 2011-2022 走看看