LibXL and harbour

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

LibXL and harbour

Post by AUGE_OHR »

hi,

did somebody use LibXL ( http://www.libxl.com ) with harbour :?:
have fun
Jimmy
User avatar
mol
Posts: 3774
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: LibXL and harbour

Post by mol »

I'm using xmlxclass.prg for reading Excel files.
It's possible to use it to write data to xlsx
Attachments
XLSXClass.zip
(11.31 KiB) Downloaded 537 times
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: LibXL and harbour

Post by AUGE_OHR »

hi Mol,

thx for Answer, i will try it
have fun
Jimmy
User avatar
mol
Posts: 3774
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: LibXL and harbour

Post by mol »

I can post a piece of my code using it if you want...
Georg_BA
Posts: 108
Joined: Fri Apr 07, 2017 5:31 pm
DBs Used: DBF

Re: LibXL and harbour

Post by Georg_BA »

Hello MOL

if you provide an example of use, I will be happy to study it
there are 2-3 different xlsx versions here on the forum

I'm mainly interested in reading xlsx, xls

Best regards, George
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: LibXL and harbour

Post by AUGE_OHR »

hi,
mol wrote: Sat May 13, 2023 6:17 am I can post a piece of my code using it if you want...
every Sample of CODE can help, thx

Question : can you run > 100000 Row :?:
have fun
Jimmy
User avatar
mol
Posts: 3774
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: LibXL and harbour

Post by mol »

AUGE_OHR wrote: Sat May 13, 2023 8:44 pm hi,
mol wrote: Sat May 13, 2023 6:17 am I can post a piece of my code using it if you want...
every Sample of CODE can help, thx

Question : can you run > 100000 Row :?:
I don't know limits. I'll try to post piece of my code tomorrow
User avatar
mol
Posts: 3774
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: LibXL and harbour

Post by mol »

Piece of my code to get data from sheet

Code: Select all

function PobierzFakture

    local cPlik
	local oExcel := NIL
	local oSheet1 := NIL
	local w, i, k
	local aKonwersja := { => }
	local cKolumna := ""
	local nKolumnaDaty := 0
	local aKeys := {}
	local nCzasKonwersji := hb_MilliSeconds()
	local dDataPozycji := 0d0
	local xDane
	local cTyp
	
	OknoGlowne.B_Faktury.ItemCount := 0
	OknoGlowne.B_Pozycje.ItemCount := 0
	ahFaktury := {=>}
	aFaktury := {}
	aPozycje := {}
	
	aKonwersja := { ;
		"DOSTAWA"                       => { "NrSklepu" , 0, .t.},;
		"NR FRY"                        => { "NrFaktury", 0, .t.},;
		"EAN"                           => { "EAN"      , 0, .t.},;
		"NAZWA"                         => { "Nazwa"    , 0, .f.},;
		"ILOSC"                         => { "Ilosc"    , 0, .t.},;
		"WARTOSC"                       => { "WartNetto", 0, .t.},;
		"VAT"                           => { "WartVAT"  , 0, .f.},;
		"STARYKOD"                      => { "OldMatNum", 0, .f.},;
		"RRP"                           => { "RRP"      , 0, .f.},;
		"NAZWA1"                        => { "Nazwa1"   , 0, .f.} ;
	}
	
	aKeys := hb_hKeys(aKonwersja)
	
    if !empty(cPlik:=GetFile( { {'Arkusz nowy format Excel XLSX','*.xlsx'} },'Wybierz plik z fakturą' , cFolderOdczytu, .f. , .t. ) )
       OknoGlowne.T_Plik.Value := cPlik
	   cFolderOdczytu := HB_FNameDir(cPlik)

		BEGIN INI FILE "konwerter.ini"
			SET SECTION "KONWERTER" ENTRY "FolderOdczytu" TO cFolderOdczytu
		END INI

	else
		return .f.
	endif
	
	pozycje->(DBZapArea())
	
	//WlaczWaitWindow("Trwa pobieranie faktur. Operacja może potrwać długo...")
	OknoGlowne.L_Status.Value := "Trwa pobieranie faktur. Operacja może potrwać długo..."
	OknoGlowne.L_Status.FontColor := {255,0,0}

	OknoGlowne.B_Pozycje.ItemCount := 0
	OknoGlowne.B_Faktury.ItemCount := 0
	
	oExcel := WorkBook():New()
	BEGIN SEQUENCE with {||break()}
		oExcel:Read(cPlik)
	RECOVER
		OknoGlowne.L_Status.Value := "Błąd podczas odczytu pliku XLSX z fakturami. Być może jest za długi?"
		MsgStop("Błąd podczas odczytu pliku XLSX z fakturami. Być może jest za długi?")
		return .f.
	END SEQUENCE
	
	BEGIN SEQUENCE with {||break()}
		cSheet1Name := oExcel:aWorkSheetNames[1]
		oSheet1:= oExcel:WorkSheet(cSheet1Name)
	RECOVER
		OknoGlowne.L_Status.Value := "Brak dostępu do arkusza z fakturą w pliku XLSX. Operacja przerwana"
		MsgStop("Brak dostępu do arkusza z fakturą w pliku XLSX. Operacja przerwana")
		return .f.
	END SEQUENCE
	
	nLiczbaWymaganychPol := 0
	for each cKolumna in hb_hKeys(aKonwersja)
		// musimy wyzerować indeksy odszukanych pól z poprzedniej pętli
		aKonwersja[ cKolumna ][2] := 0
		if aKonwersja[ cKolumna ][3] == .T.
			nLiczbaWymaganychPol++
		endif
	next
	
	// przypisujemy numery kolumn w arkuszu do poszczególnych pól
	
	for k:=1 to len(oSheet1:aData[1])
		if !empty(oSheet1:aData[1,k])
			cKolumna := upper(hb_UTF8ToStr(oSheet1:aData[1, k]))
			// 20210928 if cKolumna == "BILLING DATE"
			if cKolumna == "DATA"
				nKolumnaDaty := k
			endif
			if hb_hPos(aKonwersja, cKolumna) > 0
				aKonwersja[ cKolumna ][2] := k
				if aKonwersja[ cKolumna ][3] == .T.
					nLiczbaWymaganychPol--
				endif	
			endif
		endif
	next k

	if nKolumnaDaty == 0
		MsgStop("W wybranym pliku XLSX z fakturą nie odnaleziono daty dokumentu. Operacja przerwana!")
		return .f.
	endif
	
	if nLiczbaWymaganychPol>0
		MsgStop("W wybranym pliku XLSX z fakturą nie odnaleziono wszystkich wymaganych kolumn do konwersji. Operacja przerwana!")
		return .f.
	endif
	
	w := 2
	k := 1
	aPozycje := {}
	
	select("pozycje")
	for w:=2 to len(oSheet1:aData)
		if empty( oSheet1:aData[w, 1] )
			exit
		endif
		append blank
		for each cKolumna in aKeys
			k := aKonwersja[ cKolumna ][2]
			if k>0
				// kolumna do zaimportowania
				xDane := oSheet1:aData[w, k]
				cPole := aKonwersja[ cKolumna ][1]
				cTyp := valtype(&cPole)
				if (cTyp == "N") .and. (valtype(xDane) == "C")
					xDane := val(xDane)
				endif

				begin sequence with {||break()}
				replace;
					&cPole	with xDane
				recover
					MsgInfo("Błąd w wierszu: "+hb_ntos(w)+chr(10)+;
					"Pominięto pole: "+cPole+" z odczytaną wartością " +hb_valtoexp(xDane))
				end sequence
			endif
		next i
		
		if hb_hPos(ahFaktury, pozycje->NrFaktury ) == 0
			dDataPozycji := stod("19000101") + oSheet1:aData[w, nKolumnaDaty] - 2
			
			ahFaktury[ pozycje->NrFaktury ] := {	pozycje->NrSklepu,;
													pozycje->NrFaktury,;
													dDataPozycji,;
													0,;
													0,;
													0,;
													0 }
		endif
		
		ahFaktury[ pozycje->NrFaktury ][4]	+= pozycje->(WartNetto+WartVAT)
		ahFaktury[ pozycje->NrFaktury ][5]	+= pozycje->WartNetto
		ahFaktury[ pozycje->NrFaktury ][6]	+= pozycje->WartVAT
		ahFaktury[ pozycje->NrFaktury ][7]	+= 1
	next w
	
	aFaktury := {}
	cFaktura := ""
	for each cFaktura in hb_hKeys(ahFaktury)
		aAdd(aFaktury, ahFaktury[cFaktura])
	next
		
	OknoGlowne.B_Faktury.ItemCount := len(ahFaktury)
	
	f := min(1,len(ahFaktury))
	OknoGlowne.B_Faktury.Value := f
		
	oSheet1 := NIL
	oExcel := NIL
	//WAIT CLEAR
	nCzasKonwersji := (hb_MilliSeconds() - nCzasKonwersji)/1000
	OknoGlowne.L_Status.Value := "Zaimportowano faktury, czas wykonania: "+ hb_ntos(nCzasKonwersji)+" sek."
	OknoGlowne.L_Status.FontColor := {0,128,0}

return
Red2
Posts: 281
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: LibXL and harbour

Post by Red2 »

Hi Mol,

Can the Harbour code in your XLSXClass.zip be adapted for "Official" HMG.
It seem incompatible "as is" in 3.4.4.

The Problem:
The current hblibxlsxwriter solution I use is apparently 32-bit only.
I want to find some (non VBA) solution to create/write an .XLSX file from within the new 64-bit HMG.3.6.
Anyone's ideas would be most greatly appreciated.

======================================================
¿Se puede adaptar el código Harbour en su XLSXClass.zip para "Official" HMG?
Parece incompatible "tal cual" en 3.4.4.

El problema:
La solución hblibxlsxwriter actual que uso aparentemente es solo de 32 bits.
Quiero encontrar alguna solución (non VBA) para crear/escribir un archivo .XLSX desde el nuevo 64-bit HMG.3.6.

Las ideas de cualquiera serían muy apreciadas.

Thank you!
User avatar
mol
Posts: 3774
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: LibXL and harbour

Post by mol »

It's harbour code so it shouldn't be problem.
My main computer is out of order and I'm sending it today to hp service.
Post Reply