Hey Scripting Guy, great stuff on this blog! I have learned a ton from you and the group. I am running into a snag with a PowerShell that I hope you can help me with. I am trying to take the ChildItems(.xlsx) of a file and convert all of them to .csv for processing. I am on a sql server that does not have Office installed so I am having to use OLEDB to try and accomplish this. I tried to use a hacked version of a scripting guy post (http://blogs.technet.com/b/heyscriptingguy/archive/2008/09/15/how-can-i-write-to-excel-without-using-excel.aspx) to get this to work but had no success.
Here is what I have thus far
####source/target
$ExcelPath = "\\localhost\D$\Informatica\SrcFiles\share_point\ExcelFromSP\*"
$CSVPath = "\\localhost\D$\Informatica\SrcFiles\share_point\InfaExceltoCSV\*"
#excel connection string
$strProvider = "Provider=Microsoft.ACE.OLEDB.12.0"
$strDataSource = "Data Source ="+$excelpath
$strExtend = "Extended Properties=Excel 12.0 Xml"
#connect to excel;
$objConn = new-object System.Data.OleDb.OleDbConnection( "$strProvider;$strDataSource;$strExtend")
#$objConn.open()
#loop through the .xlsx files convert to .csv and move to the CSVPath
While($objConn.open())
{
Get-ChildItem $ExcelPath -Recurse -filter *.xlsx | foreach{
$xl = New-Object -com Excel.Application
$xl.Visible=$false
$xl.displayalerts=$false
$wb = $xl.Workbooks.Open($_.fullname)
$csv = $CSVPath + [io.path]::GetFileNameWithoutExtension($_.fullname) + ".csv"
$wb.SaveAs($csv,24)
$xl.Workbooks.Close()
$xl.quit()
}
}
$objConn.close()
I am getting stuck on the following error even though the service account I am running this under has full control on all the files. What am I doing wrong? here is the error:
Exception calling "Open" with "0" argument(s): "Failure creating file."
At line:15 char:20
+ While($objConn.open <<<< ())
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Any help to get me passed this would be greatly appreciated.