Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to call an excel worksheet from vfp8
Message
De
01/08/2005 20:25:12
 
 
À
01/08/2005 14:21:43
Information générale
Forum:
Visual FoxPro
Catégorie:
Produits tierce partie
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01037565
Message ID:
01037683
Vues:
11
hi gabriel sory i have no time to filter the code for excel just try to filter some of the existing code
Local oErrorExcel As Exception
Local oExecel  As Excel.Application
Local oWorkBook As Excel.Workbook
Local oSheet1 As Excel.Worksheet
Local oRange As Excel.Range
Local lcColumnFrom1,lcColumnTo1, lcColumn2,lcColNameLeftPartA,lcColNameLeftPartB
Local lnCol,lnRow
Local lcFileName As String,lcNewFileName As String
Local lnIncomeNextRow,lnEquipNextCol

Local lnRowForIncomeBase,lnRowForExpenseBase,lnRowForEquipBase
lnRowForIncomeBase=11
lnRowForExpenseBase=16
lnRowForEquipBase=7
lcColNameLeftPartA=""
lcColNameLeftPartB=""



pFromDate=Thisform.sjdatepickfromto1.From
pToDate =Thisform.sjdatepickfromto1.To
pEquipID=Iif(Thisform.cbonameid.ListIndex>0,Thisform.cbonameid.Value,0)


=SQLEXEC(oConn.nConnHandle,"{CALL spGetEquipmentIncomeExpense(?pFromDate,?pToDate ,?pEquipID)}","ltIncExpense")



	Select FkCustEmpVenIDEquipID,;
		FkActID,;
		sum(Abs_Value1) As Abs_Value1;
		FROM ltIncExpense;
		Group By FkCustEmpVenIDEquipID,FkActID ;
		INTO Cursor ltEquipAccountList Readwrite
	Select ltEquipAccountList


	Select EquipmentName1,;
		FkCustEmpVenIDEquipID,;
		0.00000 As ColNo;
		FROM ltIncExpense;
		Group By EquipmentName1,FkCustEmpVenIDEquipID;
		INTO Cursor ltEquipList Readwrite

	Select ltEquipList

	Thisform.sjDBHANDLER.setindexonfields("FkCustEmpVenIDEquipID","ltEquipList")


	Select GroupLevel1,;
		AccountName,;
		FkActID,;
		0.00000 As RowNo ;
		from ltIncExpense  ;
		group By GroupLevel1,AccountName,FkActID;
		Into Cursor ltIncExpGrp Readwrite

	Select ltIncExpGrp

	Thisform.sjDBHANDLER.setindexonfields("FkActID","ltIncExpGrp")

	Select ltIncExpGrp




	lcExcelFilename=oPolCheck.GetPolicyAlias("REP_EQUIP_INC_EXP_XLS")
	lcExcelFilename=Addbs(Sys(5)+Sys(2003))+Alltrim(lcExcelFilename)
	*!*				IF !EMPTY(lcReportFilename)
	*!*						this.Parent.Parent.sjcrystalprintonly1.reportfilename="rpt\" + ALLTRIM(lcReportFilename)
	*!*					ELSE
	*!*						this.Parent.Parent.sjcrystalprintonly1.reportfilename="rpt\rptDisVoucher.rpt"
	*!*
	*!*				ENDIF


	lcNewFileName =Thisform.sjDBHANDLER.sjdrivefileobject.gettmpfiles()

	oExecel  =GETOBJECT('', "Excel.Application")


	oWorkBook=oExecel.Workbooks.Open(lcExcelFilename)
	oWorkBook.SaveAs(lcNewFileName)
	oSheet1=oWorkBook.Sheets(1)
	 

		oSheet1.Range("PERIOD_COVERED").value="Period Covered From " + DTOC (pFromDate)  + " to " + DTOC(pToDate)
	


	Select ltIncExpGrp
	lnIncomeNextRow=10

	Scan For Alltrim(GroupLevel1)="INCOME"
		Scatter Memvar Fields AccountName,FkActID

		oSheet1.Range("INCOME_BASE_ROW").EntireRow.Copy
		oSheet1.Range("INCOME_BASE_ROW").EntireRow.Insert (.t.,.t.)



		oSheet1.Range("F" + Alltrim(Str(lnIncomeNextRow))).Value =Alltrim(m.AccountName)
		oSheet1.Range("A" + Alltrim(Str(lnIncomeNextRow))).Value = m.FkActID


		Replace RowNo With lnIncomeNextRow In ltIncExpGrp

		lnIncomeNextRow=lnIncomeNextRow+1




	Endscan

