void __fastcall Tfrmdispatchdataexport::D isplayexcelreport (String _title, String _strsql)
{
int i=0;
Variant Excelapp1,workbook1,sheet1;
Ansistring Filename=getcurrentdir ();
Filename=filename+ "\\Template\\DispatchReport.xlt";
Run Excel
Try
{
Excelapp1=createoleobject ("Excel.Application"); Start Excel
}
catch (...)
{
ShowMessage ("Can not Start Excel");
Return
}
Open Inorderto.xlt
Excelapp1.olepropertyset ("Visible", (Variant) false);
Excelapp1.olepropertyget ("WorkBooks"). Olefunction ("Add", (widestring) filename.c_str ());
Workbook1=excelapp1.olepropertyget ("ActiveWorkbook");
Sheet1=workbook1.olepropertyget ("ActiveSheet");
String str_title= "";
Str_title=str_title+ "" +_title;
Print Inordermst Info
Sheet1.olepropertyget ("Cells", 1,6). Olepropertyset ("Value", (widestring) str_title);
Sheet1.olepropertyget ("Cells", 3,7). Olepropertyset ("Value", Frmmain->userparameters->getoperatorid (). C_STR ());
Sheet1.olepropertyget ("Cells", 3,9). Olepropertyset ("Value", Frmmain->getsysdatetime (). dateTimeString (). C_STR ());
Print INORDERDTL Info
Qryexport->close ();
Qryexport->sql->clear ();
Qryexport->sql->add (_strsql);
Qryexport->open ();
Qryexport->first ();
int nPos = 0;
int nstep = 0;
int nrecordcnt = qryexport->recordcount;
if (nrecordcnt > 0)
{
Nstep = Ceil (nrecordcnt/100.0);
Pbexport->stepby (1);
}
Statoarbar->panels->items[1]->text = IntToStr (nrecordcnt);
int irows = 0;
For (Irows=6;irows < qryexport->recordcount+6;irows++)
{
if (bisstop) {break;}
Sheet1.olepropertyget ("Rows", irows+1). Oleprocedure ("Insert");
Sheet1.olepropertyget ("Cells", irows,1). Olepropertyset ("Value", iRows-5);
for (int icols = 1;icols < qryexport->fieldcount;icols++)
{
if (bisstop) {break;}
String strvalue = Qryexport->fields->fields[icols-1]->asstring.trim ();
Sheet1.olepropertyget ("Cells", irows,icols+1). Olepropertyset ("Value", (widestring) strvalue);
}
++npos;
if (Npos%nstep = = 0)
{
Pbexport->stepit ();
Application->processmessages ();
}
Qryexport->next ();
}
Sheet1.olepropertyget ("Rows", irows). Oleprocedure ("Delete");
Sheet1.olepropertyget ("Rows", irows). Oleprocedure ("Delete");
Excelapp1.olepropertyset ("Visible", (Variant) true);
}
Note: A template file is required:dispatchreport.xlt , which is the code that will be created by default is not displayed, when you are done, will be displayed, so you can manually save or not save. Determined by the user, I personally think this is better, the code is clear and simple. I hope you have not clear the place and I contact: qq:1574203887 or e-mail:[email protected]
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C + + Builder exports database data to Excel summary 2