Auto-detecting Excel driver

The DDT.ExcelDriver method allows auto-detecting the Excel driver with the help of Open Database Connectivity (ODBC) or the Microsoft Access Database Engine (ACE) driver depending on the Excel file format after saving.

To this end, the UseACEDriver parameter is to be used. If you would not like to have these parameters signified explicitly each time, it is possible to write a wrapper function to do this automatically.

How to do it...

To automatically define the type of the driver, we need to perform the following steps:

  1. First we define the required DDTExcel function:
    function DDTExcel(fileName, sheetName)
    {
      var useACE = aqFileSystem.GetFileExtension(fileName) == "xlsx";
      return DDT.ExcelDriver(fileName, sheetName, useACE);
    }
  2. Now we can dismiss the necessity to think about the type of the file as it will be defined automatically. The following two examples will work similarly:
    var data = DDTExcel("C:\data.xls", "Sheet1");
    var data = DDTExcel("C:\data.xlsx", "Sheet1");

How it works...

The useACE parameter of the ExcelDriver method specifies which exact driver (ODBC or ACE) should be used to access file data.

To automatically define the type of the driver, we have used the simplest method of file-extension analysis. For the files with xls extension, the ODBC driver is used, while the driver of the type of ACE is utilized for the xlsx files.

There's more...

It is possible to use the ACE driver both for the files of the xls type, and for the xlsx files as well. The following two examples will handle the task of file recognition equally effectively:

var data = DDT.ExcelDriver("C:\data.xls", "Sheet1", true);
var data = DDT.ExcelDriver("C:\data.xlsx", "Sheet1", true);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.228.88