【发布时间】:2020-08-28 16:47:42
【问题描述】:
所以我正在尝试编写一个 PowerShell 脚本来遍历目录中的 Excel 文件,这些文件都有不同的名称。我试图让脚本在特定单元格的文件中查找,并将它们作为表格输出到 PowerShell 窗口中。例如,我还需要脚本来获取文件名
Name Column1 Column2 Column3
file1.xlsx Yes linux extra info
file2.xlsx no windows more info
我尝试过使用$value = $workbook.Item(2, 4),这可行,但我不知道如何在文件之间循环、格式化为表格并提取文件名。
编辑:
$DirectoryPath = 'V:\directory goes here\
foreach ($File in (Get-ChildItem -Path $DirectoryPath))
{
#Do your work
$workbook = $excel.Workbooks.Open($File.FullName)
$workbook.sheets.item(1).activate()
$WorkbookTotal=$workbook.Worksheets.item(3)
$InternetFacingAnswer = $WorkbookTotal.Cells.Item(2, 4)
$OS = $WorkbookTotal.Cells.Item(4, 3)
$Guidance = $WorkbookTotal.Cells.Item(4,7)
$File.FullName
$File.Name
$InternetFacingAnswer.Text
$OS.Text
$Guidance.Text
$value | Format-Table -AutoSize
}
我收到的当前输出是: V:\目录到这里\testfile.xlsx 测试文件.xlsx 是的 苹果 视窗/Linux 在此处添加信息
Application Creator Parent AddIndent Areas Borders Cells Column Columns ColumnWidth
【问题讨论】:
标签: excel powershell