为什么Range.BorderAround会发出"True"消息?到控制台? [英] Why does Range.BorderAround emit "True" to the console?

查看:65
本文介绍了为什么Range.BorderAround会发出"True"消息?到控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用BorderAround会向控制台发出"True"消息.

Using BorderAround emits "True" to the console.

$range = $sum_wksht.Range('B{0}:G{0}' -f ($crow))
$range.BorderAround(1, -4138)

这可以通过使用以下方法之一来解决.

This can be overcome by using one of the following.

$wasted = $range.BorderAround(1, -4138)
[void]$range.BorderAround(1, -4138)

为什么需要这个?我没有正确创建范围吗?有更好的解决方法吗?

Why is this needed? Am I not creating the range correctly? Is there a better workaround?

推荐答案

为什么需要这个?

Why is this needed?

这是必需的,因为 BorderAround方法具有返回值,并且在PowerShell中, 输出(返回)数据 的任何命令或表达式...都是 隐式输出(成功)输出流 ,默认情况下流到 host ,该主机通常是控制台窗口 >(终端)在其中运行PowerShell会话.

It is needed, because the BorderAround method has a return value and, in PowerShell, any command or expression ... that outputs (returns) data is implicitly output to the (success) output stream, which by default goes to the host, which is typically the console window (terminal) in which a PowerShell session runs.

也就是说,数据显示在控制台/终端中,除非是,否则它是:

That is, the data shows in the console/terminal, unless it is:

  • 已捕获($var = ...)
  • 通过管道发送以进行进一步处理(... | ...;最后一个管道段的命令本身可能会或可能不会产生输出)
  • 已重定向(... >)
  • captured ($var = ...)
  • sent through the pipeline for further processing (... | ...; the last pipeline segment's command may or may not produce output itself)
  • redirected (... >)

或其任何组合.

也就是说:

$range.BorderAround(1, -4138)

(更高效)是以下简称:

is (more efficient) shorthand for:

Write-Output $range.BorderAround(1, -4138)

(明确使用 Write-Output 很少需要.)

(Explicit use of Write-Output is rarely needed.)

由于您不想要该输出,因此必须抑制 ,为此您可以选择以下几种方式:

Since you don't want that output, you must suppress it, for which you have several options:

  • $null = ...

[void] (...)

... > $null

... | Out-Null

$null = ...可能是最佳的总体选择,因为:

$null = ... may be the best overall choice, because:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