【发布时间】:2019-08-09 08:11:30
【问题描述】:
我正在复制另一个工作簿中的工作表,但 B9、B10、B11、B12 和 H13 中的公式引用了以前的工作簿,它们不应该。我还想提一下,我有点菜鸟。
我试过以下代码:
$sh2_wb2.Cells.Item(9,2).Value = "=Suivi!C6"
$sh2_wb2.Cells.Item(9,2).Formula = '=Suivi!C6'
$sh2_wb2.Cells.Item(9,2).Formula = "=Suivi!C6"
$path = ($_.fullname).substring(0,($_.FullName).lastindexOf("."))
"Adding to $path"
$file2 = $path # destination's fullpath
$wb1 = $excel.workbooks.open($file1, $null, $true) # open source, readonly
$wb1.unprotect('****') # unprotect source
$wb2 = $excel.workbooks.open($file2) # open target
$sh2_wb2 = $wb2.sheets.item(2) # second sheet in destination workbook
$sheetToCopy = $wb1.sheets.item(2) # source sheet to copy
$sheetToCopy.copy($sh2_wb2) # copy source sheet to destination workbook
$sh2_wb2.Cells.Item(9,2).Value = "=Suivi!C6"
$sh2_wb2.Cells.Item(10,2).Value = '=1!C1'
$sh2_wb2.Cells.Item(11,2).Value = '=1!C3'
$sh2_wb2.Cells.Item(12,2).Value = '=1!C4'
$sh2_wb2.Cells.Item(13,8).Value = '=1!C2'
$wb2.protect('****')
$wb1.close($false) # close source workbook w/o saving
$wb2.close($true) # close destination with saving
我没有收到任何错误。表 2 中的单元格 B9 应显示 =Suivi!C6。
【问题讨论】:
-
这段代码中的
$excel是什么?你在使用ImportExcel模块吗?
标签: excel powershell