Powershell | Excel |插入空格

时间:2015-10-06 12:35:29

标签: excel powershell whitespace

如何在Excel单元格中插入空格?我正在尝试使用以下代码,但在写入excel时,它会自动修剪空间。

$test = "122332323" + "        "
$ws.Cells.Item(5,1) = $test

我甚至尝试过PadRight,但在写入excel时也会修剪空格。

1 个答案:

答案 0 :(得分:0)

这是一个单元格格式问题,为此单元格定义'text'类型数字格式......

$test = "122332323" + "        "
$cell = $ws.Cells.Item(5,1)
$cell.NumberFormat = '@'
$cell.Value2 = $test