Powershell脚本将txt转换为xlsx [英] Powershell Script to convert txt to xlsx

查看:115
本文介绍了Powershell脚本将txt转换为xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文本文件转换为Excel格式.我使用Technet中的以下脚本:

I want to convert a textfile to Excel Format. I use the following script from Technet:

# Script name: ConvertTilde.ps1 
# Created on: 2007-01-06 
# Author: Kent Finkle 
# Purpose: How Can I Convert a Tilde-Delimited File to Microsoft Excel Format? 

$s = gc C:\Scripts\Test.txt 
$s = $s -replace("~","`t") 
$s | sc C:\Scripts\Test.txt 
$xl = new-object -comobject excel.application 
$xl.Visible = $true 
$wb = $xl.Workbooks.Open("C:\Scripts\Test.txt")
$wb.SaveAs("D:\Excel\Test.xlsx")

脚本可以正常工作,excel会打开并导入txt,但是保存的文件只是重命名为xlsx的txt文件-如何获得Excel来更改文件格式?

The Script works, excel opens and imports the txt, but the saved Files are just txt files renamed to xlsx - how can I get Excel to change the File Format?

推荐答案

我将研究

I would investigate the FileFormat parameter of the SaveAs method, although it won't magically convert a text file into a nicely formatted workbook.

这篇关于Powershell脚本将txt转换为xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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