㈠ 如何用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;} 希望能幫到你!