在office 文档里面这个问题是这样的,当你不是使用自定义模板的时候默认的是normal.dot,你可以使用normal.dot来使用,你不使用模板不可能的在模板为空的时候使用的是normal.dot

解决方案 »

  1.   

    你想呀,每次要新建一个WORD文档,都要带上normal.dot这个文件,不是很烦吗,对分发也不利
      

  2.   

    你想呀,每次要新建一个WORD文档,都要带上normal.dot这个文件,不是很烦吗,对分发也不利
      

  3.   

    //Create a new document
    Documents oDocs;
    _Document oDoc;
    oDocs = oWordApp.GetDocuments();
    //Add a new document
    oDoc = oDocs.Add(vOpt, vOpt);  
    //Note for Word 2000: The Add method has 4 arguments in Word 2000.  If 
    //you wrapped the classes from the Word type library (msword9.olb),
    //modify the Add method to provide 4 optional arguments:
    //    oDoc = oDocs.Add(vOpt, vOpt, vOpt, vOpt);
      

  4.   

    我好像用不上tangtang800620(唐唐) 的方法,因为我要实例COleDocObjectItem对象
      

  5.   

    HRESULT              hr;
    CString FileName,LoadFile,SaveFile,SaveFileName,Temp1;
    CHAR      FilePath[255];
    // BSTR TEMP1;
    VARIANT     Temp;
    COleVariant  TEMP2;
    CTime NowTime;
    hr=CoInitialize(NULL);
    // TEMP1="E:\\练习\\OFFICE\\OpenOffice\\12月6日工作日志.doc";
    // wcscat((BSTR)TEMP1,OLESTR("\\开发人员工作日志模板.dot"));

    Word::_ApplicationPtr MyOffice("Word.Application.9");
    ::GetCurrentDirectory(255,FilePath); 
    FileName.Format("%s",FilePath); 
    LoadFile=FileName+"\\开发人员工作日志模板.dot";
    TEMP2=(COleVariant)LoadFile;
    Temp=TEMP2.Detach(); 
    if (MyOffice) {
    // hr=MyOffice->Documents->Open(&Temp); 
    hr=MyOffice->Documents->Add(&Temp);
    //hr=MyOffice->ActiveDocument->Activate();
    //hr=MyOffice->ActiveWindow->put_Visible(VARIANT_BOOL(TRUE)); //显示word窗口
    //这中间你可以添加其他你要处理的功能
    if(FAILED(hr))
    {
    ::AfxMessageBox("文件打开显示错误");
    MyOffice->Quit();
    }
    NowTime=CTime::GetCurrentTime();  
    Temp1=NowTime.Format("%m月%d") ; 
    SaveFileName=Temp1+"日工作日志.doc";  
    SaveFile=FileName+"\\"+SaveFileName;
    TEMP2.Clear(); 
    TEMP2=(COleVariant)SaveFile;
    Temp=TEMP2.Detach(); 
    TEMP2.Clear();
    hr=MyOffice->ActiveDocument->SaveAs(&Temp);  
    // hr=MyOffice->Documents->Save(&Temp); //错误原因:保存文件如果是Documents是全保存 所以应该使用ActiveDocument
    if(FAILED(hr))
    {
    ::AfxMessageBox("文件保存失败");
    MyOffice->ActiveWindow->put_Visible(VARIANT_BOOL(TRUE));
    }
    ::AfxMessageBox("文件保存成功!");
    MyOffice->Quit();
    }
    // MyOffice->Quit();
    // MyOffice->Release(); 
    return 0;