使用powershell在Excel表中添加列 [英] Add a column in excel sheet using powershell

查看:677
本文介绍了使用powershell在Excel表中添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Powershell在Excel表格中的特定列号之后添加一列。
我可以在工作表的起始处添加它,但不能在特定列之后插入。

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.

推荐答案

唉,我同意,我没有找到任何文件或示例: - /。_
然而这里下面是如何插入第七列并给它一个名称:

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}
    }

最好的问候

这篇关于使用powershell在Excel表中添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