Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Transferring to multiple worksheets in excel
Message
De
06/06/2007 11:55:18
 
 
À
06/06/2007 07:28:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01230856
Message ID:
01230991
Vues:
16
This message has been marked as the solution to the initial question of the thread.
>i hv been transferring to excel regularly but always to a single sheet, what i need to do now is transfer 15 tables but the first should go to sheet 1 , second to sheet 2 and so on. all in one file.
>
>how is that done?

We have a similar situation. One file with several depts. Each dept should become its own sheet. This is the code I inherited which does the job. I've modified it to what I think your needs are but I'm sure you would need to modify it further

Hope it helps
lcFileName = "Your XLS output file"

** Assume list of tables is in a cursor
** Use the first one to create the XL spreadsheet
** Then SCAN through rest to add sheets
SELECT myTableCursor
GO TOP
USE (myTableCursor.table_name) IN 0 ALIAS sendtoXL
SELECT sendtoXL
COPY TO (lcFileName) TYPE xl5

oXL = Createobject("Excel.Application")
oXL.DisplayAlerts = .F.
oXL.Application.WorkBooks.Open(lcFileName)

SELECT myTableCursor
GOTO 2
SCAN REST
  USE (myTableCursor.table_name) IN SELECT('sendtoXL') ALIAS sendtoXL
  SELECT sendtoXL
  Copy To tempXL Type xl5
  Attach_WSheet(oXL, lcFileName, "tempXL.xls", myTableCursor.table_name, 1)
ENDSCAN
oXL.Save()
oXL.Quit
oXL = .Null.

FUNCTION Attach_WSheet(toXLObject, tcFileMoveTo, tcFileToMove, tcSheetName, tnSheetPos)
  Local ;
   lcFile As String, lcFile1Name As String, lcFile2 As String

  lcFile = Juststem(tcFileToMove)
  lcFile1Name = Justfname(tcFileToMove)
  lcFile2 = Justfname(tcFileMoveTo) + ".xls"

  toXLObject.Application.WorkBooks.Open(tcFileToMove)
  toXLObject.Windows(lcFile1Name).Activate
  toXLObject.Sheets(lcFile).Move(toXLObject.Application.WorkBooks(lcFile2).Sheets(tnSheetPos))

  oDS = toXLObject.Application.ActiveSheet
  oDS.Name = tcSheetName

ENDFUNC
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform