FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Creacion de archivos Excel .XLSX grandes de manera rapida
Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Mon Aug 02, 2021 10:16 PM

Estimados, buenas tardes

Para crear archivos excel grandes, uso "oExcel := TOleAuto():New( "Excel.Application" )" y diseño el reporte, columnas, anchos, tipos de letra y demas, todo funciona bien, pero es muy lento en archivos muy grandes, existe alguna opcion distinta que vaya tan rapido como la FILEXLS de avendaño que vuela ??
Gracias.

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Tue Aug 03, 2021 09:03 AM

Hola,

Yo utilizo la tecnica del copy-paste: Se acumula cadenas de lineas y se copian al clipboard y luego se pegan al excel.
Pero tengo entendido, pero no probado, que utilizando un ADO para Excel, debe ir mas rapido.

En todo caso, lo que mata a la exportacion es el formateo casilla a casilla, asi que lo mejor es formatear grandes por rangos, mejor una linea que una celda, mejor muchas lineas que una sola a la vez

Salu2

Posts: 129
Joined: Mon Oct 17, 2005 03:03 AM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Wed Aug 04, 2021 01:51 PM

You can use LibXL, speed is fast!!

line ID: ssbbstw

WeChat ID: ssbbstw
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Thu Aug 05, 2021 03:11 AM

Hola, tiene algun ejemplo de uso de LibXL ?
Saludos

Posts: 582
Joined: Fri Oct 07, 2005 02:17 PM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Thu Aug 05, 2021 03:25 AM

Saludos

Me uno a la consulta, tendras algun ejemplo para poder probar la libreria, es justo lo que estamos buscando.
Gracias

Enrrique Vertiz Pitta

Lima-Peru

xHb 1.23.1026X, Fwh 25.01, BCC74, MySQL 8.0.X, SQLLIB 1.9m
Posts: 129
Joined: Mon Oct 17, 2005 03:03 AM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Thu Aug 05, 2021 08:36 AM
sample:

