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
}
查看全文
相关阅读:
AC自动机模板
HDU 3065 病毒侵袭持续中(AC自动机)
HDU 2896 病毒侵袭(AC自动机)
HDU 2222 Keywords Search (AC自动机模板题)
HDU 1113 Word Amalgamation
HDU 1171 Big Event in HDU(母函数或01背包)
37.Qt网络与通信
2.Matlab数值数组及其运算
36.QT地图
35.QT蝴蝶飞舞
原文地址:https://www.cnblogs.com/goldnet/p/1515148.html
最新文章
lumerical中DEVICE和MODE模块的交互使用(真的很干货!!可以自信的说网上绝对找不到比我更详细的步骤了)
python中的进程和线程
VIM编辑器和VI编辑器的区别
关于怎么在CSDN中修改代码行中字体的颜色
python中的异常处理tryexcept
python中的静态方法、类方法、属性方法(福利:关于几种方法更好的解释)
poj3686The Windy's(费用流)
图上的文章续(KM算法)
bzoj1083 [SCOI2005]繁忙的都市(最小生成树)
Tyvj(无向图的桥)
热门文章
Tyvj(无向图的桥)
图上的文章(割点和桥)
图上的文章(割点和桥)
置换和轮换(新姿势,摘自黑书)
背包九讲
背包九讲
HDU 2296 Ring (AC自动机+DP)
HDU 2457 DNA repair(AC自动机+DP)
codeforces 862B Mahmoud and Ehab and the bipartiteness (DFS或带权并查集)
HDU 2566 统计硬币 (母函数或dfs)
Copyright © 2011-2022 走看看