Back

Topic

[KB1192]Excel provider – Version 1

Tags: Excel, File, Provider

4 years ago
By LM
Options
Print
Applies to:

PcVue 15.2 onwards


Summary:

This article contains attached files at the end.

This provider allows interaction between Excel files and PcVue.


Status:

This provider has the status: Release Candidate


Details:

Download the latest version of the provider proposed in the table at the end of this article and unzip it to execute the msi file.

Follow the instruction given in the ADO.Net Providers installation procedure article to install this provider.

To declare a connection into PcVue, goto General -> Data connections -> Add a SQL connection and select the Data source Built-in providers, then you can choose .NET Framework Data Provider for Excel Data provider:

Excel configuration general

Finally go to the second tab (Buil-in) to configure the connection:

Excel configuration connection string

Connection string examples

Property names are case insensitive and their order is not important. The Excel file is not part of the connection string: it is specified in each query.

Local or network folder (the .\ syntax targets the PcVue project root folder, since PcVue 15.2):

AccessMode=Directory;DataSource=C:\MyXLSXFolder\;SheetSelection=Name;Header=true
AccessMode=Directory;DataSource=.\TEMP;SheetSelection=Position;Header=true

FTP server:

AccessMode=Ftp;DataSource=ftp://myserver;FtpUserName=user;FtpUserPassword=xxx;FtpTransferMode=Passive;FtpRequestTimeout=60;Encryption=Explicit;TlsVersion=Tls12

Forcing column types and formats:

Header=true;Culture=fr-fr;NullValue=#N/A;DateTimeFormat=yyyy/MM/dd-HH:mm:ss.fff;FieldTypes=timestamps,DateTime,value,Double,info,String

Troubleshooting: add trace=C:\ExistingFolder (absolute path of an existing folder) to the connection string to generate provider trace files.

 

Files attached consist in the:

Attached file Description
sv-adonet-provider_Xlsx_1.0.628.zip Version 1.0.628 of Excel provider
  The documentation
  The Release Notes

   

Query examples

The data to load is defined in each query, in the FROM clause, using the following syntax:

[<FileNameWithExtension>/<SheetName>$<FirstRangeCell>:<LastRangeCell>]
  • Subfolders are allowed: [subfolder\file.xlsx/Sheet1$A1:F4].
  • Supported formats: XLSX, XLSM, XLTX, XLTM, XLSB, XLAM. The L1C1 notation is not supported.
  • The sheet is identified by its name or by its position (starting at 1) depending on the SheetSelection connection string parameter.
  • The sheet and range are optional: [file.xlsx] reads the first sheet with an automatic range.

The examples below use a file Production.xlsx with a sheet Data containing the columns id, name, value, info and timestamp (Header=true in the connection string).

1. Choosing the data range

QueryResult
SELECT * FROM [Production.xlsx/Data$A1:E10]Fixed range A1 to E10.
SELECT * FROM [Production.xlsx/Data$A1:E*]Columns A to E, from row 1 until the first empty row.
SELECT * FROM [Production.xlsx/Data$A1:*10]Rows 1 to 10, from column A until the first empty column of the first row.
SELECT * FROM [Production.xlsx/Data$A1:**]Everything from A1 to the last non-empty row and column.
SELECT * FROM [Production.xlsx/Data$**:E10]From the first non-empty cell up to E10.
SELECT * FROM [Production.xlsx/Data$**:**] or SELECT * FROM [Production.xlsx/Data]Fully automatic range.
SELECT * FROM [Production.xlsx/1$A1:**]First sheet, with SheetSelection=Position.
SELECT * FROM [Production.xlsx/Data$NAMED_CELL(TEMP)]Reads the named cell TEMP (case sensitive, value read as a string).

2. SELECT – filtering, sorting and aggregating

-- Column selection and aliases
SELECT id AS reference, [name] AS [Product name] FROM [Production.xlsx/Data$A1:**]

-- Filtering
SELECT * FROM [Production.xlsx/Data$A1:**] WHERE value > 10 AND info IS NOT NULL
SELECT * FROM [Production.xlsx/Data$A1:**] WHERE name LIKE 'Pump%'
SELECT * FROM [Production.xlsx/Data$A1:**] WHERE id IN (1, 3, 5)
SELECT * FROM [Production.xlsx/Data$A1:**] WHERE id % 2 = 0
SELECT * FROM [Production.xlsx/Data$A1:**] WHERE timestamp >= '2024/01/01 00:00:00'

-- Distinct values and top rows
SELECT DISTINCT name FROM [Production.xlsx/Data$A1:**]
SELECT TOP(10) * FROM [Production.xlsx/Data$A1:**] ORDER BY value DESC

