Page 1 of 2

Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Mon Nov 14, 2011 12:32 pm
by Enrrique Vertiz
Saludos, bueno lo que dice el titulo es el problema que tengo, uso FileXls para crear archivos Excel lo hace rapido pero tiene la limitacion de las 65,000 lineas de los archivos .XLS, entonces me queda solo la opcion del TOle, pero es MUY lenta comparada con la anterior, alguien conoce alguna opcion diferente, o forma rapida de crear un .XLSX con mas de 100,000 lineas.
Gracias

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Mon Nov 14, 2011 12:57 pm
by hmpaquito
Enrique,

A la vez que generas cada linea por cada registro, ¿ le vas dando algun formato (bold, sombra, cambio de tipo) ?

Si *NO* le das formato, te sugiero la técnica copy-paste. Al menos la clase TSBrowse 6.0 aplica esa técnica.
Saludos

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Mon Nov 14, 2011 2:16 pm
by Enrrique Vertiz
No le doy ningun formato, solo posiciono cada campo en una celda, tienes algun ejemplo para usar el Copy() Paste() ??
Muchas gracias

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Mon Nov 14, 2011 3:29 pm
by hmpaquito
Enrique,

Ahí va: ejemplo y clase; espero que te sirva.

Code: Select all  Expand view

******************************************************
* ExcelClipBoard.Prg     (c) hmpaquito
*
*
******************************************************


//-------------------------------------------------------------------------//
FUNCTION SampleDbf2Excel()
Local oExcel, oSheet, abData

........      // Abrir la .dbf y crear el objeto oExcel

abData:= {;
          {|| CodCus },;
          {|| NamCus },;
          {|| ZipCod+ Space(1)+ State};
         }
oSheet:= oExcel:Get( "ActiveSheet" )
Dbf2Excel("Customer", oExcel, oSheet, abData)

RETURN NIL
*
//-------------------------------------------------------------------------//
// Funcion para pasar cualquier dbf a una hoja de calculo.
FUNCTION Dbf2Excel(cAli, oExcel, oSheet, abData)
Local oClip, nCol
*
oClip:= TExcelClipboard():New(oExcel, oSheet, (cAli)-> (LastRec()) )
oClip:Activate()
*
SELECT (cAli)
GO TOP
DO WHILE !Eof()
   oClip:AddData(abData)
   SKIP
ENDDO
oClip:End()
*
// Ajusta columnas y otras cosas que se quieran hacer despues
// de haber traspasado la informacion, tal como dar formato a la
// cabecera poniendo nombres de encabezado.
FOR nCol:= 1 To nCols
   oSheet:Columns( nCol ):AutoFit()
NEXT
RETURN NIL
*
*
//-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -//
// (c) hmpaquito
// Clase para grabacion rapida de hojas excel con técnica Clipboard !!
CLASS TExcelClipBoard
   #Define nFILA_CABECERA 1                       // 1 indica que hay cabecera en la fila 1; esto podria ser un parametro
   #Define EXCEL_CLIP_NUEVA_LINEA    Chr(13)
   #Define EXCEL_CLIP_SEPARA_COLUMNA Chr(9)       // tabulador
   #Define WINDOW_                   WndMain()
   #Define INIT_TEXT ""
   METHOD New()
   METHOD Activate()
   METHOD End()
   METHOD AddData()
   METHOD AddLine()        HIDDEN
   METHOD VaciaClipboard() HIDDEN

   DATA cText       HIDDEN

   DATA oMeter      HIDDEN
   DATA nMeterTotal HIDDEN

   DATA lIni        HIDDEN
   DATA nFila       HIDDEN
   DATA nFilaPaste  HIDDEN
   DATA oExcel      HIDDEN
   DATA oHoja       HIDDEN
   DATA oClp        HIDDEN
