|
cbuilder 초보입니다.. 엑셀에 데이터를 집어 넣으려 하는데...
아는데로 한번 해보았는데 잘못된 것이 있으면
지적(?)해 주시면 감사하겠습니다...
void __fastcall TForm1::Buttons(TObject * Sender)
{
String Filename;
Filename = ExtractFilePath(Application->ExeName) + "RptXL\\App.xls";
XLApp = CreateOleObject("Excel.Application");
XLApp.WorkBooksOpen(Filename);
XLApp.OlePropertySet("Visible", true);
xlWorkBooks = XLApp.OlePropertyGet("WorkBooks");
xlWorkBooks.OleProcedure("Open",Filename);
XLApp.OlePropertySet("Visible", false);
xlWorkBook = xlWorkBooks.OlePropertyGet("Item",1);
xlWorkSheets = xlWorkBook.OlePropertyGet("WorkSheets");
xlWorkSheet = xlSheets.OlePropertyGet("Item",1);
insertdata();
xlWorkSheet.PrintOut(); (??)
}
void __fastcall TForm1::insertdata()
{
Variant Sheet; int i,j;
xlWorkBook = xlWorkBooks.OlePropertyGet("Item",1);
xlWorkSheets = xlWorkBook.OlePropertyGet("WorkSheets");
Sheet = xlSheets.OlePropertyGet("Item",1);
Query1->SQL->Clear();
Query1->SQL->Add("Select name,id,address,phone from Member")
Query1->Open();
for(i=0; i<Query1->RecordCount; i++ ){
j=i+1;
Sheet.Cells[j][1]=Query1->FieldByName("name")->AsString;
Sheet.Cells[j][2]=Query1->FieldByName("id")->AsString;
Sheet.Cells[j][3]=Query1->FieldByName("address")->AsString;
Sheet.Cells[j][4]=Query1->FieldByName("phone")->AsString;
} }
ps. 혹시 씨빌더에서 OLE에 관한 자료(엑셀)이 있으시면...여기에??나 어디에..
올려주시면 감사하겠습니다..
|