在vc中怎么样在word中写入东西?(比如access表中的数据,按照行列写到word中)
谢谢!

解决方案 »

  1.   

    这个简单
    打开doc文件,按它的格式写就可以了
      

  2.   

    不行,我以为是rtf格式……
      

  3.   

    //automation word 
    void CReportDemoDlg::OnStartword() 
    {
    Table table;
    Tables tables;
    if (!WordApp.CreateDispatch("Word.Application",NULL)) 

    AfxMessageBox("创建MS-WORD服务失败!"); 
    exit(1); 
    } ;

    WordApp.SetVisible(true);
    docs=WordApp.GetDocuments(); 
    COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
    COleVariant start_line,end_line;
    COleVariant Dot("c:\\test.dot");
    //使用test.dot作为模板建立新文档
    doc=docs.Add(&Dot,&covOptional);
    //获得DOC文档的书签集
    boots=doc.GetBooks();
    //第一到三列的的书签名分别是rol1、rol2、rol3
    COleVariant tem1("rol1");
    boot=boots.Item(&tem1);
    range=boot.GetRange();
    //设置列标题
    range.SetText("列标题1");
    COleVariant tem2("rol2");
    boot=boots.Item(&tem2);
    range=boot.GetRange();
    range.SetText("列标题2");
    COleVariant tem3("rol3");
    boot=boots.Item(&tem3);
    range=boot.GetRange();
    range.SetText("列标题3");
    //设置报表报送时间
    COleVariant tem4("time");
    boot=boots.Item(&tem4);
    range=boot.GetRange();
    range.SetText("2002年1月1日");
    //设置单元格内容
    tables=doc.GetTables();
    table=tables.Item(1);
    Cell cell;
    for(int i=2;i<=9;i++)
    {
    for(int ii=1;ii<=3;ii++)
    {
    cell=table.Cell(i,ii);
    range=cell.GetRange();
    range.SetText("????");
    }
    }
    }