Code (fw): Select all Collapse
oExcel  := TLibXL():New()
oBook   := oExcel:CreateXMLBook() // create .xlsx
oBook:setLocale('UTF-8') // encode utf8,  oBook:setLocale('en_US.BIG5') // ansi
oSheet := oBook:AddSheet( oQry:FieldGet("CR_COD"))
// Font
oBook:setDefaultFont('細明體',12) // 設定整體字型
//
oFnt1 := oBook:AddFont(); oFnt1:SetName('細明體'); oFnt1:SetSize(12)
oFnt2 := oBook:AddFont(); oFnt2:SetName('細明體'); oFnt2:SetSize(16)
// Format
oFmtR := oBook:AddFormat(); oFmtR:setAlignH( ALIGNH_RIGHT          ) // Horizontal - right
oFmtL := oBook:AddFormat(); oFmtL:setAlignH( ALIGNH_LEFT           ) // Horizontal - left
oFmt1 := oBook:AddFormat(); oFmt1:setNumFormat(NUMFORMAT_TEXT      )
oFmt2 := oBook:AddFormat(); oFmt2:setNumFormat(NUMFORMAT_NUMBER    ) // ex: 1000
oFmt3 := oBook:AddFormat(); oFmt3:setNumFormat(NUMFORMAT_NUMBER_D2 ) // ex: 1000.00
// create format formula '0.0'
nFmtD1 := oBook:AddCustomNumFormat("0.0")
oFmtD1 := oBook:AddFormat(); oFmtD1:setNumFormat(nFmtD1) // ex: 1000.0
//
lPtHead := .T.
nRow    := 1
//
Do While ! oQry:Eof()
   //
   If lPtHead
      //
      lPtHead := .F.
      //
      nRow := 1
      oSheet:writeStr( nRow, 1, '客戶訂貨單')
      // oSheet:setMerge( 1, 1, 1, Len(aHD) ) // merge
      //
      nRow += 1
      oSheet:writeStr( nRow, 1, "CustName: "+RTrim( oQry:FieldGet("CT_CAM"))+"("+RTrim( oQry:FieldGet("CT_NUM"))+")" )
      //
      nRow += 1
      oSheet:writeStr( nRow, 1, "Order NO: "+RTrim( oQry:FieldGet("CR_COD")))
      // Print Head
      nRow += 1
      For nI := 1 To Len( aHD )
          If aHD[nI, 3] == 'N' // Number, align-right
             oSheet:SetCol(nI, nI, aHD[nI, 2], oFmtR ) // oExcel:Columns( nI ):HorizontalAlignment := xlRight // 靠右
          Else
             oSheet:SetCol(nI, nI, aHD[nI, 2], oFmtL ) // oExcel:Columns( nI ):HorizontalAlignment := xlLeft  // 靠左
          EndIf
          //
          oSheet:writeStr( nRow, nI, aHD[nI, 1] ) // oExcel:Cells( nRow,  nI ):Value := aHD[nI, 1]
      Next nI
      //
   EndIf
   //
   nRow += 1
   //----------------------------
   nCol := 0
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_NOT"))        )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("CR_ONB")), oFmt2 )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_NAM"))        )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_AUT"))        )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("FM_DAM"))        )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_COD")), oFmt1 )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_ISB")), oFmt1 )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_CIP"))        )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("CR_AMO"), oFmt2         )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("PD_DMN"), oFmt2         )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("PD_TDM"), oFmt2         )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("CR_JER"), oFmt3         )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("CR_DMN"), oFmt3         )
   If Empty(oQry:FieldGet("PD_ODT"))
      cData := ''
   Else
      cData := TransForm( oQry:FieldGet("PD_ODT"), "@R 999.99.99" )
   EndIf
   oSheet:writeStr( nRow, ++nCol, cData )
   If Substr( ::cLimPrd, 3, 1 ) == '1'
      oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_FCO")), oFmt1 ) // oExcel:Cells( nRow, 15 ):NumberFormat := [@]       ;
      oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("FM_DA2"))        )
      oSheet:writeNum( nRow, ++nCol,        oQry:FieldGet("PD_FYJ") , oFmt3 ) // oExcel:Cells( nRow, 17 ):NumberFormat := [#,##0.00];
   EndIf
   //
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_VER"))    )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_CNT"))    )
   oSheet:writeStr( nRow, ++nCol, TrLnuPrd( oQry:FieldGet("PD_LNU")) )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_BID"))    )
   oSheet:writeStr( nRow, ++nCol, TrPkgPrd( oQry:FieldGet("PD_PKG")) )
   oSheet:writeStr( nRow, ++nCol, TrTfsPrd( oQry:FieldGet("PD_TFS")) )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("PD_PKN"), oFmt2     )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_BCO"))    )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_BC2"))    )
   oSheet:writeStr( nRow, ++nCol, TrRadPrd( oQry:FieldGet("PD_RAD")) )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("PD_HGH"), oFmtD1    )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("PD_WDH"), oFmtD1    )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("PD_LGH"), oFmtD1    )
   oSheet:writeNum( nRow, ++nCol, oQry:FieldGet("PD_PAG"), oFmt2     )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_ARE"))    )
   oSheet:writeStr( nRow, ++nCol, RTrim( oQry:FieldGet("PD_TAK"))    )
   //
   oQry:Skip()
   //
EndDo
//
oQry:End()
// Get temp file and save
Do While .T.
   If ! File( cPath + ( cXLS := cNetFile + PadL( Int( nRandom( 9999 )), 4, "0" )+".xlsx" ))
      oBook:Save(AllTrim(cPath+cXLS))
      oBook:End()
      Exit
   EndIf
EndDo
oExcel:End() // Close
SysRefresh() // Speed too fast, Need add this
line ID: ssbbstw

WeChat ID: ssbbstw
Posts: 98
Joined: Sat Dec 03, 2016 02:49 PM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Mon Aug 09, 2021 07:26 PM

Hola:

Donde se encuentra esa libreria TLibXL, es de fivewin o de terceras personas,
me puedes dar mas informacion por favor, gracias.

Esta disponible el codigo fuente o mas informacion.

Posts: 129
Joined: Mon Oct 17, 2005 03:03 AM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Tue Aug 10, 2021 01:57 AM

libxl is commercial software.
TLibxl is a class, you can search from the Internet.

line ID: ssbbstw

