PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Reading an XLS file
xlsDocument (Example)
Reading an XLS file
The following code is used to browse all the cells found in the different worksheets of an XLS file.
// File name
sNameExcelFile is string
 
// The file to open is selected by the user
sNameExcelFile = fSelect("", sNameExcelFile, "Specify the Excel file to read", ...
"Excel workbook (*.XLS)" + TAB + "*.XLS" + CR + "All files (*.*)" + TAB + "*.*", ...
"*.XLS", fselOpen + fselExist)
 
// Cancelation?
IF sNameExcelFile = "" THEN RETURN
 
// Opens the file
xlsdoc is xlsDocument
xlsdoc = xlsOpen(sNameExcelFile)
IF ErrorOccurred THEN
Error("Failure opening the Excel workbook", ErrorInfo())
RETURN
END
 
nWorksheetNum is int
nNbWorksheetRows is int
nNbWorksheetColumns is int
nRowNum is int
nColumnNum is int
 
// For each worksheet of the workbook
FOR nWorksheetNum = 1 _TO_ xlsdoc.NumberWorksheet
// Position on the specified worksheet
xlsdoc.Worksheet = nWorksheetNum
// Number of rows
nNbWorksheetRows = xlsdoc.NumberRow
nNbWorksheetColumns = xlsdoc.NumberColumn
// Progress bar
PROGBAR_ProgBar = 0
PROGBAR_ProgBar.MaxValue = nNbWorksheetRows
FOR nRowNum = 1 _TO_ nNbWorksheetRows
PROGBAR_ProgBar++
FOR nColumnNum = 1 _TO_ nNbWorksheetColumns
Trace("Row " + nRowNum + ", Column " + nColumnNum + "=" + ..
xlsdoc.Cell[nRowNum, nColumnNum])
END
END
END
 
Info("Reading completed")
Minimum version required
  • Version 17
This page is also available for…
Comments
Click [Add] to post a comment