PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Overview
  • Method 1: Handling the XLS and XLSX files dynamically
  • Method 2: Reading the Excel files (method kept for backward compatibility)
  • WLanguage functions
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
Overview
WINDEV et WEBDEV propose two methods for handling the Excel files:
  • Method 1: Handling the XLS and XLSX worksheets dynamically
    This method is using different types of variables as well as WLanguage functions. This method allows you to manage the Excel files (XLS or XLSX files) in read and write mode.
  • Method 2 (kept for backward compatibility): Using the WLanguage functions to manage the XLS functions.
    This method allows you to manage the XLS files in read mode.
Method 1: Handling the XLS and XLSX files dynamically
To handle the XLS and XLSX files, the WLanguage proposes:
  • different types of variables. These types of variables are used to handle an XLS document, an XLS row or column, an XLS cell.
  • several WLanguage functions that handle the different types of data.
To handle the XLS and XLSX files:
  1. Declare an xlsDocument variable. This type of variable is used to describe and modify an Excel document.
  2. Open the XLS file if necessary (xlsOpen) and associate it with the xlsDocument variable.
  3. The different elements found in the Excel document can be handled:
    • by the WLanguage functions.
    • by the xlsDocument properties.
Example:
XLSFileID is xlsDocument
AFile is string
AFile = fExeDir + "\Business info1.xls"

XLSFileID = xlsOpen(AFile, xlsWrite)
IF ErrorOccurred = False THEN
Azz is int = xlsCurrentWorksheet(XLSFileID)
Info("Current worksheet in the Excel file: " + Azz)
// Change worksheet
IF xlsCurrentWorksheet(XLSFileID, 2) THEN
Info("The current worksheet was modified.")
// Read a cell for test
Info(xlsData(XLSFileID, 11, 2))
ELSE
Error("The selected file does not include a second worksheet!")
END
ELSE
Error("Caution, the file is already opened on a computer!")
END
Notes:
  • If the Excel file is opened in read/write mode (xlsWrite constant), the file is opened and locked until it is closed. To save the modifications performed, use xlsSave.
  • The XLS functions do not require "Microsoft Excel" to be installed on the user computers.
  • The XLS files and the files specific to Office 2007 (.xlsx files) are supported.
Related Examples:
XLS Type Unit examples (WINDEV): XLS Type
[ + ] Handling the xlsDocument, xlsColumn, xlsRow and xlsCell variables.
The purpose of this example is to explain how these types of variables can be easily handled.
Method 2: Reading the Excel files (method kept for backward compatibility)
WINDEV and WEBDEV propose several functions allowing you to manage your ".XLS" files from your WINDEV applications and from your WEBDEV sites. These functions allow you to retrieve the data entered in Excel.
To handle an XLS document:
  1. Use xlsOpen. This function returns the identifier of the XLS file used.
  2. Use the XLS functions to retrieve the requested information about the Excel file and its data.
Notes:
  • The XLS functions do not require "Microsoft Excel" to be installed on the user computers.
  • Only the XLS files are supported. The files specific to Office 2007 (.xlsx files) are not supported.
  • Two operating modes are available for the XLS functions:
    • Operating mode compatible with the earlier versions of WINDEV and WEBDEV: in this mode, only the first worksheet of the workbook can be accessed.
    • New multi-sheet operating mode: in this mode, you have the ability to select the worksheet where the operations are performed.
The function used to modify the mode for handling the XLS functions is named xlsOpen.
WLanguage functions
These functions are used to:
  • handle the ".XLS" files: opening and closing.
  • get information about your ".XLS" files: data of a cell, number of rows, number of columns, type of column, title of column (see the diagram).
  • find out the Excel version used.
  • identify the errors that occurred during the operations performed on an ".XLS" file.
See XLS functions to find out the list of functions that can be used with a ".XLS" file.
Related Examples:
The Excel functions Unit examples (WINDEV): The Excel functions
[ + ] Using the functions for importing/exporting a WINDEV table to/from Excel and Word. This is automatically performed by the WLanguage functions.
The following topics are presented in this example:
1/ How to export the content of a table to Excel or Word
2/ How to import the content of an Excel file to a WINDEV table
A button is used to import the entire data from a Excel file into an application table.
A second button is used to export the table content to the source Excel file in order to apply the modifications.
The table can also be exported in table format into Word.
XLS Type Unit examples (WINDEV): XLS Type
[ + ] Handling the xlsDocument, xlsColumn, xlsRow and xlsCell variables.
The purpose of this example is to explain how these types of variables can be easily handled.
WD Controlling Excel Training (WINDEV): WD Controlling Excel
[ + ] This example explains how to control Excel via OLE Automation.
All the features included in Excel can be emulated.

This example requires Excel 97 or later.

Summary of the example supplied with WINDEV:
Controlling a spreadsheet as Excel may be useful to allow the user to keep his own habits from the software powered by WINDEV.
This process is very easy via the "CExcel" class supplied with WINDEV.
The main features of Excel can be directly called (chart, inserting objects, sorts, ...).
How do I control Excel via OLE Automation?
An OLE Automation contains methods and properties. This allows you to emulate it directly in WLanguage.
For example, to display the selected cell in bold:
MyOLEAutomationObject>>Selection>>Font>>Bold = True
WD Controlling Spreadsheets Training (WINDEV): WD Controlling Spreadsheets
[ + ] This example explains how to control OpenOffice Calc and Excel with a generic code.
It gives you the ability to create, open and handle the workbooks opened in OpenOfficeCalc and Excel from a WINDEV application.
You can position on a worksheet, select cells, read and modify their content, save the workbook and close it.
The use of an abstract class (CSpreadsheet) enables you to implement a unique code, regardless of the spreadsheet installed on the user computer
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment