【发布时间】:2018-01-23 05:49:52
【问题描述】:
如果可能的话,有人能指出我正确的方向吗?我几乎完成了一个脚本,它允许我根据来自用户的信息生成一个预填充的电子表格。我遇到的唯一问题是如何将一个工作表从现有工作簿复制到新工作簿。
我有一个“数据”表,其中包含对应于第二个工作簿的工作表名称。我希望 PowerShell 读取单元格,然后使用这些读取的名称来提取具有每个相应名称的工作表。目前,当我尝试使用以下内容(仅作为示例)时遇到索引错误:
$dog = "UPS"
$sourceSheet = $sourceSheets.Item($dog)
PS 能否使用“项目”按名称打开工作表单元格?
#This reads the 'DATA' sheet and uses the numbers to figure out what kits are being used for each UTC
$count = 0
For ($k = 2; $k -le 25; $k++)
{
$Value += $datasheet.Cells.Item(1, $k).Text
#next two lines verify number of cells
If ($Value -ne "") {$count++}
Write-Host $count
}
#Creates name for excel spreadsheet
$cutsheet = "cutsheet"
#saves spreadsheet in folder created earlier
$worksheet.SaveAs("Q:\$mission\$cutsheet")
#opens inventory workbook
$source = $excel.workbooks.Open("Q:\inventory.xlsx")
$sourceSheets = $source.Worksheets
$sourceSheet = $sourceSheets.Item(2)
$dest2 = $worksheets.Item(7)
$sourceSheet.copy($dest2)
【问题讨论】:
标签: excel powershell