Z
ZengMuAnSha
Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何使用ComObj 把Excel导入到StringGrid?
以下是BCB的代码 问题在于有多少有效行和列 要从Excel里得到
void xls2strgrid(char* path,int with, int height,TStringGrid *grid)
{
Variant app,workb,sheet;
app = CreateOleObject("excel.application"
app.OlePropertySet("Visible",true);
app.OlePropertyGet("WorkBooks".OleProcedure("Open",path);
workb = app.OlePropertyGet("ActiveWorkbook"
sheet = workb.OlePropertyGet("ActiveSheet"
grid->RowCount = with+1;
grid->ColCount = height+1;
try
{
for (int i=1;i<=height ;i++)
{
for (int j=1;j<=with ;j++)
{
grid->Cells[j] = sheet.OlePropertyGet("Cells",j,i) ;
}
}
}
__finally
{
app.OlePropertySet("Visible",true);
workb.OleProcedure("Close"
app.OleFunction("Quit"
}
}
以下是BCB的代码 问题在于有多少有效行和列 要从Excel里得到
void xls2strgrid(char* path,int with, int height,TStringGrid *grid)
{
Variant app,workb,sheet;
app = CreateOleObject("excel.application"
app.OlePropertySet("Visible",true);
app.OlePropertyGet("WorkBooks".OleProcedure("Open",path);
workb = app.OlePropertyGet("ActiveWorkbook"
sheet = workb.OlePropertyGet("ActiveSheet"
grid->RowCount = with+1;
grid->ColCount = height+1;
try
{
for (int i=1;i<=height ;i++)
{
for (int j=1;j<=with ;j++)
{
grid->Cells[j] = sheet.OlePropertyGet("Cells",j,i) ;
}
}
}
__finally
{
app.OlePropertySet("Visible",true);
workb.OleProcedure("Close"
app.OleFunction("Quit"
}
}