C++ Builder
| Главная | Уроки | Статьи | FAQ | Форум | Downloads | Литература | Ссылки | RXLib | Диски |

 
Word, добавление строк в таблицу
Savl
Отправлено: 11.06.2004, 20:10


Ученик-кочегар

Группа: Участник
Сообщений: 3



Подскажите почему данный код при выполнении выдает ошибку в последней строке:
AnsiString path;
path="C:\\Shet";
WD=CreateOleObject("Word.Application.10");
WD.OlePropertyGet("Documents").OleProcedure("Open",path.c_str());
WD.OlePropertySet("Visible",true);
a=WD.OlePropertyGet("Documents");
b=a.OleFunction("Item",1);
a=b.OlePropertyGet("Tables").OleFunction("Item",1);
b=a.OlePropertyGet("Rows").OleFunction("Item",1);
MDM
Отправлено: 21.06.2004, 09:09


Не зарегистрирован







QUOTE (Savl @ 11/06/2004, 21:12)
Подскажите почему данный код при выполнении выдает ошибку в последней строке:

b=a.OlePropertyGet("Rows").OleFunction("Item",1);

Уточни какую ошибку, а пока вот рабочий код:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant Word, Document, Table, Cell;
int RowCount, ColCount;

Word = CreateOleObject("Word.Application.8");
Word.OlePropertySet("Visible", true);
Word.OlePropertyGet("Documents").OleProcedure("Add");
Document = Word.OlePropertyGet("Documents").OleFunction("Item", 1);
Table = Document.OlePropertyGet("Tables").OleFunction("Add", Document.OleFunction("Range", 0, 0), 5, 5);
RowCount = Table.OlePropertyGet("Rows").OlePropertyGet("Count");
ColCount = Table.OlePropertyGet("Columns").OlePropertyGet("Count");
for (int i=1; i <=RowCount; i++)
for(int j=1; j <=ColCount; j++) {
Cell = Table.OleFunction("Cell", i, j);
Cell.OlePropertyGet("Range").OleProcedure("InsertAfter", WideString(IntToStr(i)) + WideString("-") + WideString(IntToStr(j)));
}
Document.OleProcedure("SaveAs", ChangeFileExt(Application->ExeName, ".doc"));
Word.OleProcedure("Quit");
}

Вернуться в Технологии COM/DCOM, ActiveX