【问题标题】:Add a column in excel sheet using powershell使用powershell在excel表中添加一列
【发布时间】:2014-08-24 07:52:21
【问题描述】:

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

【问题讨论】:

标签: excel powershell powershell-2.0


【解决方案1】:
#This will insert a column at column R

$Excel = New-Object -ComObject  excel.application 
$ExcelWorkSheet = $ExcelWordBook.Worksheets.Add()
$ExcelWorkSheet.Name = "TestThis"
#do other things

$ColumnSelect = $ExcelWorkSheet.Columns("R:R")
$ColumnSelect.Insert()

【讨论】:

    【解决方案2】:

    唉,我同意,我既没有找到文档也没有找到示例:-/ .
    尽管如此,下面是如何插入第 7 列并为其命名:

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

    最好的问候

    【讨论】:

      猜你喜欢
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 2017-07-20
      • 2014-10-07
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多