Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Paste an array into Excel
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00306028
Message ID:
00306034
Vues:
33
Martin,

Here's some code that works -- I'm sure I've done this a neater way than this, but I can't recall how.

You can do this, but you need to convert the array to a string first
* Program....: PASTEARRAY.PRG
* Version....: 1.0
* Author.....: Andrew Coates
* Date.......: December 20, 1999
* Compiler...: Visual FoxPro 06.00.8492.00 for Windows
* Abstract...: Pastes the contents of an array into Excel
* Changes....:

* set up a test array
local laMyArray[1]

dimension laMyArray[5,2]

laMyArray[1,1] = 'date()'
laMyArray[1,2] = date()
laMyArray[2,1] = 'datetime()'
laMyArray[2,2] = datetime()
laMyArray[3,1] = '$500.00'
laMyArray[3,2] = $500.00
laMyArray[4,1] = '.T.'
laMyArray[4,2] = .t.
laMyArray[5,1] = '55.25'
laMyArray[5,2] = 55.25

* Create a string of the array
local lcArrayString, lnRow, lnColumn
lcArrayString = ''
FOR lnRow = 1 to alen(laMyArray, 1)
	FOR lnColumn = 1 to alen(laMyArray, 2)
		lcArrayString = lcArrayString + tran(laMyArray[lnRow, lnColumn]) + iif(lnColumn = alen(laMyArray, 2), '', ',')
	ENDFOR &&* lnColumn = 1 to alen(laMyArray, 2)
	
	* each line is separated by a CRLF
	lcArrayString = lcArrayString + chr(13) + chr(10)
ENDFOR &&* lnRow = 1 to alen(laMyArray, 1)

_cliptext = lcArrayString

* public so i can manipulate them after the prg finishes
public loExcel, loWorkbook

* create an instance of excel
loExcel = create('excel.application')

* check for errors in the creation

* create a workbook
loWorkbook = loExcel.Workbooks.Add()

* check for errors

loWorkbook.ActiveSheet.Paste()
loExcel.Selection.TextToColumns(,,,,.f.,.f.,.t.)
loExcel.Visible = .t.
loWorkbook.ActiveSheet.Visible = .t.
Cheers,

Andrew
>Is it possible to paste the entire contents of an array into Excel - not just an element that is referenced e.g. myarray[1,1] or myarray[1,2] Can you paste the entire array into a spreadsheet in one go?


If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?


From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."


All my FoxTalk and other articles are available on my web site.


Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform