I want to add a column after a particular column number in excel sheet using Powershell. I am able to add it at starting of sheet, but couldn't insert after a specific column.
-
Perhaps this can help: gallery.technet.microsoft.com/office/…Raf– Raf2014-07-03 09:47:36 +00:00Commented Jul 3, 2014 at 9:47
-
I had checked this link earlier. Can u tell me what does -4161 represents?Nipun– Nipun2014-07-03 09:52:33 +00:00Commented Jul 3, 2014 at 9:52
-
Scripting guy puts it well "yes, minus 4161; go figure". This article will shine some light as the PS from my previous link is a direct adaptation: blogs.technet.com/b/heyscriptingguy/archive/2005/04/11/…Raf– Raf2014-07-03 10:06:25 +00:00Commented Jul 3, 2014 at 10:06
Add a comment
|
2 Answers
Alas, I agree, I have not found neither documentation or examples :-/ .
Nevertheless here is below how to insert a column 7th and give it a name:
(Get-ChildItem "*.xlsb")|
foreach-object {
$xl=New-Object -ComObject Excel.Application
$wb=$xl.workbooks.open($_)
$ws = $wb.worksheets.Item(1)
$ws.Columns.ListObject.ListColumns.Add(7)
$ws.Cells.Item(1,7) ='Comment'
$wb.Save()
$xl.Quit()
while([System.Runtime.Interopservices.Marshal]::ReleaseComObject([System.__ComObject]$xl)){'released'| Out-Null}
}
Best regards