Hướng dẫn powershell excel wrap text - văn bản bao bọc excel powershell

Ai đó có thể cho tôi biết lý do tại sao mã PowerShell bên dưới khiến tất cả các ô trong bảng tính đảm nhận kiểu 'Wraptext', thay vì chỉ các ô được chỉ định bởi câu lệnh Range không?

Việc làm nổi bật ô chỉ ảnh hưởng đến phạm vi được chỉ định, cũng như phông chữ đậm, nhưng Wraptext sẽ đi khắp mọi nơi !.

Và nếu tôi chỉ định một cái gì đó như:

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

Nó tắt wraptext cho toàn bộ trang tính.

Có cách nào để ảnh hưởng đến các tế bào mong muốn?

cảm ơn

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

  • Xóa khỏi các diễn đàn của tôi

  • Câu hỏi

  • Tôi có một tập lệnh thu thập thông tin từ một hoặc nhiều máy chủ và hiển thị thông qua việc chuyển các chức năng khác nhau cho một phiên từ xa (được trả về phần lớn dưới dạng mảng:

    $PSSession = New-PSSession -ComputerName $comp -Credential $fetchCreds -Name $server $buildlogsuccess = Invoke-Command -Session $pssession -ScriptBlock ${function:check-buildlog} -ArgumentList $domain $chocologstatus = Invoke-Command -Session $pssession -ScriptBlock ${function:check-choco} $DomainComms = Invoke-Command -Session $PSSession -ScriptBlock ${Function:get-domaininfo} $bigfix = Invoke-Command -Session $PSSession -ScriptBlock ${Function:get-bigfix} #clean up the remote session Remove-PSSession -Name $server [pscustomobject]@{ServerName = $comp "Physical/Virtual" = $Devicetype "IP Address" = $device.IPAddresses.ipaddress "Domain" = $DomainComms[4] "Build Script Found, Completed" = [string]$buildlogsuccess[0] + [string]"," + [string]$buildlogsuccess[1] "Windows Firewall Status" = $wfirewall "Net 3.5 Installed" = $net35 "Connection to domain OK, Current DC, AD Site" = [string]$DomainComms[0] + "," + [string]$DomainComms[1] + "," + [string]$DomainComms[2] "DelAdmin Groups in Admins" = $admins[1] "Applied GPOs" = $DomainComms[3] }

    Đầu ra (đối với hầu hết các phần) xuất hiện như mong đợi, ngoại trừ trường cuối cùng trong khi xuất hiện OK trong đầu ra danh sách và out-gridview, không xuất ra đúng khi sử dụng xuất-CSV (hoặc sao chép chính xác vào excel từ out-gridview):

    Có cách nào để bọc đầu ra đa dòng để nó có thể được giữ tất cả trong cùng một cột khi xuất ra các định dạng như CSV không?

    Chỉnh sửa: Một loạt các mã gốc đã được cắt để đáp ứng giới hạn ký tự của bài đăng.

    • Chỉnh sửa Bytuesday, ngày 27 tháng 6 năm 2017 2:27 sáng Tuesday, June 27, 2017 2:27 AM

Chủ đề