excel - Powershell - 将 'wrapText' 样式应用于某些单元格会导致整个工作表换行

标签 excel powershell

有人能告诉我为什么下面的 Powershell 代码会导致工作表中的所有单元格都采用“wrapText”样式,而不仅仅是范围语句指定的单元格吗?

单元格突出显示仅影响指定范围,粗体字体也是如此,但 WrapText 无处不在!

如果我指定如下内容:

 $ActiveWorksheet.Range("Q1"),Style.WraptText=$false

它关闭整个工作表的 WrapText。

有没有办法只影响所需的单元格?

谢谢

#Set Up EXCEL Stuff
$ExcelObj = new-Object -comobject excel.application
$ExcelObj.visible = $true
$ExcelObj.DisplayAlerts = $true

$now = get-date -format "yyyyMMddHHss"
$strPath = "Parse_$now.xlsx"

# Create the spreadsheet if it doesnt exist

If (test-Path $strPath) {
    $ActiveWorkbook = $ExcelObj.Workbooks.Open($strPath)
    $ActiveWorkSheet = $ExcelObj.Worksheets.Item(1)
    }
ELSE
    {
#   create file
    $ActiveWorkbook = $ExcelObj.Workbooks.Add()
    $ActiveWorkSheet = $ExcelObj.Worksheets.Item(1)


#   Add headers
    $ActiveWorkSheet.Cells.Item(1,1) = "Date"
    $ActiveWorkSheet.Cells.Item(1,2) = "Time"
    $ActiveWorkSheet.Cells.Item(1,3) = "Channel"
    $ActiveWorkSheet.Cells.Item(1,4) = "Codec"
    $ActiveWorkSheet.Cells.Item(1,5) = "State"
    $ActiveWorkSheet.Cells.Item(1,6) = "Target"
    $ActiveWorkSheet.Cells.Item(1,7) = "Gateway"
    $ActiveWorkSheet.Cells.Item(1,8) = "CFW"
    $ActiveWorkSheet.Cells.Item(1,9) = "DCFW"

# add reminder note - for some reason this gets wrapped
    $ActiveWorkSheet.Cells.Item(10,3) = "NOTE: If this is GW1, change Q-column Formulae from"
    $ActiveWorkSheet.Cells.Item(11,3) = "     N2/(MAX(M2:M20)-0) to N2/(MAX(M2:M20) -  23) in Col Q"

#    $format = $ActiveWorksheet.UsedRange
    $format = $ActiveWorksheet.Range("A1:I1")
    $format.Interior.ColorIndex = 23
    $format.font.ColorIndex = 11
    $format.Font.Bold = "True"

    #Set Summary Headers
    $ActiveWorkSheet.Cells.Item(1,11) = "Day"
    $ActiveWorkSheet.Cells.Item(1,12) = "Hour"
    $ActiveWorkSheet.Cells.Item(1,13) = "Channels"
    $ActiveWorkSheet.Cells.Item(1,14) = "MaxActive"
    $ActiveWorkSheet.Cells.Item(1,15) = "Average Channels Active"
    $ActiveWorkSheet.Cells.Item(1,16) = "Channels Free"
    $ActiveWorkSheet.Cells.Item(1,17) = "Max % Active LD Only"
    #Set Header Format for Summary Data
    $format = $ActiveWorksheet.Range("K1:Q1")
    $format.Interior.ColorIndex = 24
    $format.font.ColorIndex = 11
    #$format.Style.WrapText = "True"
    $ActiveWorksheet.Range("K1:Q1").Style.WrapText = "True"
    $format.Font.Bold = "True"
    #set Percent for max % Active col
    $format = $ActiveWorksheet.Range("Q2:Q50")
    $format.NumberFormat = "0.00%" #aaaa

}

最佳答案

........删除语法.Style

关于excel - Powershell - 将 'wrapText' 样式应用于某些单元格会导致整个工作表换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59688287/

相关文章:

php - 无法在 php mysql 表中存储 Excel 文件中存在的日期值

powershell - 尝试在 Terraform 启动的实例上设置 Windows 主机名

Visual Studio Online 构建结束时的 Git 标记(Build vNext,托管池)

powershell - 在Powershell中按比特率递归获取文件列表

svn - 用于查找所有 svn 工作副本的 Powershell 脚本

javascript - 从 Morningstar.com 获取上行/下行捕获率

vba - VBA图表中的系列公式过长错误

vba - Excel VBA ADODB 后期绑定(bind)错误

vba - xlDown 未按预期工作

powershell - 在Powershell中进行类型转换?奇怪的语法?