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
}
查看全文
相关阅读:
博弈论--sg函数
博弈论--nim博弈
dp--bitset优化
树--欧拉序
树--dfs序
树--dsu on tree
树--树的重心
单调队列
单调栈
dp--背包
原文地址:https://www.cnblogs.com/goldnet/p/1515148.html
最新文章
android开发之配置文件
Android数据保存方式
From Windows Live Writer
android 检测摇一摇
Radmin密码破解新招
css-triangle
【grunt整合版】30分钟学会使用grunt打包前端代码
子div margin-top bottom转移到父div
ng-click获取事件
js 小记
热门文章
AngularJS ng-repeat下使用ng-model 转
HTML5 canvas save和restore方法讲解
css3---background-size:cover/contain
js 函数名的赋值
JS 中 new 操作符
最小生成树
字典树
二分与三分的应用场景
数论--杜教BM
dp--换根dp
Copyright © 2011-2022 走看看