文件管理 · 2022年9月7日

vcword操作|vc操作wordvc在操作word时如果写入数据非常大访问就会越来越慢!请问有什么方式可以提

⑴ VC下操作word,按指定格式把替换文本。

word里面录制宏看下,然后用对应的ole方法操作Selection.Font.Bold = wdToggleSelection.Font.UnderlineColor = wdColorAutomaticSelection.Font.Underline = wdUnderlineSingle如果你引用了Office的lib,可以直接使用这些枚举,如果用的自动化接口,可以查下这些枚举对应的值,直接给属性赋值也可以

⑵ 怎样用VC++操作word实现文字替换

1、基本替换用word替换文本是很简单的:首先打开一个文档,执行“编辑一〉替换”(或按“Ctrl+H”组合键),打开“查找和替换”对话框,在“查找内容”右侧的方框中输入需要替换的字符,在“替换为”右侧的方框中输入替换后的字符,然后单击“全部替换”按钮即…

⑶ 关于VC如何操作word2003

下面是从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 Libraryhttp://support.microsoft.com/support/kb/articles/q178/7/49.asp以下两篇知识库文章给出了具体的样例,如何操作Word和Excel. 您可以使用其中的方法来完成你自己的操作。具体的对象模型的操作,您需要参见对应产品的VBA帮助文档。Q178784 HOWTO: Use Automation to Open and Print a Word Documenthttp://support.microsoft.com/support/kb/articles/q178/7/84.aspQ179706 HOWTO: Use MFC to Automate Excel and Create/Format a New Workboohttp://support.microsoft.com/support/kb/articles/q179/7/06.asp这两篇是介绍一些基础的知识以及Office 产品在Automation 上的一些支持以及常见问题。您可以用作参考。Q238972 INFO: Using Visual C++ to Automate Officehttp://support.microsoft.com/support/kb/articles/q238/9/72.aspQ196776 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 20024. Add the following code to CAutoProjectDlg::OnRun() in the AutoProjectDLG.cpp file.当以上步骤完成后,你会看到项目中有很多新的类,那些类就对应着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)…

⑷ 请教用vc++操作word,对标题进行编号,并插入目录。

把光标放在文章开头处。打开“插入”下拉菜单,选引用→索引和目录→目录,选择目录的级别,选择“显示页码”、“页码右对齐”等,然后点确定。生成目录后你就可以按住“strl”键点目录链接了。不过要进行上述操作,必须具备以下条件:一、目录是使用了大纲级别或标题样式,打文章时应设置标题格式。输入标题格式时的操作:输入标题时,点格式工具栏的左侧样式窗口,或打开“格式”菜单下的“样式和格式”,出现右边的一条“样式和格式”栏,这里面主要就是用到标题1、标题2、标题3和正文。把标题1,标题2,标题3分别应用到文中各个章节的标题上。当然标题1、标题2、标题3和正文的属性(如字体大小,居中,加粗,等等)可以自行修改的。修改方法:右键点击“标题1”选“修改”,会弹出“修改样式”菜单,您可以根据自己的要求自行修改。点该对话框的左下角的“格式”会弹出一个下拉菜单,选择“段落”,可以设置段落格式,全部设置完后,点“确定”。如果文章已经写完,可以补做上述操作。选定需要设置样式的标题或段落,选择对应的级别;下一个同样标题和段落,只要把光标置于需要设置样式的标题或段落中,选择对应的级别就行了。做上述操作后,标题左侧会有个黑色小方块标志。提示:如果文章已经写完,先按Ctrl+A选定全部文档,点“正文”,然后再设置每个标题就比较省事了。二、如果你还没有插入页码,还需要插入页码。1.单击“插入”菜单中的“页码”命令。2.在“位置”框中,指定是将页码打印于页面顶部的页眉中还是页面底部的页脚中。3.在“对齐方式”框中指定页码相对页边距的左右,是左对齐、居中还是右对齐。4.如果您不希望页码出现在首页,可清除“首页显示页码”对话框。这些都完成后,就可以进行开头的操作了。如果你重新修改了文章内容,就需要更新一下目录,方法是:在目录区域内,点右键,选“更新域”。当选“更新域”后,选第二个“更新整个目录”点确定。就OK了。。希望对你有所帮助

⑸ 如何用VC在Word中添加,操作表格

选中你要插入的地方鼠标右击选择插入就好哩!

⑹ vc操作wordvc在操作word时,如果写入数据非常大,访问就会越来越慢!请问有什么方式可以提

试试一次开好空间,不要把New 或新建对象放到迭代体内部。

⑺ 如何用VC操作word时,实现插入换页符

你好!有两种方法:方法一:插入-分页符。方法二:Ctrl+Enter,两个键一起按就可以。

⑻ 用VC怎样取某WORD文件里的第X段内容

三种方法:一是直接读取.doc文档,可以将所有的文本读入到字符串中在做相关处理:C# code?using System.IO;string temp = System.IO.File.OpenText(@“D:\word.doc”).ReadToEnd();//读取doc文档二是通过调用.NET对于Office的COM组件来做:C# code?using Microsoft.Office.Interop.Word;Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();//打开word程序Microsoft.Office.Interop.Word.Document doc = null;//实例化一个新的word文档object unknow = Type.Missing;app.Visible = true;doc = app.Documents.Open(ref fileName,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow,ref unknow);string temp = doc.Content.Text.Trim();//将全篇内容存入字符串中,也可以调用别的方法,具体可以查询MSDN…三是将Word转为XML,可以根据要求提取内容,包括标题,目录等等~~C# code?using System.XML;XmlDocument doc = new XmlDocument();doc.Load(filePath); //载入XML文档XmlElement root = doc.DocumentElement; //定义载入XML的根节点foreach(XmlNode xn1 in root.ChildNodes) //对于根节点以外的子节点做循环,以下同理{//对元素处理~~~}