Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.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/2/powershell/11.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
Excel 如何将所有列转换为文本,在使用TextToColumns时,默认情况下它是通用格式的—使用Powershell_Excel_Powershell_Excel Automation - Fatal编程技术网

Excel 如何将所有列转换为文本,在使用TextToColumns时,默认情况下它是通用格式的—使用Powershell

Excel 如何将所有列转换为文本,在使用TextToColumns时,默认情况下它是通用格式的—使用Powershell,excel,powershell,excel-automation,Excel,Powershell,Excel Automation,我需要使用分隔符|拆分文本。但是在拆分其截断前零后: 输入 0001|00030455|testing 0003|00004532|testing 0001 00030455 testing 0003 00004532 testing 预期产出 0001|00030455|testing 0003|00004532|testing 0001 00030455 testing 0003 00004532 testing 获得这样的输出 1 30455 testing 3

我需要使用分隔符
|
拆分文本。但是在拆分其截断前零后:

输入

0001|00030455|testing
0003|00004532|testing
0001  00030455  testing
0003  00004532  testing
预期产出

0001|00030455|testing
0003|00004532|testing
0001  00030455  testing
0003  00004532  testing
获得这样的输出

1  30455  testing
3  4532   testing
$colA=$wst.range("A1").EntireColumn
$colrange=$wst.range("A1")
$colA.texttocolumns($colrange,1,-4142,$false,$false,$false,$false,$false,$true,"|",@(1,3))
尝试过这个

1  30455  testing
3  4532   testing
$colA=$wst.range("A1").EntireColumn
$colrange=$wst.range("A1")
$colA.texttocolumns($colrange,1,-4142,$false,$false,$false,$false,$false,$true,"|",@(1,3))

如何使用powershell在TextToColumn()中使用上述选项?

从中可以看出,
@(1,3)
是列类型应该使用的位置,也就是说第一列应该是MDY date格式的日期,这看起来不对

相反,我认为应该是:

@((1,2),(2,2),(3,2))

# so

$colA.TextToColumns($colRange,1,-4142,$false,$false,$false,$false,$false, $true,"|",@((1,2),(2,2),(3,2)))
这是第1列第2类(xlTextFormat),第2列第2类,第3列第2类

在快速测试中,这似乎对我有效:


非常感谢您现在的工作:)@DineshKumar您很受欢迎:)(如果有帮助,请向上投票或单击“接受答案”勾选)有没有任何可能的方法可以一次给出答案,因为我有300多个专栏。我需要这样做吗?@((1,2)(2,2),…(300,2))或任何其他简单的方法。@DineshKumar我不知道它是否会起作用,但您可以尝试先为每个对象{,@($,2)}生成
$formats
,然后在调用
TextToColumns
时使用
$formats