问题如标题.........希望大侠们帮我解决下,可能的话给点简短代码提示下......无限感激~~~

解决方案 »

  1.   

    我用过这个控件来整,但是可以用VBA来操作word。
    你可以参考一下
    http://www.vckbase.com/document/viewdoc/?id=1174
    而且用VC2005导入的时候他的文件时有些变化了!
      

  2.   

    http://www.vckbase.com/document/viewdoc/?id=1174
    里面的例子我都看过了,稍微修改下,套进去还是用不了,是不是没捕抓到webbroswer打开的word文件啊,所以无法操作啊?
      

  3.   

      修改后所用的程序:      
            _Application app;
    app.CreateDispatch(_T("Word.Application"));
        // app.SetVisible(TRUE); Documents docs=app.GetDocuments();
    CComVariant Template(_T(""));
    CComVariant NewTemplate(false),DocumentType(0),Visible;
    docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);

    _Document doc=app.GetActiveDocument();  
    CComVariant FileName(_T("c:\\doc.doc")); //文件名
    CComVariant FileFormat(0);      
    CComVariant LockComments(false),Password(_T(""));
    CComVariant AddToRecentFiles(true),WritePassword(_T(""));
    CComVariant ReadOnlyRecommended(false),EmbedTrueTypeFonts(false);
    CComVariant SaveNativePictureFormat(false),SaveFormsData(false);
    CComVariant SaveAsAOCELetter(false);

    doc.SaveAs(&FileName,&FileFormat,&LockComments,&Password,
    &AddToRecentFiles,&WritePassword,&ReadOnlyRecommended,
    &EmbedTrueTypeFonts,&SaveNativePictureFormat,&SaveFormsData,
    &SaveAsAOCELetter,NULL,NULL,NULL,NULL,NULL);
    doc.ReleaseDispatch();
    docs.ReleaseDispatch();

    CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
    app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
    app.ReleaseDispatch();

    app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
    app.ReleaseDispatch();报错:向占位程序传送了空的索引指针
      

  4.   

    修改后所用的程序:   
      _Application app;
    app.CreateDispatch(_T("Word.Application"));
      // app.SetVisible(TRUE);Documents docs=app.GetDocuments();
    CComVariant Template(_T(""));
    CComVariant NewTemplate(false),DocumentType(0),Visible;
    docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);_Document doc=app.GetActiveDocument();   
    CComVariant FileName(_T("c:\\doc.doc")); //文件名
    CComVariant FileFormat(0);   
    CComVariant LockComments(false),Password(_T(""));
    CComVariant AddToRecentFiles(true),WritePassword(_T(""));
    CComVariant ReadOnlyRecommended(false),EmbedTrueTypeFonts(false);
    CComVariant SaveNativePictureFormat(false),SaveFormsData(false);
    CComVariant SaveAsAOCELetter(false);doc.SaveAs(&FileName,&FileFormat,&LockComments,&Password,
    &AddToRecentFiles,&WritePassword,&ReadOnlyRecommended,
    &EmbedTrueTypeFonts,&SaveNativePictureFormat,&SaveFormsData,
    &SaveAsAOCELetter,NULL,NULL,NULL,NULL,NULL);
    doc.ReleaseDispatch();
    docs.ReleaseDispatch();CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
    app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
    app.ReleaseDispatch();app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument); 
    app.ReleaseDispatch();报错:向占位程序传送了空的索引指针
      

  5.   

    我运行那个例子,用的是VS2005 和 office2007#include "CApplication.h"
    #include "CDocuments.h"
    #include "CSentences.h"
    #include "CDocument0.h"
    #include <atlbase.h>
    void CStep1Dlg::OnBnClickedOk()
    {
    CApplication app;
    app.CreateDispatch(_T("Word.Application"));
    app.put_Visible(TRUE); CDocuments docs = app.get_Documents();
    CComVariant Template(_T(""));
    CComVariant NewTemplate(false),DocumentType(0),Visible;
    docs.Add(&Template,&NewTemplate,&DocumentType,&Visible); CSentences sel = app.get_Selection();
    sel.TypeText(_T("HELLO\r\n大家好呀")); AfxMessageBox(_T("好了,我要保存到c:\\hello.doc中了"));

    CDocument0 doc = app.get_ActiveDocument(); //得到ActiveDocument
    CComVariant FileName(_T("c:\\Hello.doc")); //文件名
    CComVariant FileFormat(0); //重点,看下面的说明
    CComVariant LockComments(false),Password(_T(""));
    CComVariant AddToRecentFiles(true),WritePassword(_T(""));
    CComVariant ReadOnlyRecommended(false),EmbedTrueTypeFonts(false);
    CComVariant SaveNativePictureFormat(false),SaveFormsData(false);
    CComVariant SaveAsAOCELetter(false);
    doc.SaveAs2000(&FileName,&FileFormat,&LockComments,&Password,
    &AddToRecentFiles,&WritePassword,&ReadOnlyRecommended,
    &EmbedTrueTypeFonts,&SaveNativePictureFormat,&SaveFormsData,&SaveAsAOCELetter);

    sel.ReleaseDispatch();
    doc.ReleaseDispatch();
    docs.ReleaseDispatch(); CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
    app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
    app.ReleaseDispatch();
    AfxMessageBox(_T("请检查c:\\hello.doc是否正常产生了。下面该学习Setp5了"));
    }