主题:[讨论]关于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();
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();