ENDCLASS
*
//-------------------------------------------------------------------------//
// oExcel,      OBLIGATORIO
// oHoja,       OBLIGATORIO
// nMeterTotal, OPCIONAL
METHOD New(oExcel, oHoja, nMeterTotal) CLASS TExcelClipBoard
*
::lIni:=       .t.
::nFila:=      nFILA_CABECERA+ 1
::nFilaPaste:= ::nFila
*
::oExcel:= oExcel
::oHoja := oHoja
*
*
::nMeterTotal:= nMeterTotal
*
::cText:= INIT_TEXT
*
::oClp := TClipBoard():New(NIL, WINDOW_)
*
//oClp:Clear()
RETURN Self
*
//-------------------------------------------------------------------------//
METHOD Activate() CLASS TExcelClipBoard
Local nMeter
IF ::nMeterTotal != NIL
   @ 5,43 METER ::oMeter ;
                VAR nMeter   ;
                TOTAL ::nMeterTotal;
        SIZE 500,20 ;
        PROMPT "Generando la hoja "+ ::oHoja:Name+ "...";
        COLORS CLR_HGRAY, CLR_GRAY ;
        BARCOLOR CLR_HBLUE, CLR_YELLOW OF WINDOW_
ENDIF
RETURN NIL
*
//-------------------------------------------------------------------------//
METHOD AddData(abData) CLASS TExcelClipBoard
Local nI, nCols:= Len(abData)
Local xData
Local cTmp:= ""

*
xData:= Eval(abData[1])
*
*
*
cTmp:= DatoExcel2(xData, ValType(xData))
*
FOR nI:= 2 TO nCols
   xData:= Eval(abData[nI])
   *
   *
   cTmp+= EXCEL_CLIP_SEPARA_COLUMNA+;
          DatoExcel2(xData, ValType(xData))
NEXT
*
::cText+= cTmp
*
::AddLine()
*
RETURN NIL
*
*
//-------------------------------------------------------------------------//
METHOD AddLine() CLASS TExcelClipBoard
*
*
#Define nCARACTERES_CLIPBOARD 60000    // ojito con un tamaño excesivo: el ClipBoard hace cosas raras y no graba bien la excel (deja filas con huecos vacias)
*
::nFila++
IF Len(::cText) > nCARACTERES_CLIPBOARD
   *
   ::VaciaClipboard()
   *
ELSE
   ::cText+= EXCEL_CLIP_NUEVA_LINEA
ENDIF
*
#Define REFRESCAR_CADA_LINEAS 20
IF ::oMeter != NIL .AND.;
   Mod(::nFila, REFRESCAR_CADA_LINEAS) == 0
   *
   ::oMeter:Set(::nFila)
ENDIF
*
RETURN NIL
*
//-------------------------------------------------------------------------//
METHOD VaciaClipboard() CLASS TExcelClipBoard
Local oClp
*
*
::oClp:SetText( ::cText )
*
::oHoja:Paste(::oHoja:Cells(::nFilaPaste, 1))                                //Pegamos el texto a Excel
::nFilaPaste:= ::nFila
*
::cText:= INIT_TEXT
*

RETURN NIL
*
*
//-------------------------------------------------------------------------//
METHOD End() CLASS TExcelClipBoard
*
::VaciaClipboard()
*
::oMeter:End()
*
::oClp:End()
::oClp:= NIL
*
RETURN NIL
*
*
*
*
*
//-----------------------------------------------------------------------------------------------------------------
STATIC FUNCTION DatoExcel2(xDato, cType)
Local cDato
*
#Define TO_CARACTER(nDato) ;
      cDato:= AllTrim(Str(nDato)) ;;//, 14, NUMERO_DECIMALES))
      cDato:= StrTran(cDato, ".", ",") // Decimales con coma  (excel en español)
*
DO CASE
   CASE cType == "C"
      cDato:= xDato
      *
      IF Val(cDato) != 0
         // Truco para que el campo caracter (con solo numeros)
         // no lo entienda Excel como numerico, pq para los campos
         // grandes tipo codigo ean los transforma en notacion
         // cientifica, pe, 8400+12e
         cDato+= OEmToAnsi(Chr(255))
      ENDIF
      *
   CASE cType == "N"
      TO_CARACTER(xDato)
      *
   CASE cType == "D"
      cDato:= DToC(xDato)
      *
   CASE .T.
      cDato:= cValToChar(xDato)
ENDCASE
*
RETURN cDato
*

 


Saludos

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Mon Nov 14, 2011 7:23 pm
by carlos vargas
en harbour hay una libreria para crear archivos xml para excel, es extremadamente rapida,
se llama hbxlsxml
ejemplo:
Code: Select all  Expand view

/*
 * $Id: example.prg 17099 2011-10-28 18:34:39Z vouchcac $
 */


