Board index » cppbuilder » Creating a table in word document

Creating a table in word document


2005-08-09 03:46:37 PM
cppbuilder47
Hi All,
I want to create a table in a word document through my application.
I want to fill some data in this table.
Is there any way to create a word documnet with a table in it ?
Thanks,
Asawari.
 
 

Re:Creating a table in word document

"Elizabeth" < XXXX@XXXXX.COM >wrote:
Quote
Hi All,

I want to create a table in a word document through my application.
I want to fill some data in this table.
Is there any way to create a word documnet with a table in it ?

Thanks,
Asawari.

...
#include <utilcls.h>
#include <sysvari.h>
#include <ComObj.hpp>
...
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");
}