excel - 将 Excel 工作表转换为 txt 的 Powershell 脚本
问题描述
我有一个包含多个工作表的 Excel 文件,我需要使用 Powershell 将一个特定的工作表转换为 txt 文件。我“借用”了一个进行转换的脚本,但它没有指定哪个表,所以它只做第一个。
$FolderLoc = "D:\Information Services\Data\"
$files = Get-ChildItem $FolderLoc\*.xlsx -recurse
$Excel = New-Object -ComObject Excel.Application
$Excel.visible = $false
$Excel.DisplayAlerts = $false
ForEach ($file in $files) {
Write "Loading File '$($file.Name)'..."
$WorkBook = $Excel.Workbooks.Open($file.Fullname)
$NewFilePath = [System.IO.Path]::ChangeExtension($file.Fullname,".txt")
$Workbook.SaveAs($NewFilepath, 42) # xlUnicodeText
}
# cleanup
$Excel.Quit()
我需要转换的特定工作表称为“所有详细信息”。我做了各种尝试插入一行来识别工作表,但都没有奏效。
$FolderLoc = "D:\Information Services\Data"
$files = Get-ChildItem $FolderLoc\*.xlsx -recurse
$Excel = New-Object -ComObject Excel.Application
$Excel.visible = $false
$Excel.DisplayAlerts = $false
ForEach ($file in $files) {
Write "Loading File '$($file.Name)'..."
$WorkBook = $Excel.Workbooks.Open($file.Fullname)
**$worksheet = "All Detail"**
$NewFilePath = [System.IO.Path]::ChangeExtension($file.Fullname,".txt")
$Workbook.SaveAs($NewFilepath, 42) # xlUnicodeText
}
# cleanup
$Excel.Quit()
解决方案
推荐阅读
- java - 使用 ArchUnit 检查子类中的注释存在
- mysql - 为什么当带有 ALL 的 where 子句返回 true 时,我的 MySQL 语句不返回任何记录?
- c# - 引用类型c#大小的奇怪行为
- node.js - 将 create-react-app 与服务器连接
- paypal - 在 Paypal 结帐中添加自定义字段
- oracle-apex - 交互式网格工具栏中的新按钮
- javascript - 将 VueX 存储状态值绑定到输入(VueJS)
- django - 唯一约束失败 - 重定向视图?
- facebook - Facebook SDK(适用于 iOS)会破坏预先存在的深层链接吗?
- ios - 调用`type(of:xxx)`时,Swift中的类型`(val:string)`到底是什么