/*
 * Harbour Project source code:
 *
 * Copyright 2011 Fausto Di Creddo Trautwein, ftwein@yahoo.com.br
 * www - http://www.xharbour.org http://harbour-project.org
 *
 * Thanks TO Robert F Greer, PHP original version
 * http://sourceforge.net/projects/excelwriterxml/
 *
 * This program is free software; you can redistribute it AND/OR modify
 * it under the terms of the GNU General PUBLIC License as published by
 * the Free Software Foundation; either version 2, OR( at your option )
 * any later version.
 *
 * This program is distributed IN the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General PUBLIC License FOR more details.
 *
 * You should have received a copy of the GNU General PUBLIC License
 * along WITH this software; see the file COPYING.  IF NOT, write TO
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307 USA( OR visit the web site http://www.gnu.org/ ).
 *
 * As a special exception, the Harbour Project gives permission FOR
 * additional uses of the text contained IN its release of Harbour.
 *
 * The exception is that, IF you link the Harbour libraries WITH other
 * files TO produce an executable, this does NOT by itself cause the
 * resulting executable TO be covered by the GNU General PUBLIC License.
 * Your use of that executable is IN no way restricted on account of
 * linking the Harbour library code into it.
 *
 * This exception does NOT however invalidate any other reasons why
 * the executable file might be covered by the GNU General PUBLIC License.
 *
 * This exception applies only TO the code released by the Harbour
 * Project under the name Harbour.  IF you copy code FROM other
 * Harbour Project OR Free Software Foundation releases into a copy of
 * Harbour, as the General PUBLIC License permits, the exception does
 * NOT apply TO the code that you add IN this way.  TO avoid misleading
 * anyone as TO the status of such modified files, you must delete
 * this exception notice FROM them.
 *
 * IF you write modifications of your own FOR Harbour, it is your choice
 * whether TO permit this exception TO apply TO your modifications.
 * IF you DO NOT wish that, delete this exception notice.
 *
 */

/*----------------------------------------------------------------------*/

