Home > database >  Original concept function in data table export to Excel
Original concept function in data table export to Excel

Time:09-15


//outexcel (dw_1)

//global function integer f_outputtoexcel_new (datawindow dw_1);
//the function name: out_excel
//input: dw_1 - datawindow, specified data window
//return values: an Integer
Constant integer ppLayoutBlank=12
OLEObject ole_object xlapp//define a class
//create an instance of the class -- -- -- -- -- - OLE_Object and xlapp
Ole_object=CREATE OLEObject
Xlapp=CREATE OLEObject
/////////////////////////////////////////////////////////////////////////
The integer li_ret
Long I, j, k
//link -- -- -- -- -- - ConnectToObject
Li_ret=ole_object. ConnectToObject (" ", "Excel. Application")
IF li_ret & lt;> 0 THEN
//if the Excel is not open, it is new -- -- -- -- -- -- -- -- ConnectToNewObject
Li_ret=ole_object. ConnectToNewObject (" Excel. Application ")
If li_ret & lt;> 0 then
MessageBox (' OLE errors', 'OLE unable to connect! Error number: "+ string (li_ret))
Return 0
End the if
//ole_object. Application. Workbooks. Open (" e: \ bank \ lls2 XLS ")
Ole_object. Visible=True
END the IF

Ole_object. Workbooks. Add
Xlapp=ole_object. Application. Activeworkbook. Worksheets. [1]//xlapp Activate//set the first worksheet to Activate the worksheet/

Long numcols, numrows
Numcols=long (dw_1. Object. The datawindow. Column. Count)
//get the number of columns and rows data window (line number should be a data row number + 1)
Numrows=dw_1. Rowcount ()
//get the number of columns and rows data window (line number should be a data row number + 1)

//the name of the first field in the Excel "serial number"
Xlapp. Cells [1, 1]='number'

//write table body
For I=1 to numcols
Dw_1. Setcolumn (I)//set the current field
Xlapp. Cells [1, I + 1)=dw_1. GetColumnName ()//take out the name of the current field
Ls_col=trim (dw_1 GetColumnName ())
For j=1 to numrows
If I=1 then
Xlapp. Cells [j + 1, 1)=="row" () - 1
Xlapp. Cells [j + 1, I + 1)=dw_1. Object. The data [j] I
Elseif Match (ls_col, "id card") then//judgment is: "id field
"Xlapp. Cells [j + 1, I + 1)="'" + string (dw_1. Object. The data [j] I)
The else
Xlapp. Cells [j + 1, I + 1)=dw_1. Object. The data [j] I//write a table of contents
End the if
Next
Next

//original concept selects all the Excel data frame lines
Xlapp. UsedRange. Borders (1). Graphics.linestyle=1
Xlapp. UsedRange. Borders (2). Graphics.linestyle=1
Xlapp. UsedRange. Borders (3). Graphics.linestyle=1
Xlapp. UsedRange. Borders (4). Graphics.linestyle=1
Xlapp. UsedRange. RowHeight=37//* * * * * * * * * 1/0.035 (set the line height to 1 cm, 1 pound=0.035 cm)
//set the footer first & amp; P P
Xlapp. PageSetup. CenterFooter="first & amp; P P
"
//Settings page shuiping center
Xlapp. PageSetup. CenterHorizontally=True
Xlapp. UsedRange. The font. The name="tahoma"//set the font
. Xlapp. UsedRange. The Font Size="11"//set Font Size

///////////////////////////////the last split range or xlapp. UsedRange will go wrong!!!!!/////////////////////////////

Xlapp. Rows (" 1 "). The font. The name="bold"//first line
Xlapp. Rows (" 1 "). The Font, Bold=True//first line first line Font into a "Bold"
Xlapp. Rows (" 1 "). The HorizontalAlignment=3//first line 1: the left 2:3: the right center
Xlapp. Columns (1). HorizontalAlignment=3//the first column center

Xlapp. Cells. The Select//selection table
Xlapp. Cells. EntireColumn. AutoFit//excel automatically adjust cell width
Xlapp. Range (" a1: a1 "). The Select//Select a1 cell

/////////////////////Shutting down and disconnecting from the server/////////////////////////////////////

//ole_object. Quit ()//exit Excel file
Ole_object. Disconnectobject ()
Xlapp. Disconnectobject ()

DESTROY ole_object
DESTROY xlapp
return 1

CodePudding user response:

I actually is to use a class,

CodePudding user response:

It is good to find a PBToExcel PBD!

CodePudding user response:

Come on, brother, all with dw2xl export excel?

CodePudding user response:

  don't want to make too much trouble can be used for reference

CodePudding user response:

Look, also want to know the answer to this,

CodePudding user response:

Dw2xls is good
  • Related