Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

New-Object -COM Excel.Application | certain fields are not showing, inconsistent behavior

$
0
0

Hello All,

Im having some trouble when using New-Object -COM Excel.Application on foreign machines primarily. It seems like my first four categories that are listed at the top of the spreadsheet have gone missing. But the data in which corresponds to the category below it stays intact. All other regions show the categories fine. Has anyone ever seen that before? How can i assure that all my categories stay?

 $excel = New-Object -COM Excel.Application

 $excel.visible = $false

$excel.displayalerts = $false

$excel = $excel.workbooks.add()

#categories Note: I have about 20 categories, they all look like this. The first 4 were missing on just a Tokyo machine. I need somehow a way to enforce that the fields be present after attempt has been made. or run a condition on it. This is inconsistent for just this region.

$Sheet = $excel.worksheets.item(1)

$Sheet.Cells.Item(1,1) = "Category1"

$Sheet.Cells.Item(1,2) = "Category2"

$Sheet.Cells.Item(1,3) = "Category3"

$Sheet.Cells.Item(1,4) = "Category4"

$Workbook = $sheet.UsedRange

$Workbook.Interior.ColorIndex = 49

$Workbook.Font.ColorIndex = 2

$Workbook.Font.Bold = $true

$intRow = 2

# Variable values go in the respectable second row, have about 20 of those as well

$Sheet.Cells.Item($intRow,1) = $variable

$Sheet.Cells.Item($intRow,2) = $variable2

$Sheet.Cells.Item($introw,3) = $variable3

$Sheet.Cells.Item($introw,4) = $variable4

# Now the variable $data is a mass collections of Get-ChildItems which you will see shortly

Foreach ($line in $data)

{

$sheet.Cells.Item($intRow,5) = $line.Name

$sheet.Cells.Item($intRow,6) = $line.Name2

$sheet.Cells.Item($intRow,7) = $line.Name3

$intRow = $intRow + 1

}

$WorkBook.EntureColumn.AutoFit()

$excel.SaveAs($folder + "\" + "name.csv") 

$excel.Close()

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Sheet) | Out-Null

[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel) | Out-Null

[System.GC]::Collect()

[System.GC]::WaitForPendingFinalizers()


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>