Non US locale

One thing I would add is that if you are using  anything but a US locale version of Excel some of
these scripts won’t work, especially adding and saving workbooks.

Here is a function that helps with this problem:

From: http://blogs.msdn.com/powershell/archive/2006/04/25/583235.aspx

======================================================
Function Using-Culture (
[System.Globalization.CultureInfo]$culture,
[ScriptBlock]$script)
{
    $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
    trap
    {
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
    }
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
    $ExecutionContext.InvokeCommand.InvokeScript($script)
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}

Using-Culture en-us {
$xl= New-Object -COM Excel.Application
$xl.Visible = $true
$xl.Workbooks.Open("C:ScriptsPowerShelltest.xls")
#$xl.Quit()
#[System.Runtime.InteropServices.Marshal]::ReleaseComObject($xl)
}

======================================================

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s