///******************导出EXCEL表格的函数**********************************************
outputXLS(TStringGrid *sgdresult,AnsiString filename)
{
//TODO: Add your source code here
Variant Ex,wb,sheet,ERange,EBorders;
AnsiString strdir;
register int n;
n = 0;
Ex = CreateOleObject("Excel.Application");
//Ex.OlePropertySet("Visible",false);
Ex.OlePropertySet("Visible",true);
//创建一个新的excel工作本(文件)
wb= Ex.OlePropertyGet("Workbooks");
wb.Exec(Procedure("Add"));
wb=Axl.OlePropertyGet("ActiveWorkbook");
sheet=Workbook.OlePropertyGet("ActiveSheet");
AnsiString strRowTemp;
AnsiString strRange,strtemp;
strRange = "A"+IntToStr(1)+":R"+IntToStr(1);//获取操作范围
ERange = sheet.OlePropertyGet("Range",strRange.c_str());
EBorders = ERange.OlePropertyGet("Borders");//获取边框对象
EBorders.OlePropertySet("linestyle",xlNone);
//AnsiString strData = "报表标题";//报表标题
//sheet.OlePropertyGet("Cells",1,1).OlePropertySet("Value",strData.c_str());
int i = 1;
for (n;n < sgd_temp->RowCount; n++)
{
for (int j = 1;j <= sgd_temp->ColCount; j++)
{
strtemp = sgd_temp->Cells[j-1][n];
sheet.OlePropertyGet("Cells",i,j).OlePropertySet("Value",strtemp.c_str());
}
strRange = "A"+IntToStr(i)+":R"+IntToStr(i);
ERange = sheet.OlePropertyGet("Range",strRange.c_str());
EBorders = ERange.OlePropertyGet("Borders");
EBorders.OlePropertySet("linestyle",xlContinuous);
EBorders.OlePropertySet("weight",xlThin);
EBorders.OlePropertySet("colorindex",xlAutomatic);
i++;
}
wb.OleProcedure("SaveAs",savfilename.c_str()); //保存表格
wb.OleProcedure("Close");//关闭表格
Ex.OleFunction("Quit");//退出Excel
Application->MessageBox("导出完毕!!!","提示",MB_ICONINFORMATION|MB_OK);
} |