word辅助类Word文档下载推荐.docx
- 文档编号:16423441
- 上传时间:2022-11-23
- 格式:DOCX
- 页数:16
- 大小:20.32KB
word辅助类Word文档下载推荐.docx
《word辅助类Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《word辅助类Word文档下载推荐.docx(16页珍藏版)》请在冰豆网上搜索。
System.Drawing;
System.Windows.Forms;
System.IO;
namespace
WordAddinSample
{
public
class
WordHelp
private
Microsoft.Office.Interop.Word.ApplicationClass
oWordApplic;
//
a
reference
to
application
Microsoft.Office.Interop.Word.Document
oDoc;
the
document
object
missing
=
System.Reflection.Missing.Value;
WordApplication
get
{
return
}
WordHelp()
activate
interface
with
COM
of
Word
oWordApplic
new
Microsoft.Office.Interop.Word.ApplicationClass();
WordHelp(Microsoft.Office.Interop.Word.ApplicationClass
wordapp)
wordapp;
#region
文件操作
Open
file
(the
must
exists)
and
it
void
Open(string
strFileName)
fileName
strFileName;
readOnly
false;
isVisible
true;
oDoc
oWordApplic.Documents.Open(ref
fileName,
ref
missing,
readOnly,
missing,
isVisible,
missing);
oDoc.Activate();
Open()
oWordApplic.Documents.Add(ref
Quit()
oWordApplic.Application.Quit(ref
///
<
summary>
附加dot模版文件
/summary>
LoadDotFile(string
strDotFile)
if
(!
string.IsNullOrEmpty(strDotFile))
wDot
null;
(oWordApplic
!
null)
oWordApplic.ActiveDocument;
oWordApplic.Selection.WholeStory();
//string
strContent
oWordApplic.Selection.Text;
oWordApplic.Selection.Copy();
CreateWordDocument(strDotFile,
true);
bkmC
"
Content"
;
(oWordApplic.ActiveDocument.Bookmarks.Exists("
)
==
true)
oWordApplic.ActiveDocument.Bookmarks.get_Item
(ref
bkmC).Select();
//对标签"
进行填充
//直接写入内容不能识别表格什么的
//oWordApplic.Selection.TypeText(strContent);
oWordApplic.Selection.Paste();
wDot.Close(ref
打开Word文档,并且返回对象oDoc
完整Word文件路径+名称
返回的Word.Document
oDoc对象
CreateWordDocument(string
FileName,
bool
HideWin)
(FileName
oWordApplic.Visible
HideWin;
oWordApplic.Caption
oWordApplic.Options.CheckSpellingAsYouType
oWordApplic.Options.CheckGrammarAsYouType
filename
FileName;
ConfirmConversions
ReadOnly
AddToRecentFiles
PasswordDocument
System.Type.Missing;
PasswordTemplate
Revert
WritePasswordDocument
WritePasswordTemplate
Format
Encoding
Visible
OpenAndRepair
DocumentDirection
NoEncodingDialog
XMLTransform
try
wordDoc
filename,
ConfirmConversions,
ReadOnly,
AddToRecentFiles,
PasswordDocument,
PasswordTemplate,
Revert,
WritePasswordDocument,
WritePasswordTemplate,
Format,
Encoding,
Visible,
OpenAndRepair,
DocumentDirection,
NoEncodingDialog,
XMLTransform);
wordDoc;
catch
(Exception
ex)
MessageBox.Show(ex.Message);
SaveAs(Microsoft.Office.Interop.Word.Document
oDoc,
string
(File.Exists(strFileName))
(MessageBox.Show("
文件'
+
strFileName
'
已经存在,选确定覆盖原文件,选取消退出操作!
警告"
MessageBoxButtons.OKCancel)
DialogResult.OK)
oDoc.SaveAs(ref
else
Clipboard.Clear();
SaveAsHtml(Microsoft.Office.Interop.Word.Document
//wdFormatWebArchive保存为单个网页文件
//wdFormatFilteredHTML保存为过滤掉word标签的htm文件,缺点是有图片的话会产生网页文件夹
(int)Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatWebArchive;
Format,
Save()
oDoc.Save();
SaveAs(string
Save
document
in
HTML
format
SaveAsHtml(string
(int)Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
#endregion
添加菜单(工具栏)项
//添加单独的菜单项
AddMenu(Microsoft.Office.Core.CommandBarPopup
popuBar)
Microsoft.Office.Core.CommandBar
menuBar
this.oWordApplic.CommandBars["
Menu
Bar"
];
popuBar
(Microsoft.Office.Core.CommandBarPopup)this.oWordApplic.CommandBars.FindControl(Microsoft.Office.Core.MsoControlType.msoControlPopup,
popuBar.Tag,
(popuBar
(Microsoft.Office.Core.CommandBarPopup)menuBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlPopup,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- word 辅助