Может кто-нибудь сказать мне, почему приведенный ниже код Powershell заставляет все ячейки на листе принимать стиль 'wrapText', а не только ячейки, указанные оператором range?
Подсветка ячеек влияет только на указанный диапазон, как и жирный шрифт, но 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
}