FUNCTION main()
   LOCAL oXml, oSheet, xarquivo := "example.xml"
   LOCAL i, xqtddoc, xttotnot, xtbascal, xtvlricm, xtbasipi, xtvlripi, aDoc, nLinha
   LOCAL xEmpresa  
   LOCAL xDataImp  
   LOCAL xTitulo    
   LOCAL xPeriodo  
   LOCAL xOrdem
   
   SET DATE TO BRITISH
   
   oXml:= ExcelWriterXML():New(xarquivo)
   oXml:setOverwriteFile(.t.)
     
   WITH OBJECT oXml:addStyle('textLeft')            
      :alignHorizontal('Left')        
      :alignVertical('Center')
      :fontSize(10)
   END WITH
   
   WITH OBJECT oXml:addStyle('textLeftWrap')            
      :alignHorizontal('Left')        
      :alignVertical('Center')              
      :alignWraptext()
      :fontSize(10)
   END WITH
   WITH OBJECT oXml:addStyle('textLeftBold')            
      :alignHorizontal('Left')        
      :alignVertical('Center')
      :fontSize(10)
      :setFontBold()                  
   END WITH
   
   WITH OBJECT oXml:addStyle('textLeftBoldCor')            
      :alignHorizontal('Left')        
      :alignVertical('Center')
      :fontSize(10)
      :setFontBold()                  
      :bgColor('lightblue')                              
      :alignWraptext()
   END WITH
   
   WITH OBJECT oXml:addStyle('textRight')            
      :alignHorizontal('Right')        
      :alignVertical('Center')
      :fontSize(10)
   END WITH
   
   WITH OBJECT oXml:addStyle('textRightBold')            
      :alignHorizontal('Right')        
      :alignVertical('Center')
      :fontSize(10)
      :setFontBold()
   END WITH
   
   WITH OBJECT oXml:addStyle('textRightBoldCor')            
      :alignHorizontal('Right')        
      :alignVertical('Center')
      :fontSize(10)
      :setFontBold()
      :bgColor('lightblue')
      :alignWraptext()
   END WITH
   
   WITH OBJECT oXml:addStyle('numberRight')            
      :alignHorizontal('Right')
      :alignVertical('Center')
      :setNumberFormat('#,##0.00')        
      :fontSize(10)
   END WITH
   
   WITH OBJECT oXml:addStyle('numberRightBold')            
      :alignHorizontal('Right')
      :alignVertical('Center')
      :setNumberFormat('#,##0.00')        
      :fontSize(10)
      :setFontBold()
   END WITH
   
   WITH OBJECT oXml:addStyle('numberRightBoldCor')            
      :alignHorizontal('Right')
      :alignVertical('Center')
      :setNumberFormat('#,##0.00')        
      :fontSize(10)
      :setFontBold()
      :bgColor('lightblue')
   END WITH
   
   WITH OBJECT oXml:addStyle('numberRightZero')            
      :alignHorizontal('Right')
      :alignVertical('Center')
      :setNumberFormat('#,##0.00;[Red]-#,##0.00;;@') //'#,###.00')        
      :fontSize(10)    
      :setFontBold()
   END WITH
   
   WITH OBJECT oXml:addStyle('Cabec')            
      :alignHorizontal('Left')        
      :alignVertical('Center')
      :fontSize(12)
      :setFontBold()
   END WITH
   
   WITH OBJECT oXml:addStyle('CabecRight')            
      :alignHorizontal('Right')        
      :alignVertical('Center')
      :fontSize(12)
      :setFontBold()
   END WITH
   
   oSheet := oXml:addSheet('Plan1')    
   
   WITH OBJECT oSheet
      :columnWidth( 1,  70 ) // N.Fiscal
      :columnWidth( 2,  20 ) // TM
      :columnWidth( 3,  70 ) // Data Movto
      :columnWidth( 4,  70 ) // Data Emis.
      :columnWidth( 5,  50 ) // CFOP
      :columnWidth( 6,  50 ) // C›d. Cliente/Fornecedor
      :columnWidth( 7, 300 ) // Nome Cliente/Fornecedor
      :columnWidth( 8,  20 ) // UF      
      :columnWidth( 9,  80 ) // Vlr.Tot.
      :columnWidth(10,  80 ) // Base Calc.
      :columnWidth(11,  80 ) // Vlr ICMS
      :columnWidth(12,  80 ) // Base IPI
      :columnWidth(13,  80 ) // Valor IPI
   
      xEmpresa:= "EMPRESA DEMONSTRACAO LTDA"
      xDataImp:= "22.03.2011"
      xTitulo := "RELATORIO PARA DEMONSTRAR XML EXCEL"
      xPeriodo:= "01.02.2011 a 28.02.2011"
      xOrdem  := "DATA DE EMISSAO"
     
      nLinha:= 0
     
      :writeString(++nLinha,1,xEmpresa ,'Cabec')  
      :cellMerge(    nLinha,1, 5, 0)
      :writeString(  nLinha,12,"Data:"+xDataImp ,'CabecRight')  
      :cellMerge(    nLinha,12, 1, 0)
      :writeString(++nLinha,1,xTitulo  ,'Cabec')  
      :cellMerge(    nLinha,1, 5, 0)
      :writeString(++nLinha,1,xPeriodo ,'Cabec')  
      :cellMerge(    nLinha,1, 5, 0)
      :writeString(++nLinha,1,xOrdem   ,'Cabec')  
      :cellMerge(    nLinha,1, 5, 0)
   END WITH
   
   WITH OBJECT oSheet  
      :writeString(++nLinha, 1,"N.Fiscal"          ,'textLeftBoldCor' )
      :writeString(  nLinha, 2,"TM"                ,'textLeftBoldCor' )
      :writeString(  nLinha, 3,"Data Movto"        ,'textLeftBoldCor' )
      :writeString(  nLinha, 4,"Data Emis."        ,'textLeftBoldCor' )
      :writeString(  nLinha, 5,"CFOP"              ,'textLeftBoldCor' )
      :writeString(  nLinha, 6,"C›digo"            ,'textLeftBoldCor' )
      :writeString(  nLinha, 7,"Cliente/Fornecedor",'textLeftBoldCor' )
      :writeString(  nLinha, 8,"UF"                ,'textLeftBoldCor' )
      :writeString(  nLinha, 9,"Vlr.Tot."          ,'textRightBoldCor')
      :writeString(  nLinha,10,"Base Calc."        ,'textRightBoldCor')
      :writeString(  nLinha,11,"Vlr ICMS"          ,'textRightBoldCor')
      :writeString(  nLinha,12,"Base IPI"          ,'textRightBoldCor')
      :writeString(  nLinha,13,"Valor IPI"         ,'textRightBoldCor')
   END WITH
   
   aDoc:= {}
   FOR i:= 1 TO 40
      AADD( aDoc,;
           { STRZERO(i,8),;
             "VE",;
             DATE()-49-i,;
             DATE()-50-i,;
             "5.102",;
             STRZERO(i,5),;
             "NOME DO CLIENTE TESTE "+ALLTRIM(STR(i,5,0)),;
             "PR",;
             i*100,;
             i*100*0.90,;
             i*100*0.90*0.12,;
             i*100,;
             i*100*0.10 } )
   NEXT
   
   xqtddoc:= xttotnot:= xtbascal:= xtvlricm:= xtbasipi:= xtvlripi:= 0
   
   FOR i:= 1 TO 40
      WITH OBJECT oSheet
         :writeString(++nLinha, 1,aDoc[i,1],'textLeft')
         :writeString(  nLinha, 2,aDoc[i,2],'textLeft')
         :writeString(  nLinha, 3,DTOC(aDoc[i,3]),'textLeft')
         :writeString(  nLinha, 4,DTOC(aDoc[i,4]),'textLeft')
         :writeString(  nLinha, 5,aDoc[i,5],'textLeft')
         :writeString(  nLinha, 6,aDoc[i,6],'textLeft')
         :writeString(  nLinha, 7,aDoc[i,7],'textLeft')
         :writeString(  nLinha, 8,aDoc[i,8],'textLeft')
         :writeNumber(  nLinha, 9,aDoc[i,9],'numberRight')
         :writeNumber(  nLinha,10,aDoc[i,10],'numberRight')
         :writeNumber(  nLinha,11,aDoc[i,11],'numberRight')
         :writeNumber(  nLinha,12,aDoc[i,12],'numberRight')
         :writeNumber(  nLinha,13,aDoc[i,13],'numberRight')
      END WITH
      xqtddoc++
      xttotnot+= aDoc[i,9]
      xtbascal+= aDoc[i,10]
      xtvlricm+= aDoc[i,11]
      xtbasipi+= aDoc[i,12]
      xtvlripi+= aDoc[i,13]
   NEXT
   
   WITH OBJECT oSheet
      :writeString(++nLinha, 1,"",'textLeft')
      :writeString(  nLinha, 2,"",'textLeft')
      :writeString(  nLinha, 3,"",'textLeft')
      :writeString(  nLinha, 4,"",'textLeft')
      :writeString(  nLinha, 5,"",'textLeft')
      :writeString(  nLinha, 6,"",'textLeft')
      :writeString(  nLinha, 7,"TOTAL ==> "+STR(xqtddoc,5)+" documentos",'textLeftBold')
      :writeString(  nLinha, 8,"",'textLeft')            
      :writeFormula('Number',nLinha,9,'=SUM(R[-40]C:R[-1]C)','numberRightBold')
      //:writeNumber(  nLinha, 9,xttotnot,'numberRightBold')
      :writeNumber(  nLinha,10,xtbascal,'numberRightBold')
      :writeNumber(  nLinha,11,xtvlricm,'numberRightBold')
      :writeNumber(  nLinha,12,xtbasipi,'numberRightBold')
      :writeNumber(  nLinha,13,xtvlripi,'numberRightBold')
   END WITH
   
   oXml:writeData(xarquivo)
   
   RETURN NIL

