03-03-2005 01:21 PM
03-03-2005 06:33 PM
03-04-2005 03:37 AM
03-04-2005 05:17 PM
#include "oleacc.h"
#include "atlbase.h"
#pragma warning(push)
#pragma warning(disable: 4278)
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\Office10\\mso.dll" \
rename_namespace("OfficeXP")
using namespace OfficeXP;
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.olb" \
rename_namespace("VBE6")
using namespace VBE6;
#import "C:\\Program Files\\Microsoft Office\\Office10\\MSWORD.olb" \
rename("ExitWindows", "WordExitWindows") \
named_guids, \
rename_namespace("MSWord")
using namespace MSWord;
#pragma warning(pop)
CNiWordApplication app;
CNiWordDocument document = app.CreateDocument();
document.AppendLine(_T("Line 1"));
CComQIPtr<_Document> spDocument(document.GetDispatch(false));
spDocument->PrintPreview();
// ...
CNiWordApplication app;
CNiWordDocument document = app.CreateDocument();
document.AppendLine(_T("Line 1"));
document.AppendLine(_T("Line 2"));
document.AppendLine(_T("Line 3"));
document.MoveCursorUp(3);
CComQIPtr<_Application> spApplication(app.GetDispatch(true));
SelectionPtr selection = spApplication->Selection;
FindPtr find = selection->Find;
find->Text = _bstr_t(_T("Line 2"));
VARIANT_BOOL success = find->Execute();
03-07-2005 04:36 AM
03-07-2005 09:58 AM
03-07-2005 10:26 AM
03-07-2005 09:44 PM
03-08-2005 01:48 AM
03-08-2005 01:15 PM
// Create an example document
CNiWordApplication app;
CNiWordDocument document = app.CreateDocument();
// Create an example table.
CNiWordTable table = document.AddTable(2, 2);
table.WriteToCell(1, 1, _T("Cell 1"));
table.WriteToCell(1, 2, _T("Cell 2"));
table.WriteToCell(2, 1, _T("Cell 3"));
table.WriteToCell(2, 2, _T("Cell 4"));
// Retrieve the text of the first cell of the table.
CComQIPtr<_Application> spApp(app.GetDispatch(false));
_DocumentPtr spDocument = spApp->ActiveDocument;
TablesPtr spTables = spDocument->Tables;
TablePtr spTable = spTables->Item(1);
CellPtr spCell = spTable->Cell(1, 1);
RangePtr spRange = spCell->Range;
_bstr_t cellText = spRange->Text;
// Display the text in a message box ("Cell 1").
MessageBox(cellText);