PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Using the XLS functions in read/write
  • The XLS file cannot be opened
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Opens an Excel file (xls or xlsx files).
Note: To create an Excel file without using an initial file, all you have to do is create an xlsDocument variable (in this case, xlsOpen is useless).
Versions 16 and later
WINDEVLinux This function is now available for the WINDEV applications in Linux.
WEBDEV - Server codeLinux This function is now available for the WEBDEV sites in Linux.
Linux Only the xlsx format is supported.
New in version 16
WINDEVLinux This function is now available for the WINDEV applications in Linux.
WEBDEV - Server codeLinux This function is now available for the WEBDEV sites in Linux.
Linux Only the xlsx format is supported.
WINDEVLinux This function is now available for the WINDEV applications in Linux.
WEBDEV - Server codeLinux This function is now available for the WEBDEV sites in Linux.
Linux Only the xlsx format is supported.
Example used to open an Excel file while retrieving an integer
doc is xlsDocument
doc = xlsOpen(fExeDir() + ["\"] + "gpac.xls")

IF ErrorOccurred() THEN
Error(ErrorInfo())
RETURN
END

Info("Content of [1,1] cell:", doc[1,1])

xlsClose(doc)
Syntax
<Result> = xlsOpen(<Path of XLS File> [, <Opening Mode>])
<Result>: Integer or xlsDocument variable
  • Name of the xlsDocument variable corresponding to the XLS file. This variable can be used by all the XLS functions. Using this type of variable allows you to modify the XLS documents.
  • Identifier of specified XLS file. This identifier will be used by all the XLS functions. Syntax kept for backward compatibility with version 12. This syntax with identifier can only be used to read the XLS documents: no modification is possible.
The ErrorOccurred variable is set to True if an error occurred and ErrorInfo returns the error details.
<Path of XLS File>: Character string
Full or relative path of XLS file to open (up to 260 characters).
<Opening Mode>: Optional integer constant
Indicates the opening mode of XLS file. By default, the Excel file is opened in read-only by using the multi-worksheet mode of XLS files.
xlsWrite
(Default value)
Opens the Excel file in "Read/Write" mode: the XLS file is opened and locked until it is closed. Caution: the modifications performed in the XLS file will be taken into account only if you are using an xlsDocument variable.
xlsCompatibleUsed to open the Excel file in mode compatible with version 10.
In this mode:
  • A single workbook sheet is supported.
  • Unicode is not supported.
  • The groups of strings are not supported.
  • Some functions (xlsData or xlsNbRow for example) may return inconsistent results.
Warning
From version 11, this constant is available for backward compatibility.
Remarks

Using the XLS functions in read/write

To handle the XLS files in read/write, you must use an xlsDocument variable. This type of variable can also be used to handle the files specific to Office 2007 (.xlsx files) in read/write.
The use of the file identifier is kept for backward compatibility with version 12. The XLS documents (including the ".xlsx" files specific to Office 2007) handled with this identifier cannot be modified (even if the xlsWrite constant is specified).
Example using the syntax kept for backward compatibility:
XLSFileID is int
XLSFileID = xlsOpen(CompleteDir(fExeDir()) + "GPACS.XLS")
IF ErrorOccurred = False THEN
Info("The XLS file was opened")
// Close the file
xlsClose(XLSFileID)
ELSE
Info(ErrorInfo())
END
END

The XLS file cannot be opened

The possible error cases are as follows:
  • The specified XLS file was not found.
  • The specified XLS file does not exist.
  • The specified XLS file cannot be opened.
  • The specified XLS file is invalid.
  • Insufficient memory to open the XLS file.
  • The version of Excel used is unknown or too old (the XLS functions cannot read the files in Excel version 2 or earlier).
To find out the error details, call xlsMsgError (if you are using the syntax compatible with version 12) or ErrorInfo associated with the errMessage constant.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230xls.dll
Linux wd230xls.so
Minimum required version
  • Version 9
This page is also available for…
Comments
Exemplo Ler Excel e Gravar Arquivo

n_abre_excel is int=xlsOpen("nome_excel.xls")
n_numero_linhas is int=xlsNbRow(n_abre_excel)
n_contador is int=0
FOR n_contador = 2 TO n_numero_linhas
HReset(nota_rps_servico)
s_codigo_municipio is string=xlsData(n_abre_excel,n_contador,3)
nota_rps_servico.codigo_municipio=s_codigo_municipio
HAdd(nota_rps_servico)
END
Info("Final da Gravacao")
//-----------------------------------------------------------
//Blog com Video e Exemplo
http://windevdesenvolvimento.blogspot.com.br/2016/01/curso-windev-excel-001-ler-planilha.html
De matos AMARILDO
Feb. 02 2016