C + + Builder exports database data to Excel summary 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.