乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > <em>Vc</em>++ 操作word文档,光标怎么移到指定位置-vc word操作,vc读w

<em>Vc</em>++ 操作word文档,光标怎么移到指定位置-vc word操作,vc读w

作者:乔山办公网日期:

返回目录:word文档


添加包含总页数的自定义页码
库中的一些页码含有总页数(第 X 页,共 Y 页)。但是,如果要创建自定义页码,请执行下列操作:
双击页眉区域或页脚区域(靠近页面顶部或页面底部)。
这将打开“页眉和页脚工具”下的“设计”选项卡。
若要将页码放置到页面中间或右侧,请执行下列操作:
若要将页码放置到中间,请单击“设计”选项卡的“位置”组中的“插入‘对齐方式’选项卡”,单击“居中”,再单击“确定”。
若要将页码放置到页面右侧,请单击“设计”选项卡的“位置”组中的“插入‘对齐方式’选项卡”,单击“靠右”,再单击“确定”。
键入第和一个空格。
在“插入”选项卡上的“文本”e5a48de588b6e79fa5e98193331组中,单击“文档部件”,然后单击“域”。
在“域名”列表中,单击“Page”,再单击“确定”。
在该页码后键入一个空格,再依次键入页、逗号、共,然后再键入一个空格。
在“插入”选项卡上的“文本”组中,单击“文档部件”,然后单击“域”。
在“域名”列表中,单击“NumPages”,然后单击“确定”。
在总页数后键入一个空格,再键入页。
若要更改编号格式,请单击“页眉和页脚”组中的“页码”,再单击“设置页码格式”。
若要返回至文档正文,请单击“设计”选项卡(位于“页眉和页脚工具”下)上的“关闭页眉和页脚”。

你好,用键盘的左右键移动

答题不易,互相理解,您的采纳是我前进的动力,
如果我的回答没能帮助您,请继续追问。
您也可以向我们团队发出请求,会有更专业的人来为您解答。
您的追问、采纳,是我前进的动力,祝天天开心。
dt.GetDateTimeFormats('s')[0].ToString();//2005-11-05T14:06:25
dt.GetDateTimeFormats('t')[0].ToString();//14:06
dt.GetDateTimeFormats('y')[0].ToString();//2005年11月
dt.GetDateTimeFormats('D')[0].ToString();//2005年11月5日
dt.GetDateTimeFormats('D')[1].ToString();//2005 11 05
dt.GetDateTimeFormats('D')[2].ToString();//星期六7a64e59b9ee7ad94338 2005 11 05
dt.GetDateTimeFormats('D')[3].ToString();//星期六 2005年11月5日
dt.GetDateTimeFormats('M')[0].ToString();//11月5日
dt.GetDateTimeFormats('f')[0].ToString();//2005年11月5日 14:06
dt.GetDateTimeFormats('g')[0].ToString();//2005-11-5 14:06
dt.GetDateTimeFormats('r')[0].ToString();//Sat, 05 Nov 2005 14:06:25 GMT

下面是从CSDN上摘抄过来的,主要是今天调试VC操作Word2003的时候,网上下载的是操作Word 2000,但是参数已经有一些不同了。下面的代码可以在2003中运行,记录在这里便于以后复习用。

感谢您使用微软产品。

对于您所提的问题,确实可以使用OLE Automation在VC++中对Word Object Model进行操作。下面这篇知识库文章中给出了如何在VC_++中引入Office TypeLib,并通过程序启动MS Excel.参照这篇文章可以使您建立起程序的框架

Q178749 HOWTO: Create Automation Project Using MFC and a Type Library
http://support.microsoft.com/support/kb/articles/q178/7/49.asp

以下两篇知识库文章给出了具体的样例,如何操作Word和Excel. 您可以使用其中的方法来完成你自己的操作。具体的对象模型的操作,您需要参见对应产品的VBA帮助文档。

Q178784 HOWTO: Use Automation to Open and Print a Word Document
http://support.microsoft.com/support/kb/articles/q178/7/84.asp

Q179706 HOWTO: Use MFC to Automate Excel and Create/Format a New Workboo
http://support.microsoft.com/support/kb/articles/q179/7/06.asp