/*----------------------------------------------------------------------*/

 

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Mon Nov 14, 2011 8:53 pm
by Enrrique Vertiz
hmpaquito, gracias voy a probarlo.
Carlos, uso xHb no Hb, gracias de todas formas.

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Tue Nov 15, 2011 4:18 am
by Willi Quintana
Hola...
xHarbour tambien la tiene:
TXmlDocument()
Creates a new TXmlDocument object.
Syntax
TXmlDocument():new( [<nFileHandle>|<cXmlString>], [<nStyle>] ) --> oTXmlDocument
Arguments
<nFileHandle>
This is a file handle of an XML file to read. It is returned from function FOpen().
<cXmlString>
Instead of a file handle, an XML formatted character string can be passed. If the first parameter is omitted, the object has no XML data, but can be used to add XML nodes and create a new XML file (see example).
<nStyle>
This parameter instructs the TXMlDocument object how to read an XML file and/or how to write XML nodes into a file. #define constants listed in Hbxml.ch are used to specify <nStyle>:
Constants for XML object creation
Constant Value Description
HBXML_STYLE_INDENT 1 Indents XML nodes with one space HBXML_STYLE_TAB 2 Indents XML nodes with tabs HBXML_STYLE_THREESPACES 4 Indents XML nodes with three spaces HBXML_STYLE_NOESCAPE 8 Reads and creates unescaped characters in data sections
Note: when the style HBXML_STYLE_NOESCAPE is set, the textual content enclosed in an opening and closing XML tag is scanned for characters that normally must be escaped in XML. This can lead to a considerable longer time for reading the XML data.
The characters to be escaped are single and double quotes ('"), ampersand (&), and angled brackets (<>). If such characters exist in textual content and are not escaped, a parsing error is generated, unless HBXML_STYLE_NOESCAPE is used.
Return
Function TXmlDocument() creates the object and method :new() initializes it.
Description
The TXmlDocument() class provides objects for reading and creating XML files. XML stands for eXtensible Markup Language which is similar to HTML, but designed to describe data rather to display it. To learn more about XML itself, the internet provides very good free online tutorials. The website www.w3schools.com is is a good place to quickly learn the basics on XML.
A TXmlDocument object maintains an entire XML document and builds from it a tree of TXmlNode() objects which contain the actual XML data. The first XML node is stored in the :oRoot instance variable, which is the root node of the XML tree. Beginning with the root node, an XML document can be traversed or searched for particular data. The classes TXmlIteratorScan() and TXmlIteratorRegEx() are available to find a particular XML node, based on its tag name, attribute or data it contains.

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Tue Nov 15, 2011 7:27 pm
by acuellar
Enrrique
en vez de FileXls hazlo asi:
Code: Select all  Expand view

 #include "FiveWin.ch"
*
Function Main()
 Local oSheet,oBook
   oExcel:=CreateObject( "excel.application" );oExcel:DisplayAlerts=.F.;oBook:=oExcel:Workbooks:Add();oSheet:=oExcel:ActiveSheet
    oSheet:Range( "A1" ):Value ="100.000 REGISTROS";oSheet:Range( "A1:D1" ):HorizontalAlignment := 7
    oSheet:Cells(2,3):Value = Time()
     For I=2 To 100001
          oSheet:Cells(I,2):Value = I-1
     Next I
     oSheet:Cells(I-1,3):Value = Time()
     oExcel:Visible = .T.
Return Nil
 


En mi máquina tarda 1'10" que es bastante rápido para la cantidad de registros.

Saludos,

Adhemar

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Wed Nov 16, 2011 12:08 am
by Enrrique Vertiz
Adhemar, es correcto lo que indicas, asi sale bien, claro que con 1 sola columna demora lo mencionado, con 23 que tengo se toma MUCHISIMO mas tiempo, pero bueno, funciona y es lo mas importante, gracias

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Wed Nov 16, 2011 9:04 pm
by sysctrl2
modificando el ejemplo de Adhemar:

en 65 mil registros tarda 10 segundos,

hay que tomar encuenta que el excel depende de la memoria disponible,

en mi caso con 100 mil registros se cae ya que mi computadora solo tiene 1gb en ram.

dejo el ejemplo utilizando la tecnica que usa xbrowse para enviar a excel.

saludos.


Code: Select all  Expand view

 #include "FiveWin.ch"
*
Function Main()
   Local oSheet
   local oBook
   local oExcel
   local i
   
   local oWait
   
   local nRow := 4
   local nStart := nRow
   local cMemo := ''  
   local oClip
   
   
   WAITON(space(30), @oWait)
   oWait:say(1,1,'Creando el objeto...')
   
   oExcel:=CreateObject( "excel.application" );oExcel:DisplayAlerts=.F.;oBook:=oExcel:Workbooks:Add();oSheet:=oExcel:ActiveSheet
   oSheet:Range( "A1" ):Value ="65 mil REGISTROS";oSheet:Range( "A1:D1" ):HorizontalAlignment := 7
   oSheet:Cells(2,3):Value = Time()
   For I=2 To 65000
      oWait:say(2,1, 'Procesando registro: ' + str(i) + space(10 ))
      //oSheet:Cells(I,2):Value = I-1
      cMemo += ''
      cMemo += chr(9) + str(i-1,10)
      cMemo += CRLF
      nRow++    
     

      if len(cMemo) >= 16000  .or. i = 65000
         oClip := TClipBoard():New()
         oClip:SetText( cMemo )
         oSheet:Cells( nStart, 1 ):Select()
         oSheet:Paste()
         oClip:Clear()
         cMemo       := ""
         nStart   := nRow            
         oClip:End()
      endif              
     
     
      sysrefresh()
   Next I
   oSheet:Cells(I-1,3):Value = Time()
   oExcel:Visible = .T.
   
   waitoff(@oWait)
Return Nil

static function waitOn( cCaption, oWait, cTitle )  //simula un waiton de grump
   LOCAL nWidth
   local lVal := .t.
   local oBrush

   LOCAL   bAction  := { || .t. }
   default cTitle := "Usuario, un momento por favor"
   DEFINE BRUSH oBrush COLOR RGB( 192, 216, 255 )   //rosa


   IF cCaption == NIL
      DEFINE DIALOG oWait ;
         FROM 0,0 TO 12, Len( cTitle ) + 4 ;
         STYLE nOr( DS_MODALFRAME, WS_POPUP ) BRUSH oBrush TRANSPARENT
   ELSE
      DEFINE DIALOG oWait ;
         FROM 0,0 TO 12, Max( Len( cCaption ), Len( cTitle ) ) + 4 ;
         TITLE cTitle ;
         STYLE DS_MODALFRAME BRUSH oBrush TRANSPARENT
   ENDIF

   oWait:cMsg   := cCaption

   nWidth := oWait:nRight - oWait:nLeft

   ACTIVATE DIALOG oWait CENTER ;
      ON PAINT oWait:Say( 1, 0, xPadC( oWait:cMsg, nWidth ) ) ;
      NOWAIT
   sysRefresh()
return (lVal)

static function WaitOff( oWait )
   IF valtype(oWait) <> 'U'  /* waiton has to be called first! */
      oWait:end()
      oWait := NIL
   ENDIF
   sysRefresh()
RETURN NIL
 

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Thu Nov 17, 2011 7:58 am
by hmpaquito
sysctrl,

Se conoce que vd. no ha leido mi post en este mismo hilo. En él he adjuntado una clase que utiliza la técnica clipboard, que simplifica enormemente el manejo de esta tecnica y además la mejora: entre otros no hay por qué crear el objeto clipboard por cada paste.

Saldudos

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Thu Nov 17, 2011 6:53 pm
by Enrrique Vertiz
hmpaquito, un favor he intentado adaptar el ejemplo que envias junto con la clase y me sale un error que es probable sea mio

El error lo bota en esta linea de codigo :

Local nI, nCols:= Len(abData)

Y es :

Error description: Error BASE/1111 Error de argumento: LEN
Args:
[ 1] = U

Entiendo que el problema esta en abData, pero no entiendo porque, ahi coloco Yo todas las columnas que componen la tabla que quiero exportar, es correcto ??, asi lo pongo :

abData:= {;
{|| 80->fec_movimi },;
{|| cAno+"-"+80->mes_movimi },;
{|| 80->cdo_fuente },;
{|| 80->cdo_cuenta },;
{|| alltrim((1->( DbSeek( 80->cdo_cuenta) ), 1->des_cuenta )) },;
{|| cdo_auxili },;
{|| alltrim((2->( DbSeek( 80->cdo_auxili) ), 2->des_cuenta )) },;
{|| subs(80->cdo_auxil2,1,3) },;
{|| alltrim((2->( DbSeek( subs(80->cdo_auxil2,1,3) ) ), 2->des_cuenta )) },;
{|| 80->cdo_auxil2 },;
{|| alltrim((2->( DbSeek( 80->cdo_auxil2) ), 2->des_cuenta )) },;
{|| 80->cdo_auxil3 },;
{|| alltrim((2->( DbSeek( 80->cdo_auxil3) ), 2->des_cuenta )) },;
{|| 80->cdo_usuari};
}

Si me puedes dar una luz te lo agradecere.

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Thu Nov 17, 2011 6:57 pm
by Enrrique Vertiz
Yo mismo me contesto, en el ejemplo al llamar a Dbf2Excel() pones 3 parametros, pero en la funcion recibe 4, faltaba ese parametro, ya esta procesando, veamos el resultado, gracias !!!

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Thu Nov 17, 2011 8:31 pm
by hmpaquito
Enrique,

Puesto el parámetro ! Gracias !

Saludos

Re: Creacion de archivo Excel .XLSX con mas de 100,000 Lineas

PostPosted: Thu Nov 17, 2011 8:56 pm
by sysctrl2
amigo paquito, si mire tu ejemplo,
solo quise agregar algo al ejemplo de athemar,
que bueno que halla mas opciones.
saludos.