Writing data to cells Excel 2007 / PowerShell
Why can't I write values ββto Excel using Worksheet class or Sheet interface? I expected to be able to do something like this:
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Excel")
$Excel = New-Object Microsoft.Office.Interop.Excel.ApplicationClass
$Workbook = $Excel.Workbooks.Add()
$Worksheet = $Workbook.Worksheets.Add()
$Worksheet.Cells.Item(1,1).Value2 = "Test"
But instead it seems that you need to write the values ββusing the ApplicationClass object:
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Excel")
$Excel = New-Object Microsoft.Office.Interop.Excel.ApplicationClass
$Workbook = $Excel.Workbooks.Add()
$Worksheet = $Workbook.Worksheets.Add()
$Excel.Cells.Item(1,1).Value2 = "Test"
This doesn't seem logical to me because I am writing the value for the specific worksheet I am working with, not at the application level.
Any thoughts on this?
+2
source to share