*!*		oSheet1.Range("ROW_INC_HIDE").EntireRow.Hidden =.t.
*!*		oSheet1.Range("INCOME_BASE_ROW").EntireRow.Hidden =.t.	  
	



	Select ltIncExpGrp
	lnIncomeNextRow=lnRowForExpenseBase+ (lnIncomeNextRow-lnRowForIncomeBase)

	Scan For Alltrim(GroupLevel1)="COST_OF_SALES"
		Scatter Memvar Fields AccountName,FkActID

		oSheet1.Range("EXPENSE_BASE_ROW").EntireRow.Copy
		oSheet1.Range("EXPENSE_BASE_ROW").EntireRow.Insert (.t.,.t.)		
		
		oSheet1.Range("F" + Alltrim(Str(lnIncomeNextRow))).Value =Alltrim(m.AccountName)
		oSheet1.Range("A" + Alltrim(Str(lnIncomeNextRow))).Value =m.FkActID

		Replace RowNo With lnIncomeNextRow In ltIncExpGrp

		lnIncomeNextRow=lnIncomeNextRow+1

	Endscan

	Select ltIncExpGrp




	Select ltEquipList

	lnEquipNextCol=7
	*!*			oSheet1.Range("G1").EntireColumn.Copy
	*!*			oSheet1.Range("H1").EntireColumn.PasteSpecial(-4104)


	lcColumnFrom1="G"
	lcColumnTo1="H"
	
	Scan
		Scatter Memvar Fields EquipmentName1, FkCustEmpVenIDEquipID
		lcColumn2=Chr(Asc(lcColumnTo1)+1)

*!*			oSheet1.Range(lcColumn2+"1").EntireColumn.Insert(.T.,.F.)
*!*			oSheet1.Range(lcColumn2+"1").EntireColumn.Insert(.T.,.F.)

		oSheet1.Range("COL_INSERT").EntireColumn.Insert(.T.,.F.)
		oSheet1.Range("COL_INSERT").EntireColumn.Insert(.T.,.F.)

		**oSheet1.Range("COL_INSERT").EntireRow._PrintOut 

	 
		oSheet1.Range("COL_COPY").EntireColumn.Copy
		oSheet1.Range(oSheet1.Cells(1, oSheet1.Range("COL_INSERT").Column-2),oSheet1.Cells(1, oSheet1.Range("COL_INSERT").Column-1) ).EntireColumn.PasteSpecial(-4104)
		
		

		Replace ColNo With lnEquipNextCol In   ltEquipList

		oSheet1.Cells(lnRowForEquipBase,lnEquipNextCol).Value= m.EquipmentName1
		oSheet1.Cells(1,lnEquipNextCol).Value= m.FkCustEmpVenIDEquipID
		lnEquipNextCol=lnEquipNextCol+2



	Endscan


	*!*	SELECT FkCustEmpVenIDEquipID,;
	*!*		   FkActID,;
	*!*		   sum(Abs_Value1) as Abs_Value1;
	*!*	FROM ltIncExpense;
	*!*	Group BY FkCustEmpVenIDEquipID,FkActID ;
	*!*	INTO CURSOR ltEquipAccountList READWRITE
	*!*	SELECT ltEquipAccountList




	*!*	SELECT EquipmentName1,;
	*!*		   FkCustEmpVenIDEquipID,;
	*!*		   0.00000 as ColNo;
	*!*	FROM ltIncExpense;
	*!*	Group BY EquipmentName1,FkCustEmpVenIDEquipID;
	*!*	INTO CURSOR ltEquipList READWRITE


	*!*	Select GroupLevel1,;
	*!*	       AccountName,;
	*!*	       FkActID,;
	*!*	       0.00000 as RowNo ;
	*!*	from ltIncExpense  ;
	*!*	group by GroupLevel1,AccountName,FkActID;
	*!*	Into CURSOR ltIncExpGrp READWRITE



	Select ltEquipAccountList
	Scan
		Scatter Memvar Fields FkCustEmpVenIDEquipID,FkActID,Abs_Value1

		If Seek(m.FkCustEmpVenIDEquipID,"ltEquipList","FkCustEmpV") And Seek(m.FkActID,"ltIncExpGrp","FkActID")
			Select ltEquipList
			Scatter Memvar Fields 	ColNo

			Select ltIncExpGrp
			Scatter Memvar Fields 	RowNo

			oSheet1.Cells(m.RowNo,m.ColNo).Value =m.Abs_Value1

		Else
			=Messagebox("NOT SEEK",0,APP_NAME)

		Endif




	Endscan




	oExecel.Visible = .T.

Try
	SELECT ltEquipAccountList
	Use In  ltEquipAccountList
	Use  In ltEquipList
	Use In ltIncExpGrp
	Use In  ltIncExpense


Catch To oErrorExcel

*	=MESSAGEBOX(oErrorExcel.LineContents,0,APP_NAME) 
Endtry
Roses are #FF0000 Violets are #0000FF all my base are belong to you
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform