I don't (and can't) have Excel installed on a system that needs access to an Excel worksheet. Per what I've read, accessing it as a database is dramatically faster.
I actually have Office 2012 installed on the system I'm developing on; I'm aware that I'll need to install the Office 2007 Data Access components on any system that runs this script.
I'm finding conflicting info on the web (shocking!) and I'm wondering if I'm missing something obvious. The code is straightforward:
$strFileName = "C:\Users\[my directory]PWS20130821.xlsx"
$strProvider = "Provider = Microsoft.ACE.OLEDB.12.0"
$strDataSource = "Data Source = $strFileName"
$strExtend = 'Extended Properties = "Excel 12.0 Xml;IMEX=1;HDR=No"'
$passwd = get-ssp
$strPass = "Jet OLEDB:Database Password = $passwd"
$strConn = "$strProvider;$strDataSource;$strExtend;$strPass"
$objConn = New-Object System.Data.OleDb.OleDbConnection($strConn)
$objConn.open()
Which gives me "External Table is not in the expected format." My connection string when invoking the $objConn is
Provider = Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users[my directory]\PWS20130821.xlsx;Extended Properties = "Excel 12.0 Xml;IMEX=1;HDR=No";Jet OLEDB:Database Password = [removed, but correct]
Removing the IMEX and HDR have no impact. Putting the password in quotes (there are no spaces or special characters) has no impact.
I did find this: "I'm afraid. You cannot open a connection to a password-protected spreadsheet unless you have already manually opened the spreadsheet in Excel . The described error is with the Excel ODBC provider, but the behavior is identical in the Jet 4.0 OLE DB provider. Your other option is to remove the password from the spreadsheet, and rely on some other security mechanism (like restricting permissions on the folder where the file resides) to control access."
Is this still accurate?