WeChat ID: ssbbstw
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Thu Aug 12, 2021 07:04 AM
Con HDO se pueden tratar los XLSX por medio de ODBC.
Mira este ejemplo:

Code (fw): Select all Collapse
/*
 * Proyecto: hdo_general
 * Fichero: ej37_xls_rs.prg
 * Descripci�n:
 * Autor:
 * Fecha: 11/04/2020
    Se necesita {Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}
    Descargarlo desde:
    <!-- m --><a class="postlink" href="http://www.microsoft.com/en-us/download/details.aspx?id=13255">http://www.microsoft.com/en-us/download ... x?id=13255</a><!-- m -->
    o en espa�ol aqui
    <!-- m --><a class="postlink" href="https://www.microsoft.com/es-ES/download/details.aspx?id=13255">https://www.microsoft.com/es-ES/downloa ... x?id=13255</a><!-- m -->
 */

//------------------------------------------------------------------------------

#include "hdo.ch"

REQUEST RDLODBCN

//------------------------------------------------------------------------------
// Programa principal

procedure main

    TApp():new( "contacts.xls", "Hoja1" )

return

//------------------------------------------------------------------------------
// Clase aplicacion

CLASS TApp

    DATA oXLS
    DATA oSheet

    METHOD new( cXLS, cSheet ) CONSTRUCTOR
    METHOD end()

ENDCLASS

//------------------------------------------------------------------------------
// Constructor de la clase

METHOD new( cXLS, cSheet ) CLASS TApp

    local e

    if ValType( cXLS ) == 'C' .and. File( cXLS )
        cXLS := AllTrim( cXLS )
        // Creamos el objeto XLS
        ::oXLS := THDO():new( "odbcn" )
        ::oXLS:setAttribute( HDO_ATTR_DEF_STR_PAD, .t. )
        try
            // Intenta crear los objetos XLS y hoja
            ::oXLS:connect( "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};Dbq=./" + cXLS + ";" )
            ::oSheet := ::oXLS:rowSet( "SELECT * FROM " + "[" + AllTrim( cSheet ) + "$]" )
            ::oSheet:load()
            simpleBrowse( ::oSheet, "Mirando la Hoja1" )
        catch e
            // Gestion del error aqui uso el estandar de harbour
            eval( errorBlock(), e )
        finally
            // Cierre automatico en caso de error
            ::end()
        end
    else
        alert( "No se ha pasado un fichero excel" )
    endif

return Self

//------------------------------------------------------------------------------
// Libera recursos

PROCEDURE end() CLASS TApp

    //libera los objetos en orden inverso a su creacion

    if ValType( ::oSheet ) == 'O'
        ::oSheet:free()
    endif

    if ValType( ::oXLS ) == 'O'
        ::oXLS:free()
    endif

    msg( "FIN" )
return

//------------------------------------------------------------------------------
______________________________________________________________________________

Sevilla - Andalucía
Posts: 129
Joined: Mon Oct 17, 2005 03:03 AM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Tue Dec 21, 2021 01:21 AM
carito wrote:Hola:

Donde se encuentra esa libreria TLibXL, es de fivewin o de terceras personas,
me puedes dar mas informacion por favor, gracias.

Esta disponible el codigo fuente o mas informacion.


http://www4.zzz.com.tw/phpBB3/viewtopic ... p=391#p391

include source code.
line ID: ssbbstw

WeChat ID: ssbbstw
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Tue Dec 21, 2021 11:21 AM

Good morning ssbbstw, could you please provide an example translated from Chinese to English? Thanks.

Buenos días ssbbstw, ¿podría proporcionar un ejemplo traducido del chino al inglés? Gracias.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 129
Joined: Mon Oct 17, 2005 03:03 AM
Re: Creacion de archivos Excel .XLSX grandes de manera rapida
Posted: Tue Dec 21, 2021 03:33 PM
karinha wrote:Good morning ssbbstw, could you please provide an example translated from Chinese to English? Thanks.

Buenos días ssbbstw, ¿podría proporcionar un ejemplo traducido del chino al inglés? Gracias.

Regards, saludos.


You can use Google Translate.
line ID: ssbbstw

WeChat ID: ssbbstw

Continue the discussion