void CAboutDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CApplication App;
CDocument0 oDoc;
CDocuments oDocs;
CRange oRange;
CField oField;
CFields oFields;
CFont0 oFont;
CParagraph oPara;
CParagraphs oParas;
CSelection oSel; if(!App.CreateDispatch(_T("Word.Application")))
{
   AfxMessageBox(_T(" 你没有安装OFFICE!"));
   return;
}
else
{
App.put_Visible(TRUE);
App.put_WindowState(1);
}
COleVariant covTrue((short)TRUE);
COleVariant covFalse((short)FALSE);
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
/*VARIANT covTrue;
VARIANT covFalse;
VARIANT covOptional;
VariantInit(&covOptional);
covOptional.vt=VT_ERROR;
covOptional.scode=DISP_E_PARAMNOTFOUND;
*/
LPDISPATCH pDocs=App.get_Documents();
oDocs.AttachDispatch(pDocs);
// oDocs.AttachDispatch(App.get_Documents());
// oDoc.AttachDispatch(oDocs.Add(&covOptional,&covOptional,&covOptional,&covOptional));
LPDISPATCH pDoc=oDocs.Add(&covOptional,&covOptional,&covOptional,&covOptional);
oDoc.AttachDispatch(pDoc);
oSel.TypeText("轮式起重即桁架式臂架设计说明书");
oSel.TypeParagraph();
oSel.TypeText("太原科技大学");
oSel.TypeParagraph();
// oParas=oDoc.get_Paragraphs();
oParas.AttachDispatch(oDoc.get_Paragraphs());
oPara=oParas.Item(1);
oParas.put_Alignment(1);
// oFont=oRange.get_Font();
oFont.AttachDispatch(oRange.get_Font());
oFont.put_Size(14);
oFont.put_Color(250);
oFont.put_Bold(1);
oRange.put_Font(oFont);COleVariant vTime("yyyy-MM-dd:dddd");
oSel.InsertDateTime(vTime,&covFalse,&covOptional,&covOptional,&covOptional);
CnlineShapes inlineshapes;
//oRange=oSel.get_Range();
oRange.AttachDispatch(oSel.get_Range());
//inlineshapes=oRange.get_InlineShapes();
inlineshapes.AttachDispatch(oRange.get_InlineShapes());
COleVariant vRange;
vRange.vt=VT_DISPATCH;
vRange.pdispVal = oRange.m_lpDispatch;
oRange.ReleaseDispatch();
//inlineshapes.AddPicture("D:\\Picture.bmp",&covFalse,&covTrue,&vRange);//inlineshapes = oDoc.get_InlineShapes();
inlineshapes.AttachDispatch(oDoc.get_InlineShapes());
CnlineShape inlineshape;
inlineshape = inlineshapes.Item(1);
CShape oshape1= inlineshape.ConvertToShape();
oshape1.put_Width(165);
oshape1.put_Height(165);
oshape1.ConvertToInlineShape();//oRange = oSel.get_Range();
oRange.AttachDispatch(oSel.get_Range());
//CTables0 tabs = oDoc.get_Tables();
CTables0 tabs;
tabs.AttachDispatch(oDoc.get_Tables());
CTable0 tab;
tab.AttachDispatch(tabs.Add(oRange,9,6,&covFalse,&covTrue));
//CBorders oborders= tab.get_Borders();
CBorders oborders;
oborders.AttachDispatch(tab.get_Borders());
oborders.put_Enable(1);
CCells oCells;
//oCells = oRange.get_Cells();
oCells.AttachDispatch(oRange.get_Cells());
oCells.put_VerticalAlignment(1);
CRows oRows;
//oRows = tab.get_Rows();
oRows.AttachDispatch(tab.get_Rows());
CRow oRow;
oRow = oRows.Item(1);
//oRange = oRow.get_Range();
oRange.AttachDispatch(oRow.get_Range());
//oCells = oRange.get_Cells();
oCells.AttachDispatch(oRange.get_Cells());
oCells.Merge();
CCell oCell;
oCell = tab.Cell(2,1);
oCell.Merge(tab.Cell(3,1));
//tabs = oDoc.get_Tables();
tabs.AttachDispatch(oDoc.get_Tables());
tab = tabs.Item(1);
oCell = tab.Cell(1,1);
//oRange = oCell.get_Range();
oRange.AttachDispatch(oCell.get_Range());
oRange.InsertAfter("原始参数");
oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
oSel.MoveDown(COleVariant((short)5),&covOptional,&covOptional);
COleVariant vUnit((short)5);
COleVariant vCount((short)3);
oSel.Move(&vUnit,&vCount);
COleVariant vEnd((short)5);
COleVariant vOpt((short)5);
oSel.EndKey(&vEnd,&vOpt);//oFields = oSel.get_Fields();
oFields.AttachDispatch(oSel.get_Fields());
COleVariant oFontName;
oSel.InsertSymbol(945,oFontName,&covTrue,&covOptional);//Text = "EQ \s \do4(q)";
//oFields.Add(oRange,covOptional,Text,covFalse);
//Text = "EQ L=\f(A,cosθ) = \f(14,cos45)";
//oFields.Add(oRange,covOptional,Text,covFalse);
//Text = "";oSel.InsertBreak(&covOptional);
CWindow0 oWind;
//oWind = oDoc.get_ActiveWindow();
oWind.AttachDispatch(oDoc.get_ActiveWindow());
//CPane oPane;
//oPane = oWind.get_ActivePane();
CView0 oView;
//oView = oPane.g;
oView.put_SeekView(9);
oSel.TypeText("太原科技大学");
oView.put_SeekView(10);
oSel.TypeText("轮式起重机产品设计说明书");
oView.put_SeekView(0);
//oDoc = App.get_ActiveDocument();
oDoc.AttachDispatch(App.get_ActiveDocument());
//CPageSetup oPageSetup = oDoc.get_PageSetup();
CPageSetup oPageSetup;
oPageSetup.AttachDispatch(oDoc.get_PageSetup());
oPageSetup.put_TopMargin((float)56);
oPageSetup.put_BottomMargin((float)56.7);
oPageSetup.put_LeftMargin((float)56.7);
oPageSetup.put_RightMargin((float)56.7);COleVariant filenamepath("D:\\轮式起重机产品设计说明书.doc");oDoc.SaveAs(filenamepath,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional);
//oDoc.PrintOut();
oDoc.Close(&covFalse,&covOptional,&covOptional);
App.Quit(&covFalse,&covOptional,&covTrue);App.ReleaseDispatch();
oDocs.ReleaseDispatch(); 
oDoc.ReleaseDispatch(); 
oRange.ReleaseDispatch(); 
oFont.ReleaseDispatch();
oFields.ReleaseDispatch();
oField.ReleaseDispatch();
oParas.ReleaseDispatch();
oPara.ReleaseDispatch();
oSel.ReleaseDispatch();
oPageSetup.ReleaseDispatch();
oView.ReleaseDispatch();
oWind.ReleaseDispatch();
oCell.ReleaseDispatch();
oCells.ReleaseDispatch();
oRow.ReleaseDispatch();
tabs.ReleaseDispatch();
tab.ReleaseDispatch();
inlineshape.ReleaseDispatch();
inlineshapes.ReleaseDispatch();
oshape1.ReleaseDispatch();
oborders.ReleaseDispatch();}
老是出现 0x578ae9d0 (mfc90d.dll) 处未处理的异常: 0xC0000005: 读取位置 0xcccccccc 时发生访问冲突 的错误提示。
让后就定位到oledisp2.cpp 的m_lpDispatch 没有值什么的
怎么折腾也弄不好 还是按着别人的教程做的。
我是新手 对AttachDispatch的用法不了解,再有COleVariant和VARIANT的区别也很难理解。望高手帮着看看。

