13,825
社区成员
发帖
与我相关
我的任务
分享
int TableCount = MSWord.OlePropertyGet("ActiveDocument").OlePropertyGet("Tables").OlePropertyGet("Count");
//ShowMessage(TableCount);文档中所有表格
for (int i = 1; i < TableCount+1; i++) {
vTable = MSWord.OlePropertyGet("ActiveDocument").OlePropertyGet("Tables").OleFunction("Item",i);
int RowsCount = vTable.OlePropertyGet("Rows").OlePropertyGet("Count");
ShowMessage(RowsCount); // 你所需要的行数
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant MSWord,vTable,RowsCell ;
try
{
MSWord=Variant::CreateObject("Word.Application");
}
catch(...)
{
MessageBox(0, "启动 Word 出错, 可能是没有安装Word.",
"提示", MB_OK | MB_ICONERROR);
MSWord = Unassigned;
return;
}
// 隐藏Word界面
MSWord.OlePropertySet("Visible", true);
MSWord.OlePropertyGet("Documents").OleProcedure("Open", "C:\\Doc2.doc");
// V1.OlePropertyGet("Selection").OleProcedure("WholeStory");
//OlePropertyGet("Words",1).OlePropertyGet("Text");
vTable = MSWord.OlePropertyGet("ActiveDocument").OlePropertyGet("Tables").OleFunction("Item",1);
int RowsCount = vTable.OlePropertyGet("Rows").OlePropertyGet("Count");
ShowMessage(RowsCount); // 你所需要的行数
/* int CellCountOfRow;
for(int i = 0;i < RowsCount;i++)
{
RowsCell = vTable.OlePropertyGet("Rows").OleFunction("Item",1);
CellCountOfRow = RowsCell.OlePropertyGet("Cells").OlePropertyGet("Count");
ShowMessage(CellCountOfRow);
} */
MSWord.OleFunction("Quit");
MSWord=Unassigned;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant MSWord,vTable,RowsCell ;
try
{
MSWord=Variant::CreateObject("Word.Application");
}
catch(...)
{
MessageBox(0, "启动 Word 出错, 可能是没有安装Word.",
"提示", MB_OK | MB_ICONERROR);
MSWord = Unassigned;
return;
}
// 隐藏Word界面
MSWord.OlePropertySet("Visible", true);
MSWord.OlePropertyGet("Documents").OleProcedure("Open", "C:\\Doc2.doc");
// V1.OlePropertyGet("Selection").OleProcedure("WholeStory");
//OlePropertyGet("Words",1).OlePropertyGet("Text");
vTable = MSWord.OlePropertyGet("ActiveDocument").OlePropertyGet("Tables").OleFunction("Item",1);
int RowsCount = vTable.OlePropertyGet("Rows").OlePropertyGet("Count");
ShowMessage(RowsCount); // 你所需要的行数
/* int CellCountOfRow;
for(int i = 0;i < RowsCount;i++)
{
RowsCell = vTable.OlePropertyGet("Rows").OleFunction("Item",1);
CellCountOfRow = RowsCell.OlePropertyGet("Cells").OlePropertyGet("Count");
ShowMessage(CellCountOfRow);
} */
MSWord.OleFunction("Quit");
MSWord=Unassigned;
}