-- Aggregations
SELECT name, AVG(value) AS average, MAX(value) AS maximum, COUNT(*) AS nb
FROM [Production.xlsx/Data$A1:**] GROUP BY name HAVING AVG(value) > 2 ORDER BY name ASC

-- Computation in the WHERE clause
SELECT * FROM [Production.xlsx/Data$A1:**] WHERE value + id = 120

3. SELECT – pagination (OFFSET / FETCH)

Use OFFSET ... FETCH NEXT (not TOP) to read the data page by page, for example to fill a grid. Combine it with ORDER BY to get a deterministic result.

-- Rows 1 to 20
SELECT * FROM [Production.xlsx/Data$A1:**] ORDER BY id OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY
-- Rows 21 to 40
SELECT * FROM [Production.xlsx/Data$A1:**] ORDER BY id OFFSET 20 ROWS FETCH NEXT 20 ROWS ONLY
-- Everything after the first 20 rows
SELECT * FROM [Production.xlsx/Data$A1:**] ORDER BY id OFFSET 20 ROWS

4. SELECT – adding constant columns (STATICVALUE)

Adds columns containing a constant (integer or string) to the result. Maximum of 99 static values.

SELECT * FROM [Production.xlsx/Data$A1:**] STATICVALUE(1, "Line1")

5. INSERT

The file and the sheet must already exist (they are not created by INSERT). Not available in FTP access mode. New rows are added right after the last row of the range.

-- Add a row (all columns)
INSERT INTO [Production.xlsx/Data$A1:**] VALUES (10, 'Pump A', 12.5, 'OK', '2024/11/18 16:00:00')

-- Add a row (some columns only)
INSERT INTO [Production.xlsx/Data$A1:**] (id, name) VALUES (11, 'Pump B')

-- Add several rows at once
INSERT INTO [Production.xlsx/Data$A1:E*] (id, name, value) VALUES (12, 'Pump C', 3.2), (13, 'Pump D', 4.8)

-- Write an Excel formula (value starting with '=')
INSERT INTO [Production.xlsx/Data$A1:**] (value) VALUES ('=AVERAGE(C2:C10)')

6. UPDATE

Not available in FTP access mode.

UPDATE [Production.xlsx/Data$A1:**] SET value = 0.4 WHERE id = 1
UPDATE [Production.xlsx/Data$A1:**] SET name = 'Pump X', info = 'Maintenance' WHERE id = 10
UPDATE [Production.xlsx/Data$A1:**] SET value += 1 WHERE name LIKE 'Pump%'
UPDATE [Production.xlsx/Data$A1:**] SET info = NULL WHERE value < 0

-- Write the named cell TEMP
UPDATE [Production.xlsx/Data$NAMED_CELL(TEMP)] SET col0 = 25

7. DELETE

DELETE removes the matching rows and compacts the remaining ones at the top of the range (empty rows are added at the end of the range). Not available in FTP access mode.

DELETE FROM [Production.xlsx/Data$A1:**] WHERE id = 1
DELETE FROM [Production.xlsx/Data$A1:**] WHERE name LIKE '%old'

-- Clear the content of the named cell TEMP
DELETE FROM [Production.xlsx/Data$NAMED_CELL(TEMP)]

8. List the available files (system table)

Returns the files found in the data source folder (subfolders included). Use the QueryPath column as the identifier after FROM.

SELECT * FROM information_schema_files
SELECT QueryPath, Size, LastWriteTime FROM [information_schema_files] WHERE IsReadOnly = 0 ORDER BY LastWriteTime DESC

Columns (Directory mode): Name, QueryPath, FullPath, Size, CreationTime, LastWriteTime, LastAccessTime, IsReadOnly. In FTP mode: Name, QueryPath, FullPath, Size, LastWriteTime, Permission.

Syntax rules to remember

  • Boolean values: 0/1 or true/false without quotes.
  • Decimal separator is a dot: 0.4, not 0,4.
  • Dates to insert/update always use the format 'yyyy/MM/dd HH:mm:ss', for example '2024/11/18 16:00:00'.
  • Null values: NULL without quotes.
  • The modulo operator (%) in a WHERE clause only works with integer values.
  • Excel formulas can be read (evaluated result) and written, but they are not evaluated by the provider.
  • Numeric cells are read as Double and other cells as String unless FieldTypes is set; custom cell formats are read as strings.

Limitations and good practices

  • Mapped drives cannot be used because DbConnect runs as a Windows service: use a UNC path (\\server\share) and only as a last resort, since the behaviour in case of network loss is uncertain.
  • Concurrent access to the same Excel file (for example while it is open in Excel) is not supported.
  • Large files consume a lot of memory (about 3 GB of RAM for 14 million cells), so prefer restricted ranges and pagination.
  • Excel does not need to be installed on the PcVue machine.

Created on: 20 Mar 2023 Last update: 27 Nov 2026