代码如下:
C#
        int iCount;
        for (int idr = 0; idr < drs.Count; idr++)
        {
            iCount = idr + 1;
            count = 0;
            wordApp.Selection.MoveLeft(ref unit, ref count, ref extend);
            //
            wordApp.Selection.TypeText(iCount.ToString());
            for (int idbField = 0; idbField < db.FieldNames.Length; idbField++)
            {
                // 
                count = 1;
                wordApp.Selection.Move(ref unit, ref count);
                string text = db.FieldNames[idbField];
                wordApp.Selection.TypeText(text);
            }
            // 插入新的记录行
            wordApp.Selection.InsertRowsBelow(ref extend);
        }在指定位置插入表格,db.FieldNames.Length 列;drs.Count行,请问在VC中如何实现,

解决方案 »

  1.   

    db.FieldNames.Length 和 drs.Count是数据库访问函数,和Word操作没有关系。
    你直接用ADO来访问库就行了。
      

  2.   

    个人感觉C#要迁移到VC,基本上要完全重写。
      

  3.   


      _Application   app;   
      app.CreateDispatch(_T("Word.Application"));   
      app.SetVisible(TRUE);   
        
      Documents   docs=app.GetDocuments();   
      CComVariant   Template(_T("")); //不使用WORD的文档模板   
      CComVariant   NewTemplate(false),DocumentType(0),Visible;   
      _Document   doc   =   docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);   
        
                    //绘制5*6的表格   
      CComVariant   vFalse(false),vTrue(true);   
      Tables   tables   =   doc.GetTables();   
      _Table   table   =   tables.Add(sel.GetRange(),5,6,&vTrue,&vFalse);   
                    //往表格填充文字   
                  ....................   
                    //释放资源   
                      table.ReleaseDispatch();   
      tables.ReleaseDispatch();   
      doc.ReleaseDispatch();   
      docs.ReleaseDispatch();   
        
      CComVariant   SaveChanges(false),OriginalFormat,RouteDocument;   
      app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);   
      app.ReleaseDispatch();   
      

  4.   

    vc中操作word,要用word的Com接口等来操作...Word.Application
      

  5.   

    for (i =0; i < nIndex; i++)
    {
    iCount = i + 1;
    count->intVal = 0;
    spApp->Selection->MoveLeft(COleVariant("1"),COleVariant("3"),COleVariant("3")); 
    // 得到记录行数
    int nIndexF = 5;
    int j=0;
    for (j =0; j < nIndexF; j++)
    {
    gridHF[j] = fields.GetAt(j);
    count->intVal = 1;
                    spApp->Selection->Move(unit, count);
                    spApp->Selection->TypeText((_bstr_t)gridHF[j]);
    }
    // 插入新的记录行
    spApp->Selection->InsertRowsBelow(extend);
    }我按照C#格式改写了,程序不能运行,各位我写的那理由问题,请指出来,不胜感激
      

  6.   

    调用WORD的COM对象,建议你去学习下相关的知识
      

  7.   

      _Table   table   =   tables.Add(sel.GetRange(),5,6,&vTrue,&vFalse);  这句话有错 ,我用的是WORD2003,是这两个&vTrue,&vFalse参数有错,郁闷