Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过Powershell使用system.collections.ArrayList写入工作表.range?_Powershell - Fatal编程技术网

如何通过Powershell使用system.collections.ArrayList写入工作表.range?

如何通过Powershell使用system.collections.ArrayList写入工作表.range?,powershell,Powershell,当我尝试使用system.collections.ArrayList写入工作表.range时,失败了,但因为我将其转换为system.array时它是一维数组,所以它是一维数组,如何将其转换为二维数组?或者如何写入工作表 错误: [DBG]:PS C:\Users\xxxxxxxxx>> 缺少的参数没有默认值。 参数名称:参数 在C:\Users\xxxxxxxxx\Desktop\txt2excel.ps1:148 char:1 $ws.Range($startCell,$endCell).

当我尝试使用system.collections.ArrayList写入工作表.range时,失败了,但因为我将其转换为system.array时它是一维数组,所以它是一维数组,如何将其转换为二维数组?或者如何写入工作表

错误:

[DBG]:PS C:\Users\xxxxxxxxx>> 缺少的参数没有默认值。 参数名称:参数 在C:\Users\xxxxxxxxx\Desktop\txt2excel.ps1:148 char:1

  • $ws.Range($startCell,$endCell).Value2=$target\u列
[DBG]:PS C:\Users\xxxxxxxxx>>$ws.Range($startCell,$endCell.Value2=[System.Array]$target\u columns 来自HRESULT的异常:0x800A03EC 第1行字符:1

  • $ws.Range($startCell,$endCell).Value2=[System.Array]$target\u列
主要代码:

$original_file = Get-Content $originalTXT[1]
$target_columns = New-Object System.Collections.ArrayList 

foreach ($ss in $original_file) { 

    [System.Collections.ArrayList]$target_row_temp = $ss.Split("|")
    $string_temp = $target_row_temp.GetRange(0,2)
    $target_columns.Add($string_temp) | Out-Null 
    $target_row_temp.RemoveRange(0,2)
    $target_range.Add($target_row_temp) | Out-Null 

} 

$startCell = ws.Cells.Item(11,2)
$endCell = $ws.Cells.Item(10 + $excelHigh,3)
$ws.Range($startCell,$endCell).Value2 = [System.Array]$target_columns

主代码:$originalText[1]$target\u columns=New Object System.Collections.ArrayList foreach($original\u file中的ss){[System.Collections.ArrayList]$target\u row\u temp=$ss.Split(“|”)$string\u temp=$target\u row\u temp.GetRange(0,2)$target\u columns.Add($string\u temp)| Out Null$target\u row\u temp.ange(0,2)$target_range.Add($target_row_temp)| Out Null}$startCell=$ws.Cells.Item(11,2)$endCell=$ws.Cells.Item(10+$excelHigh,3)$ws.range($startCell,$endCell.Value2=[System.Array]$target_columnsmain代码:$originalText=Get Content$originalText[1]$target_columns=New Object System.Collections.ArrayList foreach($original\u文件中的ss){[System.Collections.ArrayList]$target_row_temp=$ss.Split(“|”)$string_temp=$target_row_temp.GetRange(0,2)$target_row_temp.Add($string_temp)$Out Null$target_row_temp.Add($startCell.Item(11,2)$endCell=$ws.Cells.Item(10+$excelHigh,3)$ws.range($startCell,$endCell).Value2=[System.Array]$target\u列
  + CategoryInfo          : OperationStopped: (:) [], COMException
  + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

$original_file = Get-Content $originalTXT[1]
$target_columns = New-Object System.Collections.ArrayList 

foreach ($ss in $original_file) { 

    [System.Collections.ArrayList]$target_row_temp = $ss.Split("|")
    $string_temp = $target_row_temp.GetRange(0,2)
    $target_columns.Add($string_temp) | Out-Null 
    $target_row_temp.RemoveRange(0,2)
    $target_range.Add($target_row_temp) | Out-Null 

} 

$startCell = ws.Cells.Item(11,2)
$endCell = $ws.Cells.Item(10 + $excelHigh,3)
$ws.Range($startCell,$endCell).Value2 = [System.Array]$target_columns