StringGrid导入Excel~~~求助,帮忙看看我的代码错在哪里?
想将StringGrid里的档案导入Excel中去,不成功,不知道错在哪里~请大侠帮忙看看~
void __fastcall Tfrm_Main::Button2Click(TObject *Sender)
{
Variant ExcelApp,ExcelWorkBook,Sheet;
ExcelApp=Variant::CreateObject("Excel.Application");
ExcelApp.PS("Visible",true);
ExcelApp.PG("Workbooks").FN("Add");
Sheet=ExcelApp.PG("ActiveWorkbook").PG("Sheets",1);
for(int n=0;n<=sg_Record->RowCount;n++)
{
for(int m=0;m<=sg_Record->ColCount;m++)
{
Sheet.PG("Cells",n+1,m+1).PS("Value",sg_Record->Cells[n][m]);
}
}
ExcelApp.PG("ActiveWorkbook").FN("SaveAs","F:\\ddd.xls");
ExcelApp.FN("Quit");
}
[解决办法]
Sheet.PG("Cells",n+1,m+1).PS("Value",sg_Record->Cells[n][m]);//类型错误 char *
Sheet.PG("Cells",n+1,m+1).PS("Value",sg_Record->Cells[n][m].c_str());//bcb6,2007
Sheet.PG("Cells",n+1,m+1).PS("Value",sg_Record->Cells[n][m].t_str());//2008及以后