Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel
Message
From
10/11/2006 01:55:40
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Re: Excel
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01167275
Message ID:
01168672
Views:
15
Hi Yuri, Sergey, and Erick. Thanks for the info. I am working on it!


>>Hi All
>>
>>I want to put an Excel object on a form and then instruct it to open a XLS file from disk. Then I want the user to be able to edit the cells of the spreadsheet directly on the form. When I choose to add an OLE object to the form and choose MS Office Spreadsheet control I get a COM error. Am I choosing the correct control? MS Office 2003 is installed.
>
>Hi Jos,
>
>One of the solutions is to put the excel window inside your form. Let us suppose you have a blank form with the "Open Excel File" button in the left lower corner:
>
>*Form.load
>DECLARE LONG FindWindowA IN WIN32API STRING class, STRING title
>
>DECLARE SetParent IN user32 integer hWndChild, integer hWndParent
>DECLARE integer SetWindowPos IN User32 ;
>	integer Wnd_handler, integer Window_Order, ;
>		integer X1, integer Y1, integer X2, integer Y2, integer
>
>*Form.Init
>thisform.AddProperty("oExcel",.NULL.)
>thisform.AddProperty("oExcelWindowHandle",0)
>thisform.AddProperty("units_fox2ole",1)
>
>*Form.Unload
>SetParent(thisform.oExcelWindowHandle,0)
>IF TYPE("thisform.oExcel")="O" AND NOT ISNULL(thisform.oExcel)
>	thisform.oExcel.quit()
>ENDIF
>thisform.oExcel=null
>
>*Form.Resize
>WITH this.command1
>	.top = this.height - .height -2
>ENDWITH
>
>IF TYPE("thisform.oExcel")="O" AND NOT ISNULL(thisform.oExcel) AND ;
>			thisform.oExcel.visible
>	WITH thisform.oExcel
>		.visible=.f.
>		.width=thisform.Width /thisform.units_fox2ole
>		.height=thisform.Command1.Top /thisform.units_fox2ole
>		.left = -5
>		.Top  = 0
>		.visible=.t.
>	ENDWITH
>ENDIF
>
>*Formk.Command1.Click.
>* Modify the procedure as needed to deal with many files open, etc.
>
>=ADIR(aa,"c:\*.xls")
>IF TYPE("thisform.oExcel")#"O" OR ISNULL(thisform.oExcel)
>		
>	thisform.oExcel = CREATEOBJECT("Excel.Application")
>	
>	WITH thisform.oExcel
>		.DisplayAlerts = .f.
>		.Visible=.t.
>	
>		thisform.oExcelWindowHandle = FindWindowA(NULL, .Name)
>
>		SetParent(thisform.oExcelWindowHandle,thisform.HWnd)
>		setWindowPos(thisform.oExcelWindowHandle,0,0,0,;
>			thisform.width,;
>			thisform.command1.top,;
>			0)
>		
>		thisform.oExcel.Workbooks.Open("c:\"+aa[1])	
>		thisform.units_fox2ole = thisform.width/.width
>		
>	endwith
>ENDIF
>
>
>
>Best Wishes
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Previous
Reply
Map
View

Click here to load this message in the networking platform