回 帖 发 新 帖 刷新版面

主题:[讨论]关于word表格读取的一段程序,谁能帮我详细的解释一下?

COleVariant aindex(short(1));
    aDoc = m_Docs.Item(aindex);
    Tables aTables = aDoc.GetTables();

    CString tableMessage;//输出的表格文本

    tableMessage = "!!!\r\n! Routing exercise Connection List\r\n !Uses default Example format";
    tableMessage += "!\r\n! unique_id, from_comp, from_conn,from_port,to_comp,to_conn,to_port,\r\n";
    tableMessage += "! gauge,type,color,length,cut_length,fabrication,description,od  \r\n! !\r\n";


    CString strtemp,strcell,strid,strfromconn,strfromport,strtoconn,strtoport;
    CString strgauge,strcolor,strtype,strfabrication,strdescript,strod;//临时读取单元格文本
    
    char achar;
    bool bempty=FALSE;
    BOOL bkong = FALSE;//本行为空
    int isame;
    Cell acell;
    try
    {

    //几个表格
    for (int tablepos = 1; tablepos <= aTables.GetCount(); tablepos++)
    {
        Table aTable = aTables.Item(tablepos);
        Columns acolumns;
        acolumns = aTable.GetColumns();
        Rows arows;
        arows = aTable.GetRows();

//行循环
    for (int rowpos = 1; rowpos <= arows.GetCount(); rowpos++ )
{。。。。。。。。。。。。。。。。。。。。}

//列循环
        for (int colpos = 2; colpos <= 10;  colpos++)//    acolumns.GetCount()    
{。。。。。。。。。。。。。。。。。。。。。。。。。}

if ( colpos == 1 )//读颜色
                {
            
                    strcolor = strcell;
                //    bempty = FALSE;
                }

if ( colpos == 2 )//读备注
                {
                    
                    strdescript = strcell;
                    bempty = FALSE;
                }
。。。。。。。。。。。。。。。。。。。。。。。。。。

if ((!bempty)&&(!bkong))
        {

            tableMessage += strid;
            tableMessage += ",";
            tableMessage += strfromconn;
            tableMessage += ",";
            tableMessage += strfromconn;
            tableMessage += ",";
            tableMessage += strfromport;
            tableMessage += ",";
            tableMessage += strtoconn;
            tableMessage += ",";
            tableMessage += strtoconn;
            tableMessage += ",";
            tableMessage += strtoport;
            tableMessage += ",";
            tableMessage += strgauge;
            tableMessage += ",";
            tableMessage += strtype;
            tableMessage += ",";
            tableMessage += strcolor;
            tableMessage += ",";
            tableMessage += ",";
            tableMessage += ",";
            tableMessage += ",";
            tableMessage += strdescript;
            tableMessage += ",";
            tableMessage += strod;
            tableMessage += "\t";                
            tableMessage += "\r\n";
            

        //    MessageBox(strid,"提示",MB_ICONEXCLAMATION);
        }

    }
    }
    }
    catch(CException *e) 
    {
        m_Docs.ReleaseDispatch();//断开关联;
        m_Sel.ReleaseDispatch();
        m_App.Quit(vOpt, vOpt, vOpt); 
        m_App.ReleaseDispatch();
        return false;
    }
    //MessageBox("写文本","提示",MB_ICONEXCLAMATION);
    
//创建文本文档
    CString savepath;
    savepath="D:\\buxian\\routing_dev\\ug_program\\application\\connect.hrn";


    CFile fil;//声明一个文件类对象

    fil.Open(savepath,CFile::modeCreate|CFile::modeWrite);//打开文件

    //CArchive ar(&fil,CArchive::store);//用指向fil的指针创建//CArchive类对象,store模式为存储,load为载入。


    fil.Write(tableMessage,strlen(tableMessage));
    //ar.Close();
    fil.Close();

    m_Docs.ReleaseDispatch();//断开关联;

    m_Sel.ReleaseDispatch();

回复列表 (共3个回复)

沙发

用Word的宏录制,然后你就知道了。

板凳

哪部分操作是用宏录制的,您能详细的帮我解释一下吗?谢谢了!

3 楼

你先点击“录制宏”
然后就按部就班的操作表格,基本就能知道表格操作接口了:)

我来回复

您尚未登录,请登录后再回复。点此登录或注册