Created
January 22, 2015 15:33
-
-
Save bungard/17f66de0624fa77b6d3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseExcel{ | |
param( | |
[string] $strFileName = $(throw "Please specify an excel file to parse."), | |
[string] $strSheetName = 'Sheet1$', | |
[string] $callListId = $(throw "Please specify a callListId.") | |
) | |
$strProvider = "Provider=Microsoft.Jet.OLEDB.4.0" | |
$strDataSource = "Data Source = $strFileName" | |
$strExtend = "Extended Properties=Excel 8.0" | |
$strQuery = "Select * from [$strSheetName]" | |
$objConn = New-Object System.Data.OleDb.OleDbConnection("$strProvider;$strDataSource;$strExtend") | |
$sqlCommand = New-Object System.Data.OleDb.OleDbCommand($strQuery) | |
$sqlCommand.Connection = $objConn | |
$objConn.open() | |
$DataReader = $sqlCommand.ExecuteReader() | |
$count = 0 | |
if($DataReader.HasRows) | |
{ | |
$DataReader.read() #Dump header row | |
While($DataReader.read()) | |
{ | |
$emplid = $DataReader[0].Tostring() | |
$desc = $DataReader[2].ToString() | |
# Do Something | |
$count++ | |
} | |
} | |
$dataReader.close() | |
$objConn.close() | |
} | |
parseExcel -strFileName "some-file.xls" -callListId "18" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment