I was trying to use some simple script to create a workbook in Excel 2007 and add some worksheets in it, with data.
Spend hours on it, but it just opened up the Excel application. But no workbook and no sheets ?
This was the intial code :
CLS #[threading.thread]::CurrentThread.CurrentCulture = 'en-US' $Excel = new-Object -com Excel.Application $Excel.visible = $True $Excel.DisplayAlerts = $False $ExcelWB = $Excel.Workbooks.Add() # adding 3 extra sheets $Sheet = $ExcelWB.Worksheets.Add() $Sheet = $ExcelWB.Worksheets.Add() $Sheet = $ExcelWB.Worksheets.Add() # Assign each worksheet to a variable and # name the worksheet. $Sheet1 = $ExcelWB.Worksheets.Item(1) $Sheet2 = $ExcelWB.WorkSheets.Item(2) $Sheet3 = $ExcelWB.WorkSheets.Item(3) $Sheet4 = $ExcelWB.WorkSheets.Item(4) $Sheet5 = $ExcelWB.WorkSheets.Item(5) $Sheet6 = $ExcelWB.WorkSheets.Item(6) $Sheet1.Name = "General" $Sheet2.Name = "System" $Sheet3.Name = "Processor" $Sheet4.Name = "Memory" $Sheet5.Name = "Disk" $Sheet6.Name = "Network" Sleep 2 $ExcelWB.SaveAs('C:\Temp\test.xls',56) write-host $Error Sleep 2 $ExcelWB.Close() $Excel.Quit()
On the second line you can notice the line including
[threading.thread]::CurrentThread.CurrentCulture = 'en-US'
When you uncomment it, everything works fine ?
Reason is that I use an English OS with a non English regional settings, which seems to be the issue.