Các lệnh làm việc với Excel trong VFP

http://social.msdn.microsoft.com/Forums/en-US/visualfoxprogeneral/thread/72575fea-a9f9-4c2e-856b-d2846dfdeb4b
 
oExcel = CreateObject("Excel.Application") 
Create Object
oSheet = oExcel.Activesheet Create Object
oExcel.Sheets.Add Add a new worksheet
oExcel.Workbooks.Add Add a new workbook
oExcel.Range("A2:A3").Verticalalignment = 2
oExcel.Range("H2:N2").HorizontalAlignment = 3 Alignment, Center
oExcel.Range(oExcel.Cells(mrow,mcol), oExcel.Cells(mrow,mcol)).HorizontalAlignment = 3 Alignment, Center
oExcel.Range("H2:N2").HorizontalAlignment = 2 Alignment, Left
oExcel.Cells(3,4).Horizontalalignment = 1 Alignment, Right
oExcel.Columns("A:AD").Autofit Autofit
oExcel.Activewindow.Displayworkbooktabs = -1 Book Tab
oExcel.Activeworkbook.Close() Close
oExcel.Cells(2,8).Interior.Colorindex = 6 Color, Background
oExcel.Columns("C").ColumnWidth = 15 Column Width
oExcel.Columns("C:H").ColumnWidth = 15 Column Width
oExcel.Sheets("sheet1").Delete Delete Sheet
oExcel.Displayalerts = 0   &&& or -1 Displayalerts Off
oExcel.Cells(1,1).Font.Bold = 1 Font
oExcel.Cells(1,1).Font.Colorindex = 55 Font Color
oExcel.Cells(1,1).Font.Size = 16 Font Size
oExcel.Columns("B:G").NumberFormatLocal = "0.00_ " Format : 2 Decimals
oExcel.Columns("A:A").NumberFormatLocal = "[$-404]e/m/d;@" Format : Year
oExcel.Activewindow.Freezepanes = -1 Freezepanes
oExcel.Activewindow.Displaygridlines = -1 Gridline, Display
oExcel.Activewindow.Displaygridlines = 0 Gridline, Hide
oExcel.Range("B1").Entirecolumn.Insert Insert Column
oExcel.Range("2:20").Entirerow.Insert Insert Row
oExcel.Range("H2:N2").Borders.Linestyle = 1 Linestyle
oExcel.Range("A2:B3").Merge Merge
oExcel.Range(oExcel.Cells(mrow,mcol), oExcel.Cells(mrow,mcol)).Merge Merge
oExcel.Activesheet.Name = "ABC" Name an Active Sheet
oExcel.Activeworkbook.Open("ABC.xls") Open
oExcel.Quit() Quit
#Define XLDBF 8 Save Excel file as DBF file - step 1
oExcel.ActiveWorkbook.Saveas("ABC.dbf", XLDBF) Save Excel file as DBF file - step 2
oExcel.Activeworkbook.Saveas("ABC.xls") Saveas
oExcel.Cells("A1").Select Select
oExcel.Columns("B:E").Select Select
oExcel.range("A9").Select Select
oExcel.Selection.Copy Select and Copy
oExcel.Selection.Cut Select and Cut
oExcel.Selection.Paste Select and Paste
oExcel.Sheets("sheet1").Select Select Sheet
oExcel.Cells(1,1).Value = "ABC" Value, Assign a
oExcel.Cells(mrow,mcol).Value = "ABC" Value, Assign a
mValue=oExcel.Cells(mrow,mcol).Value Value, Return a
oExcel.Visible = -1     Workbook Visible
oExcel.Visible = 0 Workbook Invisible
oExcel.Activewindow.DisplayZeros = .F. Zero Values, Hide All
oExcel.Activewindow.Zoom = 70 Zoom

Use ABC.dbf Arrange data for chart
Select fieldname1, fieldname2, fieldname3 from ABC.dbf Into Cursor crsData Arrange data for chart
Copy To (ABC.txt) Type Delimited With Tab Arrange data for chart
_Cliptext = "fieldname1"+CHR(9)+"fieldname2"+CHR(9)+"fieldname3"+CHR(13)+Filetostr(ABC.txt) Arrange data for chart
Erase (ABC.txt) Arrange data for chart


With oSheet Start of outer loop
    .Range('B2').PasteSpecial Paste _Cliptext
    oRange = .Application.Selection Chart Object Creation
With oRange
    oChartRange   = .Range(.Cells(0,1), .Cells(.Rows.Count-1, 3))  Chart Range Creation
    oLabelsRange = .Range(.Cells(0,0), .Cells(.Rows.Count-1, 0))    Chart Label Creation
Endwith

#Define     xlColumnStacked 52 Define Chart Type

#Define     xlCategory 1 Define X Axis
#Define     xlValue 2 Define Y Axis


    .ChartObjects.Add(2, 2, 717, 245)                              Add new chart and specify its position and area
With .ChartObjects(1).Chart Name chart object as 1
    .SetSourceData(oChartRange)
    .hastitle = .T.
    .haslegend = .T.
    .legend.position = 3 or 1 or 2 or 4 or 5
    .ChartTitle.Caption = "ChartTitle" "ChartTitle" or memory variable
    .ChartType = xlLine or xlColumns or xlColumnClustered or xlPie …
    .SeriesCollection(1).XValues = oLabelsRange Label (1st field of selected fields) of Y axis
    .SeriesCollection(3).ApplyCustomType( xlColumnClustered ) Show bar(3rd field of selected fields) in line-chart
    .Axes(xlCategory).HasTitle = .T.
    .Axes(xlCategory).AxisTitle.caption = "Date" Title of X axis, "Date" or memory variable
    .Axes(xlValue).HasTitle = .T.
    .Axes(xlValue).AxisTitle.caption = "$$$" Title of Y axis, "$$$" or memory variable
    .plotarea.width = 660 Optional
    .plotarea.height = 210 Optional
    .plotarea.left = 43 Optional
    .plotarea.top = 0 Optional
Endwith
Endwith Finish of outer loop




***  Re above, more solutions are available from Excel Macro ***






oWS = CreateObject("Wscript.Shell") Create Object
oWS.run("c:\ABC.doc") Open file
oWS.run("c:\ABC.pps") Open file
oWS.run("c:\ABC.ppt") Open file
oWS.run("c:\ABC.jpg") Open file
oWS.run("c:\ABC.pdf") Open file  
--------------





Không có nhận xét nào:

Đăng nhận xét