㈠ 如何用VC在word中添加,操作表格
选中你要插入的地方
鼠标右击选择插入就好哩!
㈡ 如何用VC将Crystal Report水晶报表输出成PDF格式或者EXCEL格式、WORD格式
点击左上角的图标就可以了。
㈢ 怎么使用vc控制word画出列的宽度不同的表格
在Word中,自定义表格线条宽度的设置方法:
1、选中表格;
2、单击页面布局----页面边框按钮;
3、弹出边框和底纹对话框,选择边框选项卡,在宽度处单击,在下拉选项中选择一种线宽即可
㈣ 关于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 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.
当以上步骤完成后,你会看到项目中有很多新的类,那些类就对应着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表格,指定单元格合并
打开Word2010文档页面,选择表格中需要合并的两个或两个以上的单元格。
㈥ 请问如何在vc6.0的MFC程序导出word表格并添加文字
刚好前段时间弄过。我把大致的代码粘上你看下吧。是C#的。和你说下思路吧,先在WORD中画好要打印的表,并且设置好,横向的可以在“文件”->“页面设置”里设置。然后把要绑定数据库的部分插入书签。打印的时候调用设计好的那个WORD文件把数据库的内容绑定到书签就行了。首先要在程序中引入COM组件中的Microsoft Word 11。安装的word中要包括.net编程组件和Interop(默认是不安装的)。public void bindAndPrint(){ //绑定Work和数据库Microsoft.Office.Interop.Word.Application app = null;
Microsoft.Office.Interop.Word.Document doc = null;
object missing = System.Reflection.Missing.Value;
object templateFile = Application.StartupPath + @"\word模板.doc";try
{
app = new Microsoft.Office.Interop.Word.ApplicationClass();
doc = app.Documents.Add(ref templateFile, ref missing, ref missing, ref missing);
try
{
foreach (Microsoft.Office.Interop.Word.Bookmark bm in doc.Bookmarks)
{
bm.Select();
string item = bm.Name;
if (item.Equals("title")) //word中的书签名"title"
{
bm.Range.Text = title; //title为要替换书签的变量, //即可以将数据库中的值读入title中
}
}
}
catch
{ } //打印 doc.PrintOut(ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, this.Text);
} //结束word进程 finally
{
object saveChange = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
if (doc != null) doc.Close(ref saveChange, ref missing, ref missing);
if (app != null) app.Quit(ref missing, ref missing, ref missing);
} break;} 希望能帮到你!