这两篇是介绍一些基础的知识以及Office 产品在Automation 上的一些支持以及常见问题。您可以用作参考。

Q238972 INFO: Using Visual C++ to Automate Office
http://support.microsoft.com/support/kb/articles/q238/9/72.asp

Q196776 FAQ: Office Automation Using Visual C++
http://support.microsoft.com/support/kb/articles/q196/7/76.asp

此外,我在以下列出了Q178784中的样例代码,并添加了一些中文注释。

Steps to Create the Project
---------------------------

1. In Microsoft Word, create a new document, add some text to the document, and save it as Test.doc. Close the document and exit Word.

2. Follow steps 1 through 12 in the following Microsoft Knowledge Base article to create a sample project that uses the IDispatch interfaces and member functions defined in the MSWord8.olb type library:

Q178749 HOWTO: Create an Automation Project Using MFC and a Type Library

请先按照Q178749的步骤建立一个框架程序,并引入Word typelib.

3. At the top of the AutoProjectDlg.cpp, add the following line:

#include "msword8.h" // msword9.h for Word 2000, msword.h for Word 2002

4. Add the following code to CAutoProjectDlg::OnRun() in the AutoProjectDLG.cpp
file.

当以上步骤完成后,你会看到项e79fa5e98193e59b9ee7ad94365目中有很多新的类,那些类就对应着Word的对象模型。

Sample Code
-----------

_Application objWord; //定义Word应用程序对象(Word.application)

// Convenient values declared as ColeVariants.
COleVariant covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

// Get the IDispatch pointer and attach it to the objWord object.
if (!objWord.CreateDispatch("Word.Application"))
{
AfxMessageBox("Couldn't get Word object.");
return;
}

objWord.SetVisible(TRUE); //This shows the application.

Documents docs(objWord.GetDocuments());//定义Word Documents对象(Word.Documents)

_Document testDoc; //定义Word Document对象(Word.Document)

testDoc.AttachDispatch(docs.Open( //可看成VB语句set testDoc = Word.documents.Open(…)
COleVariant("C:\\Test.doc",VT_BSTR),
covFalse, // Confirm Conversion.
covFalse, // ReadOnly.
covFalse, // AddToRecentFiles.
covOptional, // PasswordDocument.
covOptional, // PasswordTemplate.
covFalse, // Revert.
covOptional, // WritePasswordDocument.
covOptional, // WritePasswordTemplate.
covOptional) // Format. // Last argument for Word 97
covOptional, // Encoding // New for Word 2000/2002
covTrue, // Visible
covOptional, // OpenConflictDocument
covOptional, // OpenAndRepair
(long)0, // DocumentDirection wdDocumentDirection LeftToRight
covOptional // NoEncodingDialog
) // Close Open parameters
); // Close AttachDispatch(?)

AfxMessageBox("Now printing 2 copies on the active printer");

testDoc.PrintOut(covFalse, // Background. //可看成VB语句testDoc.PrintOut(…)
covOptional, // Append.
covOptional, // Range.
covOptional, // OutputFileName.
covOptional, // From.
covOptional, // To.
covOptional, // Item.
COleVariant((long)2), // Copies.
covOptional, // Pages.
covOptional, // PageType.
covOptional, // PrintToFile.
covOptional, // Collate.
covOptional, // ActivePrinterMacGX.
covOptional // ManualDuplexPrint.
covOptional, // PrintZoomColumn New with Word 2002
covOptional, // PrintZoomRow ditto
covOptional, // PrintZoomPaperWidth ditto
covOptional); // PrintZoomPaperHeight ditto

// If you wish to Print Preview the document rather than print it,
// you can use the PrintPreview member function instead of the
// PrintOut member function:
// testDoc.PrintPreview.

objWord.Quit(covFalse, // SaveChanges.
covTrue, // OriginalFormat.
covFalse // RouteDocument.
);

5. You may need to modify the code in CAutoProjectDlg::OnRun() to indicate the correct path for your document Test.doc. The document is referenced in the following line:

testDoc.AttachDispatch(docs.Open(
COleVariant("C:\\My Docs\\Test.doc",VT_BSTR)...

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网