Tem que usar essa versão. hbxlsxwriter 1.1.5
Não sei onde baixar.
Código: Selecionar todos
// Begin code.
/*
Test.prg
https://groups.google.com/g/harbour-users/c/zosdM49E5Cs
Using : Windows 10 Family 22H2
Harbour 3.2.0dev (r2104281802)
hbxlsxwriter 1.1.5
Compile with -lhbwin
This code is a basic sample for tests.
*/
// <Parameters>
// Parameters files.
#define BM_FILE_OUT hb_dirbase() + "_Result.txt" // Test result.
#define BM_FILE_XLSX hb_dirbase() + "_Result_Calc.xlsx" // File Excel to create with his path.
// Parameters country and codepage.
#define BM_LANG_REQUEST request HB_LANG_FR
#define BM_LANG_SELECT hb_langSelect( 'FR' )
#define BM_CODE_REQUEST request HB_CODEPAGE_FRWIN
#define BM_CODE_SELECT hb_cdpSelect( 'FRWIN' )
// </Parameters>
#include "hbxlsxwriter.ch"
// Create datas for test.
function DatasCreate()
local aDatas := {}
aadd( aDatas, { "Rent", "diciembre 28 2023", 1000, hb_date( 2023, 12, 28 ) } )
aadd( aDatas, { "Gas" , "febrero 1 2000" , 100, hb_date( 2000, 2, 1 ) } )
aadd( aDatas, { "Food", "enero 17 2024" , 300, hb_date( 2024, 1, 17 ) } )
aadd( aDatas, { "Gym" , "abril 1 2000" , 50, hb_date( 2000, 4, 1 ) } )
return aDatas
procedure Main
local i // Count variable number.
local c // Column num.
local l // Row num.
local aDatas // Datas for test write.
local fBold // Bold format.
local fDate // Date format.
local fMoney // Money format.
local fNum2 // 2 dec format.
local oBook // Book object.
local oSheet // Sheet object.
// Country and codepage.
BM_LANG_REQUEST ; BM_LANG_SELECT
BM_CODE_REQUEST ; BM_CODE_SELECT
set( _SET_CONFIRM , .T. )
set( _SET_WRAP , .T. )
set( _SET_DELETED , .T. )
set( _SET_SCOREBOARD, .F. )
set( _SET_EXACT , .T. )
set( _SET_SOFTSEEK , .T. )
set( _SET_MESSAGE , maxrow() - 1 )
set( _SET_MCENTER , .T. )
set( _SET_DATEFORMAT, "DD/MM/YY" )
set( _SET_EXCLUSIVE , .F. )
set( _SET_CURSOR , 1 )
set( _SET_EPOCH , 1990 )
set( _SET_EOF , .F. )
setmode( 25, 80 )
setcolor( "GR+/B" )
@ 0, 0, maxrow(), maxcol() box space( 9 )
ferase( BM_FILE_OUT )
ferase( BM_FILE_XLSX )
set( _SET_ALTFILE , BM_FILE_OUT )
set( _SET_ALTERNATE, .T. )
? "Test https://groups.google.com/g/harbour-users/c/zosdM49E5Cs"
?
? "hbxlsxwriter version :", lxw_version()
? "Harbour version :", hb_version( 0 )
// Create datas for test.
aDatas := DatasCreate()
// Create a new workbook and add a worksheet.
oBook := workbook_new( BM_FILE_XLSX )
oSheet := workbook_add_worksheet( oBook )
// Create the used numberformats.
fBold := workbook_add_format( oBook )
format_set_bold( fBold )
fDate := workbook_add_format( oBook )
format_set_num_format( fDate, "mm/dd/yyyy" )
fMoney := workbook_add_format( oBook )
format_set_num_format( fMoney, "$#,##0.00" )
fNum2 := workbook_add_format( oBook )
format_set_num_format( fNum2, "#,##0.00" )
// Write titles.
l := 0 ; c := -1
c++ ; worksheet_write_string( oSheet, l, c, "Item" )
c++ ; worksheet_write_string( oSheet, l, c, "Cost" )
c++ ; worksheet_write_string( oSheet, l, c, "Money" )
c++ ; worksheet_write_string( oSheet, l, c, "Date 1" )
c++ ; worksheet_write_string( oSheet, l, c, "Num" )
// Change the columns width for clarity.
worksheet_set_column( oSheet, 0, 0, 16 )
worksheet_set_column( oSheet, 1, 1, 24 )
worksheet_set_column( oSheet, 2, 2, 10 )
worksheet_set_column( oSheet, 3, 3, 12 )
worksheet_set_column( oSheet, 4, 4, 10 )
// Write datas.
for i := 1 to len( aDatas )
l++ ; c := -1
c++ ; worksheet_write_string( oSheet, l, c, aDatas[ i, 1 ] )
c++ ; worksheet_write_string( oSheet, l, c, aDatas[ i, 2 ] )
c++ ; worksheet_write_number( oSheet, l, c, aDatas[ i, 3 ], fMoney )
c++ ; worksheet_write_datetime( oSheet, l, c, aDatas[ i, 4 ], fDate )
c++ ; worksheet_write_number( oSheet, l, c, aDatas[ i, 3 ], fNum2 )
endfor
// Write sum.
l++
c := 0 ; worksheet_write_string( oSheet, l, c, "Total", fBold )
c := 2 ; worksheet_write_formula( oSheet, l, c, "=SUM(" + bh_IntToCell( 2, c + 1 ) + ":" + bh_IntToCell( l, c + 1 ) + ")", fMoney )
c := 4 ; worksheet_write_formula( oSheet, l, c, "=SUM(" + bh_IntToCell( 2, c + 1 ) + ":" + bh_IntToCell( l, c + 1 ) + ")", fNum2 )
// Close the workbook.
workbook_close( oBook )
?
set( _SET_ALTERNATE, .F. )
set( _SET_ALTFILE , "" )
// wapi_ShellExecute( nil, "open", BM_FILE_OUT )
wapi_ShellExecute( nil, "open", BM_FILE_XLSX )
// wait
return
// Tools functions common.
// Convert the row and col to cell name.
function bh_IntToCell( nRow, nCol )
local n := abs( nCol )
local cReturn := ""
do while n > 0
if mod( n, 26 ) == 0 // For character "Z".
cReturn := "Z" + cReturn
n := int( n / 26 ) - 1
else
cReturn := chr( 64 + mod( n, 26 ) ) + cReturn
n := int( n / 26 )
endif
enddo
cReturn += hb_ntos( nRow )
return cReturn
// End code.
Best regards,
Bernard.
Código, extraído do forum Harbour user.
Itamar M. Lins Jr.