Add a column in excel sheet using powershell

2019-09-13 00:23发布

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.

1条回答
劳资没心,怎么记你
2楼-- · 2019-09-13 01:01

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

查看更多
登录 后发表回答