PC SOFT
ONLINE REPOSITORY
FOR WINDEVWEBDEV AND WINDEV MOBILE

Home |  | Sign in | English US
 WD The Excel functions
Published by Boller
in the category Tools
New features



Description
WD The Excel functions

Import
********

nFileID is int // identifier of the Excel file
nColumn is int // current column
nRow is int // current line
nFirstLine is int // first row to read
sLine is string // content of current line
nNbLines is int // number of rows in the Excel table
nNbColumns is int // number of columns in the Excel table
sFileName is string // name of XLS file
sData is string

IF EDIT_FILE~="" THEN
Error("Select an Excel file!")
RETURN
END

// name of XLS file
sFileName = EDIT_FILE

HourGlass(True)

// check the existence of the file
IF fSize(sFileName)<=0 THEN
Error("Unable to find the specified file")
RETURN
END

// try to open the file
nFileID = xlsOpen(sFileName)
IF nFileID=-1 THEN
Error("Unable to open the file.",...
"Check whether it is not already opened on another application.",xlsMsgError(nFileID))
RETURN
END

// clear the table
TableDeleteAll(TableImport)

// initialize the name of the columns
FOR nColumn=1 TO COLNB
TableImport[1][nColumn]..Caption = ""
{"Column"+nColumn,indControl}..Visible=True
END

// number of rows and columns in the Excel table
nNbLines = xlsNbRow(nFileID)
nNbColumns = xlsNbColumn(nFileID)

// if the first row contains the column titles
IF CBox_Title[1] = True THEN
// modify the column titles
FOR nColumn=1 TO nNbColumns
TableImport[1][nColumn]..Caption = xlsData(nFileID, 1, nColumn)
END

// first row containing the data
nFirstLine = 2

ELSE
// first row containing the data
nFirstLine = 1
END

// fill the memory table
FOR nRow = nFirstLine TO nNbLines

sLine = ""
TableAddLine(TableImport)

// build the line read
FOR nColumn = 1 TO nNbColumns
sData = xlsData(nFileID, nRow, nColumn, False)
{"Column"+nColumn,indControl}[TableCount(TableImport)]= sData

// if it is a numeric
IF NumToString(Val(sData))=sData THEN
{"Column"+nColumn,indControl}..HorizontalAlignment=iRight
ELSE
{"Column"+nColumn,indControl}..HorizontalAlignment=iLeft
END
END
END

// the other columns are invisible
FOR nColumn = nNbColumns+1 TO COLNB
{"Column"+nColumn,indControl}..Visible=False
END
WinRedraw()

// close the file
xlsClose(nFileID)

HourGlass(False)

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

Export
********

IF EDIT_FILE~="" THEN
Error("Select an Excel file!")
RETURN
END

// if the table is empty
IF TableCount(TableImport)=0 THEN
IF YesNo("The table is empty. Do you want to overwrite the Excel worksheet?")=No RETURN

END

HourGlass(True)

bCR is boolean // status report of operation

// export to an Excel file
// if the title is required
IF CBox_Title[1] = True THEN
bCR = TableToExcel(TableImport, EDIT_FILE, taColumnsTitles)
ELSE
bCR = TableToExcel(TableImport, EDIT_FILE, taNoTitle)
END

IF bCR=False THEN
Error("The Excel file cannot be created.")
ELSE
Info("Export completed")
END

HourGlass(False)
Illustrations, screen shots
none
none
User reviews
(To evaluate this resource, click 'Write a review')
No review or comment? Be the first one!