您好我需要隐藏一些列without hardcoding in this command:
Get-SLDocument "C:\123\123.xlsx" | Hide-SLColumn `
-StartColumnName D -ENDColumnName F -Verbose | Save-SLDocument
我试图创建一个循环,但无法让它工作:
$Path = "C:\123\"
$excelFiles = Get-ChildItem -Path $path -include *.xlsx
Foreach ($wb in $excelFiles) {
Get-SLDocument $wb | Hide-SLColumn -StartColumnName D `
-ENDColumnName F -Verbose | Save-SLDocument
}
答案 0 :(得分:2)
$path1="C:\fso"
$excelfiles=Get-ChildItem -Path $path1 -filter *.xls
$xl=new-object -comobject Excel.application
if($excelfiles.item.membertype -eq "ParameterizedProperty"){
for ($i=0;$i-lt $excelfiles.length;$i++)
{
echo $excelfiles[$i].FullName
$wb=$xl.Workbooks.open($excelfiles[$i].FullName)
$wb.CheckCompatibility = $False
$wb.sheets(1).columns("U:AF").entirecolumn.hidden=$true
$wb.save()
$wb.close()
}}
else
{
$wb=$xl.Workbooks.open($excelfiles.FullName)
$wb.CheckCompatibility = $False
$wb.sheets(1).columns("U:AF").entirecolumn.hidden=$true
$wb.save()
$wb.close()
}
$xl.Quit()
这使用com-object创建一个excel对象,并在excel中打开以隐藏列并关闭并退出。如果你不想看到excel对象打开和关闭,你可以在创建对象后使用$ xl.visible = $ false