I'm trying to use the LibXl dll library for writing an excel file, but I'm having a problem with numbers, that are not written in the file.
Anyone has tried to use this library ?
I'm using Xhb.com
Thanks a lot.
Massimo
- Code: Select all Expand view
#include "fivewin.ch"
#include "ord.ch"
STATIC hLib
PROCEDURE MAIN
LOCAL book, sheet, riga, font1, formato1
LOCAL xFont_Text1, xFont_Text2
LOCAL xfrm1, xf1, format1
LOCAL xfrm2, xf2, format2
LOCAL xfrm3, xf3, format3
set date italian
hLib = LOADLIBRARY("LIBXL.DLL")
book = xlCreateBook()
If book # 0
xFont_Text1 = xlBookAddFont( Book ) ; xlFontSetName( xFont_Text1 , "Arial" ) ; xlFontSetSize( xFont_Text1 , 9 )
xFont_Text2 = xlBookAddFont( Book ) ; xlFontSetName( xFont_Text2 , "Arial" ) ; xlFontSetSize( xFont_Text2 , 10 ) ; xlFontBold(xFont_Text2)
xFont_Text3 = xlBookAddFont( Book ) ; xlFontSetName( xFont_Text3 , "Arial" ) ; xlFontSetSize( xFont_Text1 , 9 )
xfrm1 = "###.###.###,##0"
xf1 = xlBookAddCustomNumFormat( Book , xfrm1 )
format1 = xlBookAddFormat( Book )
xlFormatSetNumFormat( format1, xf1 )
xlFormatSetFont( format1, xFont_text1 )
format2 = xlBookAddFormat( Book )
xlFormatSetFont( format2, xFont_text2 )
format3 = xlBookAddFormat( Book )
xlFormatSetFont( format2, xFont_text3 )
sheet = xlBookAddSheet(book, "Sheet1", 0)
use "EMPLOYEE" NEW ALIAS nomi
dbgotop()
riga = 0
xlSheetWriteStr(sheet, riga, 0, "Nome", format2)
xlSheetWriteStr(sheet, riga, 1, "Cognome", format2)
xlSheetWriteStr(sheet, riga, 2, "Indirizzo", format2)
xlSheetWriteStr(sheet, riga, 3, "Città", format2)
xlSheetWriteStr(sheet, riga, 4, "Stato", format2)
xlSheetWriteStr(sheet, riga, 5, "C.A.P.", format2)
xlSheetWriteStr(sheet, riga, 6, "Data nascita", format2)
xlSheetWriteStr(sheet, riga, 7, "Sposato", format2)
xlSheetWriteStr(sheet, riga, 8, "Età", format2)
xlSheetWriteStr(sheet, riga, 9, "Stipendio", format2)
do while !eof()
riga ++
xlSheetWriteStr(sheet, riga, 0, nomi->FIRST, format3)
xlSheetWriteStr(sheet, riga, 1, nomi->LAST, format3)
xlSheetWriteStr(sheet, riga, 2, nomi->STREET, format3)
xlSheetWriteStr(sheet, riga, 3, nomi->CITY, format3)
xlSheetWriteStr(sheet, riga, 4, nomi->STATE, format3)
xlSheetWriteStr(sheet, riga, 5, nomi->ZIP, format3)
xlSheetWriteStr(sheet, riga, 6, dtoc(nomi->HIREDATE), format3)
xlSheetWriteStr(sheet, riga, 7, iif(nomi->MARRIED,"X"," "), format3)
xlSheetWriteNum(sheet, riga, 8, nomi->AGE, format1) <--- here is the problem
xlSheetWriteNum(sheet, riga, 9, nomi->SALARY, format1) <--- here is the problem
dbskip()
enddo
nomi->(dbclosearea())
xlSheetSetAutoFitArea(sheet, 0, 0, riga, 5)
xlBookSave(book, "example.xls")
xlBookRelease(book)
EndIf
freelibrary(hLib)
msginfo("Finito")
quit
DLL32 Function xlBookSetKey(bookHandle As LONG, nome As LPSTR, chiave As LPSTR) AS LONG PASCAL FROM "xlBookSetKeyA" Lib hlib
DLL32 Function xlCreateBook() AS LONG PASCAL FROM "xlCreateBookA" LIB hlib
DLL32 Function xlBookAddSheet(bookHandle As LONG, name As LPSTR, sheetHandle As LONG) AS LONG PASCAL FROM "xlBookAddSheetA" Lib hlib
DLL32 Function xlSheetWriteStr(sheetHandle As LONG, riga As LONG, colonna As LONG, valore As LPSTR, formatHandle As LONG) AS VOID PASCAL FROM "xlSheetWriteStrA" Lib hlib
DLL32 Function xlSheetWriteNum(sheetHandle As LONG, riga As LONG, colonna As LONG, valore As LONG, formatHandle As LONG) AS VOID PASCAL FROM "xlSheetWriteNumA" Lib hlib
DLL32 Function xlBookInsertSheet(bookHandle As LONG, indice As LONG, name As LPSTR, sheetHandle As LONG) As LONG PASCAL FROM "xlBookInsertSheetA" Lib hlib
DLL32 Function xlBookDelSheet(bookHandle As LONG, indice As LONG) As LONG PASCAL FROM "xlBookDelSheetA" Lib hlib
DLL32 Function xlBookSave(bookHandle As LONG, filename As LPSTR) AS VOID PASCAL FROM "xlBookSaveA" Lib hlib
DLL32 Function xlBookRelease(bookHandle As LONG) As LONG PASCAL FROM "xlBookReleaseA" Lib hlib
DLL32 Function xlSheetSetAutoFitArea(sheetHandle As LONG, rowFirst As LONG, colFirst As LONG, rowLast As LONG, colLast As LONG) AS VOID PASCAL FROM "xlSheetSetAutoFitAreaA" Lib hlib
DLL32 Function xlBookAddFont(bookHandle As LONG, fontHandle As LONG) AS LONG PASCAL FROM "xlBookAddFontA" Lib hlib
DLL32 Function xlFontSetName(fontHandle As LONG, nome As LPSTR) AS LONG PASCAL FROM "xlFontSetNameA" Lib hlib
DLL32 Function xlFontSetSize(fontHandle As LONG, size As LONG) AS VOID PASCAL FROM "xlFontSetSizeA" Lib hlib
DLL32 Function xlFontSetBold(fontHandle As LONG, bold As LONG) AS VOID PASCAL FROM "xlFontSetBoldA" Lib hlib
DLL32 Function xlFontBold(fontHandle As LONG) AS LONG PASCAL FROM "xlFontBoldA" Lib hlib
DLL32 Function xlBookAddCustomNumFormat (bookHandle As LONG, customNumFormat As LPSTR) AS LONG PASCAL FROM "xlBookAddCustomNumFormatA" Lib hlib
DLL32 Function xlBookAddFormat(bookHandle As LONG, formatHandle As LONG) AS LONG PASCAL FROM "xlBookAddFormatA" Lib hlib
DLL32 Function xlFormatSetNumFormat(formatHandle As LONG, numFormat As LONG) AS VOID PASCAL FROM "xlFormatSetNumFormatA" Lib hlib
DLL32 Function xlFormatSetFont(formatHandle As LONG, fontHandle As LONG) AS LONG PASCAL FROM "xlFormatSetFontA" Lib hlib
DLL32 Function xlBookSetDefaultFont(bookHandle As LONG, fontName As LPSTR, fontSize As LONG) AS VOID PASCAL FROM "xlBookSetDefaultFontA" Lib hlib