Cell少了一個s~試試看~
![]()
還有你的>< face="Verdana, Arial, Helvetica">引言:
小弟在嘗試將excel的內容顯示到表單上,但是程式只能將excel打開, 無法將資料讀入,錯誤訊息顯示 "不明的名稱", 不清楚是那個地方出問題, 懇請先進撥空為小弟解惑,感謝!
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant ExcelAp,WorkBooks,Sheets,Sheet,WorkBook,Cell;
int i,j;
if(OpenDialog1->Execute())
{
ExcelAp=CreateOleObject("Excel.Application");
ExcelAp.OlePropertySet("Visible",true);
WorkBooks=ExcelAp.OlePropertyGet("WorkBooks");
WorkBook=WorkBooks.OleFunction("Open",OpenDialog1->FileName.c_str());
Sheets = WorkBook.OlePropertyGet("Sheets");
Sheet = Sheets.OlePropertyGet("Item",1);
for(i=1;i<7;i )
{
for(j=1;j<7;j )
{
Cell = Sheet.OlePropertyGet("Cells",i,j);
StringGrid1->Cells[i-1][j-1]=Cell.OlePropertyGet("Text");
}
}
StringGrid1->RowCount=i-1;
StringGrid1->ColCount=j-1;
} }
國泰平安