Un Archivo Excel con varias Hojas Generadas con Datos de una DBF.

HMG en Español

Moderator: Rathinagiri

Post Reply
User avatar
LOUIS
Posts: 204
Joined: Tue Dec 11, 2012 9:05 pm
DBs Used: DBF

Un Archivo Excel con varias Hojas Generadas con Datos de una DBF.

Post by LOUIS »

Amigos buenas tardes:

Por aquí con una inquietud, que de seguro uds podrán ayudarme.

Al exportar una dbf ya filtrada hacia excel con esta sentencia COPY TO ('ITEMS.XLS') me crea efectivamente el archivo excel y su hoja respectiva, pero ahora tengo la necesidad de crear ese archivo excel, pero con 2 o más hojas, con los mismos datos pero filtrados de otra manera.

Cómo podría crear Un archivo xls con varias hojas activas y con datos ?

De antemano, muchas gracias por vuestro tiempo y paciencia.

Saludos.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Un Archivo Excel con varias Hojas Generadas con Datos de una DBF.

Post by andyglezl »

Al exportar una dbf ya filtrada hacia excel con esta sentencia COPY TO ('ITEMS.XLS')
...pero ahora tengo la necesidad de crear ese archivo excel, pero con 2 o más hojas...
De esta forma ya no lo podrías hacer...
Aquí en el foro hay muchos post que hablan de como crear un archivo de Excel.
Según Excel 2010 (yo no le he probado), esto dice:
*---------------------------------------------------------------
This way you could not do it ...
Here in the forum there are many posts that talk about how to create an Excel file.
According to Excel 2010 (I have not tried it), this says:


http://www.hmgforum.com/viewtopic.php?f ... ilit=excel

Sheets.Add method (Excel)

Creates a new worksheet, chart, or macro sheet. The new worksheet becomes the active sheet.

Syntax
expression.Add(Before, After, Count, Type)

expression A variable that represents a Sheets object.

Parameters
Name Required/Optional Data type Description
Before Optional Variant An object that specifies the sheet before which the new sheet is added.
After Optional Variant An object that specifies the sheet after which the new sheet is added.
Count Optional Variant The number of sheets to be added. The default value is one.
Type Optional Variant Specifies the sheet type. Can be one of the following xlSheetType constants: xlWorksheet, xlChart, xlExcel4MacroSheet, or xlExcel4IntlMacroSheet. If you are inserting a sheet based on an existing template, specify the path to the template. The default value is xlWorksheet.
Return value
An Object value that represents the new worksheet, chart, or macro sheet.

Remarks
If Before and After are both omitted, the new sheet is inserted before the active sheet.

Example
This example inserts a new worksheet before the last worksheet in the active workbook.

ActiveWorkbook.Sheets.Add(Before:=Worksheets(Worksheets.Count))

This example inserts a new worksheet after the last worksheet in the active workbook.

ActiveWorkbook.Sheets.Add(After:=Worksheets(Worksheets.Count))
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
LOUIS
Posts: 204
Joined: Tue Dec 11, 2012 9:05 pm
DBs Used: DBF

Re: Un Archivo Excel con varias Hojas Generadas con Datos de una DBF.

Post by LOUIS »

Andy, gracias por responder.

Ví el enlace que me dejaste y sí crea archivos excel desde dbf, pero sólo una hoja ...

Yo necesito crear 2 o más hojas (sheets) dentro del mismo archivo excel.

Si sabes de otros enlaces, te agrecería mucho.

Saludos.
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Un Archivo Excel con varias Hojas Generadas con Datos de una DBF.

Post by SALINETAS24 »

Hola Louis, creo que buscas algo como esto.

Code: Select all

   IF nQueHoja = NIL
      oExcel := CreateObject( "Excel.Application" )  // HMG 3
      oWorkBook := oExcel:WorkBooks:Add()
      oHoja := oExcel:ActiveSheet
   ELSE
      IF nQueHoja = 1
         oExcel := CreateObject( "Excel.Application" )  // HMG 3
         oWorkBook := oExcel:WorkBooks:Add()
         oHoja := oExcel:ActiveSheet
      ELSE
         nSheets := oExcel:Sheets:Count()
         IF nSheets >= nQueHoja
            oExcel:Sheets(nQueHoja):Select()
         ELSE
            oExcel:Sheets:Add()
         ENDIF
         oHoja := oExcel:ActiveSheet
      ENDIF
   ENDIF
http://www.hmgforum.com/viewtopic.php?f ... eet#p57596

Salud
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
Post Reply