我想使用Powershell在excel表中的特定列号后面添加一列。 我可以在工作表的开头添加它,但是在特定列之后无法插入。
答案 0 :(得分:0)
唉,我同意,我没有找到任何文件或例子: - /。
然而,下面是如何插入第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}
}
祝你好运
答案 1 :(得分:0)
#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()