$sInputFile="D:\temp\exceldocument.xlsx"
$oExcel = New-Object -ComObject "Excel.Application"
$oExcel.Visible = $true
$oExcelDoc = $oExcel.Workbooks.Open($sInputFile)
$oWorksheet = $oExcelDoc.Worksheets.item(1)
$oWorksheet.Activate()
$iUsedRangeRow = $oWorksheet.UsedRange.Rows.Count
$iUsedRangeColumns = $oWorksheet.UsedRange.Columns.Count
$oWorksheet.UsedRange.EntireColumn.AutoFit()|out-null
write-host "Cell A1" $oWorksheet.Cells.Item(1,1).Text
$oWorksheet.Cells.Item(2,1).value2="New Text"
$oWorksheet.Cells.Item(1,1).Activate()|out-null
$oWorksheet.Cells.Item(1,1).Interior.ColorIndex = 4
[reflection.assembly]::LoadWithPartialName("System.Drawing")
$oWorksheet.Cells.Item(2,1).Interior.Color=[System.Drawing.Color]::White.ToARgb()
$oWorksheet.Cells.Item(2,1).Interior.Color=([System.Drawing.Color]::FromArgb(254,7,7)).ToArgb()
$oWorksheet.Cells.Item(2,1).Font.ColorIndex = 1
$oWorksheet.Cells.Item(2,1).Font.Size=12
$oWorksheet.Cells.Item(2,1).Orientation=45
$oWorksheet.Cells.Item(2,1).Font.Bold = $true
$oWorksheet.Cells.Item(2,1).Font.Strikethrough=$true
$oWorksheet.Cells.Item(2,1).AddComment("This is a comment")|Out-Null
$oWorksheet.Range("A1:B3").Numberformat="00,0"
$oWorksheet.Cells.Item(2,1).NumberFormat="@"
$oWorksheet.Cells.Item(2,1).NumberFormatLocal="@"
$oNewWorksheet=$oExcelDoc.Worksheets.add()
$oNewWorksheet.Name="My new worksheet"
$oExcelDoc.Close($true)
Start-Sleep 1
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($oWorksheet)|out-null
$oWorksheet=$null
Start-Sleep 1
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($oExcelDoc)|out-null
$oExcelDoc=$null
$oExcel.Quit()
Start-Sleep 1
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($oExcel)|out-null
$oExcel=$null
[GC]::Collect()
[GC]::WaitForPendingFinalizers()