Add a column in excel sheet using powershell

前提是你 提交于 2019-12-25 05:09:28

问题


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:


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



来源:https://stackoverflow.com/questions/24549477/add-a-column-in-excel-sheet-using-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!