Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exporting to an Excel template file
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 6 SP5
OS:
Windows '98
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01032719
Message ID:
01033215
Vues:
16
Jaime,

Here's the program so far: (This is cool!!!)
* frmLoadsReport.cmdOK.Click()
LOCAL lcWorkOrder, lcNewFileName

* This is the Work Order the user selected to export to Excel.
lcWorkOrder = ThisForm.cboOrders.Value
IF EMPTY(lcWorkOrder)
	RETURN .F.	&& If the user did not select a Work Order, return to the screen.
ENDIF
* get the data for the one work order.
SELECT * ;
	FROM LOADING ;
	WHERE Loading.Order = lcWorkOrder ;
	INTO TABLE E:\CERTS\tmpLoading

* Check to see if there is any data.
IF RECCOUNT("tmpLoading") = 0
	lcMessage = "Work Order: " + lcWorkOrder + " does not exist" 
	MESSAGEBOX(lcMessage,0,"No such work order")
	RETURN
ENDIF

* Prepare the CERTS data for the EXCEL spreadsheet
* from the Loading and Customer tables.
SELECT ;
		tmpLoading.Order, ;
		tmpLoading.Cust,;
		Customer.Customer,;
		tmpLoading.ProdCode,;
		tmpLoading.Heat,;
		tmpLoading.Serial,;
		tmpLoading.Desc,;
		tmpLoading.Date,;
		tmpLoading.Dia,;
		tmpLoading.Break,;
		tmpLoading.Tensile,;
		tmpLoading.Elong,;
		tmpLoading.Wt_Of_Coat;
	FROM ;
		tmpLoading, Customer ;
	WHERE ;
		tmpLoading.Cust==Customer.CustNo ;
	ORDER BY tmpLoading.Serial ;
	INTO TABLE E:\CERTS\tmpExportCerts

lcNewFileName="E:\CERTS\" + lcWorkOrder + ".XLS"
COPY FILE E:\DEV\WireCertReport.XLS TO &lcNewFileName

* Now that you've got your data, it is time to copy the Template
* spreadsheet and then modify it.
LOCAL oExcel	&& AS "Excel.Application"

oExcel = CreateObject("Excel.Application")
IF VARTYPE(oExcel) != "O"	&& Is this now a valid Object?
	* could not instantiate Excel object
	RETURN .F.
ENDIF

* Make Excel visible during development. Turn off otherwise.
oExcel.Visible = .T.

* Open the workbook
oExcel.SheetsInNewWorkBook = 1
oWorkbook = oExcel.Workbooks.Open(lcNewFileName)

* Rename the Sheet.
oActiveSheet = oExcel.ActiveSheet
oActiveSheet.Name = lcWorkOrder		&& NewSheetTitle

* Let's work with the date formatting a bit. mm/dd/yyyy.
lcMonth = SUBSTR(tmpExportCerts.Date,5,2)
lcDay   = SUBSTR(tmpExportCerts.Date,7,2)
lcYear  = LEFT(tmpExportCerts.Date,4)
lcDate = lcMonth + "/" + lcDay + "/" + lcYear

oExcel.Range("C3").Select
oExcel.Cells(3,3).Value = tmpExportCerts.Cust		&& Cell C3  = Row 3, Col 3
oExcel.Cells(3,8).Value = lcDate					&& Cell H3  = Row 3, Col 8
oExcel.Cells(4,3).Value = tmpExportCerts.Customer	&& Cell C4  = Row 4, Col 3
oExcel.Cells(5,8).Value = tmpExportCerts.Order		&& Cell H5  = Row 5, Col 8
oExcel.Cells(6,3).Value = tmpExportCerts.Desc		&& Cell C6  = Row 6, Col 3
oExcel.Cells(10,1).Value = tmpExportCerts.Heat		&& Cell A10 = Row 10, Col 1

* Start a loop here until all data has been listed out.
SELECT tmpExportCerts
* Row and Column variables needed here. Starts on Row 13 with data.

LOCAL lnRow, lnCol
lnRow = 13
SCAN
	oExcel.Cells(lnRow, 1).Value = tmpExportCerts.Serial
	oExcel.Cells(lnRow, 2).Value = tmpExportCerts.Dia
	oExcel.Cells(lnRow, 3).Value = tmpExportCerts.Break
	oExcel.Cells(lnRow, 4).Value = tmpExportCerts.Tensile
	oExcel.Cells(lnRow, 5).Value = tmpExportCerts.Elong
	oExcel.Cells(lnRow, 6).Value = tmpExportCerts.Wt_Of_Coat
	lnRow = lnRow + 1
ENDSCAN

* Add the certification statement.
LOCAL
lcLine1 = ;
	"We hereby certify that the above test results are representative"
	" of those contained in the records"



* Save Excel.
oWorkbook.Save()
*oWorkBook.Close()
*oExcel.Application.Quit

* Erase temporary files.
IF USED("tmpExportCerts")
	SELECT tmpExportCerts
	USE
	ERASE E:\CERTS\tmpExportCerts.DBF
ENDIF
IF USED("tmpLoading")
	SELECT tmpLoading
	USE
	ERASE E:\CERTS\tmpLoading.DBF
ENDIF
* Tell user name of EXCEL file and that program is completed.
lcMessage="EXCEL file " + lcWorkOrder + ".XLS is now located in E:\Certs"
MESSAGEBOX(lcMessage,0,"Program completed!")


**********
* Add a Row.
*oExcel.Range("A1").Select
*oExcel.Selection.Insert(3)

* Play with values in specific fields
* oExcel.Cells(1,1).Value = "Bla Bla Bla"
* oExcel.Cells(1,5).Value = 12345

* Find address of last occupied cell
*lcLastCell= oExcel.ActiveCell.SpecialCells(11).Address()
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform