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
}
查看全文
相关阅读:
于丹的婚姻观
相貌与成功的关系—俞敏洪6月2号在同济大学的演讲
NetBeans IDE 6.9.1 发布
NetBeans IDE 6.9.1 发布
NetBeans 时事通讯(刊号 # 112 Aug 05, 2010)
VS Feature Pack学习之使用CMFCMenuBar自定义菜单栏
使用 Apache Wink、Eclipse 和 Maven 开发 RESTful Web 服务
Have to run sudo dhclient eth0 automatically every boot
java regex
HTTPCLIENT 解决乱码方案 linfeng_0212的日志 网易博客
原文地址:https://www.cnblogs.com/goldnet/p/1515148.html
最新文章
艾伟_转载:[一步一步MVC]第六回:什么是MVC(上)? 狼人:
艾伟_转载:使用LINQ to SQL更新数据库(中):几种解决方案 狼人:
艾伟_转载:[一步一步MVC]第三回:MVC范例大观园 狼人:
艾伟_转载:.NET Discovery 系列之四深入理解.NET垃圾收集机制(下) 狼人:
艾伟_转载:VS 2010 和 .NET 4.0 系列之《VS 2010代码智能提示的改进》篇 狼人:
艾伟_转载:.NET Discovery 系列之二string从入门到精通(勘误版下) 狼人:
艾伟_转载:Visual Studio DSL 入门 1 狼人:
TCHAR,WCHAR,LPSTR,LPWSTR,LPCTSR的区别
学vc,加油站(一)区域渐变
用 公平的算法 把一个数组打乱(两种实现方式)
热门文章
小Q系列故事——大笨钟
cocos2dx监听home键,锁屏,后台转前台暂停功能
后缀为 axd 与 ashx 的文件有什么区别
core 文件生成设置详解
学习笔记之cocos2dx2.1.1实现读取.plist文件(使用数组CCArray)
[跟着hsp步步学习系统]oracle培训学习集锦全360度扫描
sql server如何查询一个表中的一个列是否存在唯一约束 比如查询 AA表的 BB列
使用 Apache Wink、Eclipse 和 Maven 开发 RESTful Web 服务
NetBeans 时事通讯(刊号 # 112 Aug 05, 2010)
如果你学习C++,请不要选择DevCpp
Copyright © 2011-2022 走看看