解决方案 »

  1.   

    而下边这个我可以通过的好好的 
    void CAboutDlg::OnBnClickedButton1()
    {
    // TODO: 在此添加控件通知处理程序代码CString strField[8],strTop;
    strField[0]="商品编号";
    strField[1]="商品名称";
    strField[2]="现有数量";
    strField[3]="价    格";
    strField[4]="采购数量";
    strField[5]="采购价格";
    strField[6]="供应商";
    strField[7]="计划采购时间";CString Title="计划采购信息";CWaitCursor wait;
    CApplication wordApp;
    CDocument0 wordDoc;
    CDocuments wordDocs;
    if(!wordApp.CreateDispatch("word.Application"))
    {
       AfxMessageBox("Failed!");
       return;
    }
    LPDISPATCH pDocs=wordApp.get_Documents();
    wordDocs.AttachDispatch(pDocs);
    VARIANT varUnit;
    VARIANT varOptional;
    VariantInit(&varUnit);
    varUnit.vt=VT_I4;
    varUnit.lVal=5;
    //
    VariantInit(&varOptional);
    varOptional.vt=VT_ERROR;
    varOptional.scode=DISP_E_PARAMNOTFOUND;
    //
    LPDISPATCH pDoc=wordDocs.Add(&varOptional,&varOptional,&varOptional,&varOptional);
    wordDoc.AttachDispatch(pDoc);long nRows,nCols;
    nRows=8;
    nCols=8;
    //
    CRange wordRange;
    wordRange=wordDoc.Range(&varOptional,&varOptional);
    //
    CSelection wordSelec=wordApp.get_Selection();
    CFont0 oFont;
    CParagraphFormat wordFormat;//标题
    wordSelec.HomeKey(&varUnit,&varOptional);oFont=wordSelec.get_Font();
    oFont.put_Size(12);
    oFont.put_Name("宋体");
    wordFormat=wordSelec.get_ParagraphFormat();
    wordFormat.put_Alignment(1);
    wordSelec.InsertAfter(LPCSTR(Title));
    wordSelec.InsertParagraphAfter();oFont.put_Size(16);
    oFont.put_Name("黑体");
    wordFormat=wordSelec.get_ParagraphFormat();
    wordFormat.put_Alignment(1);
    wordSelec.InsertAfter(LPCSTR(strTop));
    wordSelec.InsertParagraphAfter();wordSelec.EndKey(&varUnit,&varOptional);//设置表格
    wordRange=wordSelec.get_Range();
    oFont=wordSelec.get_Font();
    oFont.put_Size(10);
    oFont.put_Name("宋体");
    wordFormat=wordSelec.get_ParagraphFormat();
    wordFormat.put_Alignment(1);VARIANT varTable;
    VariantInit(&varTable);
    varUnit.vt=VT_I4;
    varUnit.lVal=0;
    //
    CTables0 wordTables=wordSelec.get_Tables();
    CTable0 wordTable=wordTables.Add(wordRange,nRows,nCols,&varOptional,&varTable);
    //
    CBorders tblBorders;
    tblBorders=wordTable.get_Borders();
    tblBorders.put_InsideLineStyle(1);
    tblBorders.put_OutsideLineStyle(7);
    //
    CColumns0 tblColumns;
    tblColumns=wordTable.get_Columns();
    tblColumns.get_PreferredWidthType();
    //
    int i,j,n;
    char buf[50];
    CString strValue;
    CCell tblCell;for(i=1;i<=nRows;i++)
    {
       for(j=1;j<=nCols;j++)
       {
        if(i==1)
        {
         tblCell=wordTable.Cell(i,j);
         wordRange=tblCell.get_Range();
         oFont=wordRange.get_Font();
         oFont.put_Name("黑体");
         n=j-1;
         strValue=strField[n];
         wordRange.InsertAfter(strValue);
        }
        else
        {
         tblCell=wordTable.Cell(i,j);
         wordRange=tblCell.get_Range();
         n=j-1;
         if(n==0 || n==1 || n==6)
         {
             strValue="016";
         }
         if(n==2 || n==3 || n==4 ||n==5)
         {  
          strValue="2345";
         }
         if(n==7)
         {
          strValue="7";
         }
         //strValue.TrimRight();
         wordRange.InsertAfter(strValue);
        }
       }}
    wordApp.put_Visible(true);
    wordDoc.Activate();
    }
      

  2.   

    这是我做的过程
    (1)创建(或打开已有的)一个 MFC 的程序工程。
    (2)执行 项目-->Add Class-->From a type Library--> 在 Office 目录中,找到你想使用的类型库。现使用的是 Office2003,其Word 的类型库文件,保存在 c:\Program Files\Microsoft Office\Office11\MSWORD.OLB。(3)选择类型库文件后,在弹出的对话窗中继续选择要添加的类。我们现在添加——Application,Documents,Document,Range,Borders, Font,ParagraphFormat,Selection,Table,Tables,Columns,Cell。这时候会在项目中添加N多类。CApplication类对应Application对象,获取WordApplication对象,可以控制word的显示,例如显示打印预览,状态栏是否可见等CDocument0类对应Document对象,打开或者创建一个word文件时,Document对象就产生了。CDocuments类对应Documents对象这是一个Document对象的集合。操作多个word时需要。CRange类对应Range对象,该对象用于操作word中的一块区域,Range对象代表word中一块连续的区域,有起始位置和结束位, VC中用COleVarian对象的intVal属性表示起始位和结束位。put_Text向该区域中写入文字。CTables0类对应表格对象,还有Column,Row,Cell对象。(4)初始化COM。方法一,找到App的InitInstance()函数,在其中添加 AfxOleInit()函数的调用;方法二,在需要调用COM功能的地方 CoInitialize(NULL),调用完毕后 CoUninitialize()。
    (5)在你需要调用 Office 功能函数的 cpp 文件中
         #include <atlbase.h>  // 为了方便操作 VARIANT 类型变量,使用 CComVariant 模板类
        #include "CApplication.h"    #include "CDocuments.h"
        #include "CDocument0.h"
        #include "CRange.h"
        #include "CBorders.h"
        #include "CFont0.h"
        #include "CParagraphFormat.h"
        #include "CSelection.h"
        #include "CTable0.h"
        #include "CTables0.h"
        #include "CColumns0.h"
        #include "CCell.h"  // 具体的头文件名,是由装载类型库的文件名决定的。在每个新加的office头文件中,即上边这些头文件中("CApplication.h","CDocuments.h",,"CDocument0.h", "CRange.h", "CBorders.h", "CFont0.h", "CParagraphFormat.h","CSelection.h", "CTable0.h", "CTables0.h", "CColumns0.h","CCell.h")将"c:\Program Files\Microsoft Office\Office11\MSWORD.OLB"  no_namespace 替换为#import "C:\\Program Files\\Microsoft Office\\OFFICE11\\MSWORD.OLB" no_namespace     raw_interfaces_only \
    rename("FindText","_FindText")       \
    rename("Rectangle","_Rectangle")   \
    rename("ExitWindows","_ExitWindows")(6)好了,现在开始写程序吧。另外要说明的是,步骤2和3,其实也可以使用 #import 方式引入类型库。新建一个对话框程序,建一按钮添加如下代码
     CString strField[8],strTop;
    strField[0]="商品编号";
    strField[1]="商品名称";
    strField[2]="现有数量";
    strField[3]="价    格";
    strField[4]="采购数量";
    strField[5]="采购价格";
    strField[6]="供应商";
    strField[7]="计划采购时间";CString Title="计划采购信息";CWaitCursor wait;
    CApplication wordApp;
    CDocument0 wordDoc;
    CDocuments wordDocs;
    if(!wordApp.CreateDispatch("word.Application"))
    {
       AfxMessageBox("Failed!");
       return;
    }
    LPDISPATCH pDocs=wordApp.get_Documents();
    wordDocs.AttachDispatch(pDocs);
    VARIANT varUnit;
    VARIANT varOptional;
    VariantInit(&varUnit);
    varUnit.vt=VT_I4;
    varUnit.lVal=5;
    //
    VariantInit(&varOptional);
    varOptional.vt=VT_ERROR;
    varOptional.scode=DISP_E_PARAMNOTFOUND;
    //
    LPDISPATCH pDoc=wordDocs.Add(&varOptional,&varOptional,&varOptional,&varOptional);
    wordDoc.AttachDispatch(pDoc);long nRows,nCols;
    nRows=8;
    nCols=8;
    //
    CRange wordRange;
    wordRange=wordDoc.Range(&varOptional,&varOptional);
    //
    CSelection wordSelec=wordApp.get_Selection();
    CFont0 oFont;
    CParagraphFormat wordFormat;//标题
    wordSelec.HomeKey(&varUnit,&varOptional);oFont=wordSelec.get_Font();
    oFont.put_Size(12);
    oFont.put_Name("宋体");
    wordFormat=wordSelec.get_ParagraphFormat();
    wordFormat.put_Alignment(1);
    wordSelec.InsertAfter(LPCSTR(Title));
    wordSelec.InsertParagraphAfter();oFont.put_Size(16);
    oFont.put_Name("黑体");
    wordFormat=wordSelec.get_ParagraphFormat();
    wordFormat.put_Alignment(1);
    wordSelec.InsertAfter(LPCSTR(strTop));
    wordSelec.InsertParagraphAfter();wordSelec.EndKey(&varUnit,&varOptional);//设置表格
    wordRange=wordSelec.get_Range();
    oFont=wordSelec.get_Font();
    oFont.put_Size(10);
    oFont.put_Name("宋体");
    wordFormat=wordSelec.get_ParagraphFormat();
    wordFormat.put_Alignment(1);VARIANT varTable;
    VariantInit(&varTable);
    varUnit.vt=VT_I4;
    varUnit.lVal=0;
    //
    CTables0 wordTables=wordSelec.get_Tables();
    CTable0 wordTable=wordTables.Add(wordRange,nRows,nCols,&varOptional,&varTable);
    //
    CBorders tblBorders;
    tblBorders=wordTable.get_Borders();
    tblBorders.put_InsideLineStyle(1);
    tblBorders.put_OutsideLineStyle(7);
    //
    CColumns0 tblColumns;
    tblColumns=wordTable.get_Columns();
    tblColumns.get_PreferredWidthType();
    //
    int i,j,n;
    char buf[50];
    CString strValue;
    CCell tblCell;for(i=1;i<=nRows;i++)
    {
       for(j=1;j<=nCols;j++)
       {
        if(i==1)
        {
         tblCell=wordTable.Cell(i,j);
         wordRange=tblCell.get_Range();
         oFont=wordRange.get_Font();
         oFont.put_Name("黑体");
         n=j-1;
         strValue=strField[n];
         wordRange.InsertAfter(strValue);
        }
        else
        {
         tblCell=wordTable.Cell(i,j);
         wordRange=tblCell.get_Range();
         n=j-1;
         if(n==0 || n==1 || n==6)
         {
             strValue="016";
         }
         if(n==2 || n==3 || n==4 ||n==5)
         { 
          strValue="2345";
         }
         if(n==7)
         {
          strValue="7";
         }
         //strValue.TrimRight();
         wordRange.InsertAfter(strValue);
        }
       }}
    wordApp.put_Visible(true);
    wordDoc.Activate();http://blog.sina.com.cn/s/blog_412535a20100jsc4.html
      

  3.   

    CApplication App;
    CDocument0 oDoc;
    CDocuments oDocs;
    CRange oRange;
    CField oField;
    CFields oFields;
    CFont0 oFont;
    CParagraph oPara;
    CParagraphs oParas;
    CSelection oSel; if(!App.CreateDispatch(_T("Word.Application")))
    {
       AfxMessageBox(_T(" 你没有安装OFFICE!"));
       return;
    }
    else
    {
    App.put_Visible(TRUE);
    App.put_WindowState(1);
    }
    COleVariant covTrue((short)TRUE);
    COleVariant covFalse((short)FALSE);
    COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
    CComVariant tpl(_T("D:\\11.doc")), NewTemplate(false), DocType(0), Visble;
    oDocs.AttachDispatch(App.get_Documents()); oDoc.AttachDispatch(oDocs.Add(&tpl,&NewTemplate,&DocType,&Visble));
    oSel = App.get_Selection();
    oSel.TypeText("轮式起重即桁架式臂架设计说明书");
    oSel.TypeParagraph();
    oSel.TypeText("太原科技大学");
    oSel.TypeParagraph(); oParas.AttachDispatch(oDoc.get_Paragraphs());
    oPara=oParas.Item(1);
    oParas.put_Alignment(1); oRange = oPara.get_Range();
    oFont.AttachDispatch(oRange.get_Font());
    oFont.put_Size(14);
    oFont.put_Color(250);
    oFont.put_Bold(1);
    oRange.put_Font(oFont); COleVariant vTime("yyyy-MM-dd:dddd");
    oSel.InsertDateTime(vTime,&covFalse,&covOptional,&covOptional,&covOptional);
    CnlineShapes inlineshapes; oRange.AttachDispatch(oSel.get_Range());
    inlineshapes=oRange.get_InlineShapes(); inlineshapes.AttachDispatch(oRange.get_InlineShapes()); COleVariant vRange;
    vRange.vt=VT_DISPATCH;
    vRange.pdispVal = oRange.m_lpDispatch;
    vRange.pdispVal->AddRef();inlineshapes.AddPicture("D:\\1.jpg",&covFalse,&covTrue,&vRange);
    inlineshapes = oDoc.get_InlineShapes();
    inlineshapes.AttachDispatch(oDoc.get_InlineShapes());
    CnlineShape inlineshape;
    inlineshape = inlineshapes.Item(1);
    CShape oshape1= inlineshape.ConvertToShape();
    oshape1.put_Width(165);
    oshape1.put_Height(165);
    oshape1.ConvertToInlineShape();
    oRange.AttachDispatch(oSel.get_Range());
    CTables0 tabs;
    tabs.AttachDispatch(oDoc.get_Tables());
    CTable0 tab;
    tab.AttachDispatch(tabs.Add(oRange,9,6,&covFalse,&covTrue));
    CBorders oborders;
    oborders.AttachDispatch(tab.get_Borders());
    oborders.put_Enable(1);
    oRange = tab.get_Range(); 
    CCells oCells;
    oCells.AttachDispatch(oRange.get_Cells());
    oCells.put_VerticalAlignment(1);
    CRows oRows;
    oRows.AttachDispatch(tab.get_Rows());
    CRow oRow;
    oRow = oRows.Item(1);
    oRange.AttachDispatch(oRow.get_Range());
    oCells.AttachDispatch(oRange.get_Cells());
    oCells.Merge();
    CCell oCell;
    oCell = tab.Cell(2,1);
    oCell.Merge(tab.Cell(3,1));
    tabs.AttachDispatch(oDoc.get_Tables());
    tab = tabs.Item(1);
    oCell = tab.Cell(1,1);
    oRange.AttachDispatch(oCell.get_Range());
    oRange.InsertAfter("原始参数");
    oSel.MoveRight(COleVariant((short)1),COleVariant((short)1),COleVariant((short)0));
    oSel.MoveDown(COleVariant((short)5),&covOptional,&covOptional);
    COleVariant vUnit((short)5);
    COleVariant vCount((short)3);
    oSel.Move(&vUnit,&vCount);
    COleVariant vEnd((short)5);
    COleVariant vOpt((short)5);
    oSel.EndKey(&vEnd,&vOpt);oFields = oSel.get_Fields();
    oFields.AttachDispatch(oSel.get_Fields());
    oSel.InsertBreak(&covOptional);
    CWindow0 oWind;
    oWind.AttachDispatch(oDoc.get_ActiveWindow());
    CPane0 oPane;
    oPane.AttachDispatch(oWind.get_ActivePane());
    CView0 oView;
    oView.AttachDispatch(oPane.get_View());
    oView.put_SeekView(9);oSel.TypeText("太原科技大学");
    oView.put_SeekView(10);
    oSel.TypeText("轮式起重机产品设计说明书");
    oView.put_SeekView(0);
    oDoc.AttachDispatch(App.get_ActiveDocument());
    CPageSetup oPageSetup;
    oPageSetup.AttachDispatch(oDoc.get_PageSetup());oPageSetup.put_TopMargin((float)56.7);
    oPageSetup.put_BottomMargin((float)56.7);
    oPageSetup.put_LeftMargin((float)56.7);
    oPageSetup.put_RightMargin((float)56.7);
    COleVariant filenamepath("D:\\轮式起重机产品设计说明书.doc");
    oDoc.SaveAs(filenamepath,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional,&covOptional);
    oDoc.Close(&covFalse,&covOptional,&covOptional);
    App.Quit(&covFalse,&covOptional,&covTrue);App.ReleaseDispatch();
    oDocs.ReleaseDispatch(); 
    oDoc.ReleaseDispatch(); 
    oRange.ReleaseDispatch(); 
    oFont.ReleaseDispatch();
    oFields.ReleaseDispatch();
    oField.ReleaseDispatch();
    oParas.ReleaseDispatch();
    oPara.ReleaseDispatch();
    oSel.ReleaseDispatch();
    oPageSetup.ReleaseDispatch();
    oView.ReleaseDispatch();
    oWind.ReleaseDispatch();
    oCell.ReleaseDispatch();
    oCells.ReleaseDispatch();
    oRow.ReleaseDispatch();
    tabs.ReleaseDispatch();
    tab.ReleaseDispatch();
    inlineshape.ReleaseDispatch();
    inlineshapes.ReleaseDispatch();
    oshape1.ReleaseDispatch();
    oborders.ReleaseDispatch();CoUninitialize();