Note: To export #include // dBGRID data in header file to Excel form void __stdcall GridToExcel (TDBGRID * DBGRIDB, ANSISTRING TITLEB, ANSISTRING FILENAMEB) {// To export DBGRID / Export to Excel The title / saving of Excel's path // determines if the file exists and decides whether IF (fileExists (fileEnameb)) {if (Messagedlg already exists, is it deleted? "MTWARNING, TMSGDLGButtons () MTWARNING, TMSGDLGBUTTONS ()
, 2 * 28.5); // The lower margin 2 // Sets the horizontal alignment of the horizontal hordment. Ops ("centerhorizontally", true); // Table 1 title ****** ******** // Merge unit A1 to M1, and assign a A1: M1 area to Range Range = Sheeta.Opg ("Range", "A1: M1"); Range.Ofn ("Merge" , false; // combined with false, split with true // to fill in the content SHEETA.OPG ("Cells", 1, 1) .Ops ("Value", titleb.c_str ()); // Set zone font range.opg ("cells"). OPG ("font"). OPS ("name", "Song"); // Sets the area font size Range.Opg ("cells"). OPG ("font" ) .OPS ("size", 18); // Set vertical alignment - hosted range.opg ("cells"). OPS ("VerticalAlignment", 2); // Set the horizontal alignment - hide range.opg (" Cells "). OPS (" HorizontalaLight ", 3); // Table 1 The title ends ************ // Table 1's head ********* ****** for (int I = 0; i datasource-> dataset-> fields-> count; i ) {string str = dbgridb-> datasource-> dataset-> fields-> fields [i ] -> displadinglabel; // Filter content to cells Sheeta.Opg ("Cells", 2, i 1) .Ops ("Value", str.c_str ()); // Set Border Sheeta.opg ("Cells ", 2, i 1) .Opg (" Borders ", 1) .Ops (" LINESTYLE ", 1); // Left Border Sheeta.Opg (" Cells ", 2, i 1) .opg (" Borders ", 2) .ops (" LINESTYLE ", 1); // Right Box Sheeta.Opg (" Cells ", 2, i 1) .opg (" Border S ", 3) .ops (" LINESTYLE ", 1); // On the border Sheeta.Opg (" Cells ", 2, i 1) .opg (" Borders ", 4) .ops (" LINESTYLE ", 1 ); // NextA.OPG ("Cells", 2, i 1) .OPS ("WrapText", true); // Set the automatic wrap sheeta.opg ("cells", 2, i 1). OPS ("HorizontalaLalignment", 3); // Setting the horizontal} // Table 1 The head end *********** // Table 1 data start ******* **** DBGRIDB-> DataSource-> DataSet-> first (); for (int J = 1; j datasource-> dataset->
RecordCount 1; J ) {for (int i = 0; i datasource-> dataset-> fields-> count-1; i ) {string straw = dbgridb-> datasource-> dataset-> fields-> Fields [i] -> text; sheeta.opg ("cells", J 4, i 1) .OPS ("Value", stra.c_str ()); Sheeta.opg ("cells", J 4, i 1) .Opg ("Borders", 1) .ops ("LINESTYLE", 1); // Left Border Sheeta.Opg ("Cells", J 4, I 1) .opg ("Borders", 2) .OPS ("LINESTYLE", 1); // Right Box Sheeta.Opg ("Cells", J 4, i 1) .Opg ("Borders", 3) .ops ("LineStyle", 1) ; // On the border sheeta.opg ("cells", J 4, i 1) .opg ("Borders", 4) .ops ("LINESTYLE", 1); // Next Box} ●} (! DBGridb- > Datasource-> dataset-> eof) {dbgridb-> DataSource-> DataSet-> next ();}} // Table 1's data end ********** // Close warning prompt Workbook. OPG ("Application"). OPS ("Displayalerts", False; / / Save As Workbook.OPR ("SaveAs", FileNameb.c_STR ()); // Close Workbook Workbook.OPR ("Close"); / / Close Excel Program Excelapp.Ofn ("Quit"); // End, if there is no code, the Excel thread ends until the application exits EXCELAPP = Unassigned; Workbook = unassigned; off = unassigned; ShowMessage (Titl EB "Export Success!");} // Write the bad, for reference only: I reference information http://www.ccrun.com/doc/go.asp?id=529
http://www.ccrun.com/doc/go.asp?id=543
Description: Users can get what they need by recording macro, view macro code.