Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Excel工作表之间传输数据,而不发送实际的工作表模板_Excel_Powershell_Automation_Etl - Fatal编程技术网

在Excel工作表之间传输数据,而不发送实际的工作表模板

在Excel工作表之间传输数据,而不发送实际的工作表模板,excel,powershell,automation,etl,Excel,Powershell,Automation,Etl,如何在不发送实际工作表模板的情况下在Excel工作表之间传输数据 源代码是.xls;设计为.xlsm 我有一个powershell脚本,它可以将工作表从源文件传输到目标文件,并进行一些重命名,使其向最终用户显示,就像只传输数据一样,但实际上,它是将工作表复制到目标文件中,然后重命名原始工作表,然后重命名复制的工作表以替换原始工作表,然后删除现在重命名但为原始的工作表 这是一个问题,因为工作簿中的某些单元格引用了原始工作表(该工作表会被重命名然后被删除),因此引用会中断并变成#REF 是否有一种方

如何在不发送实际工作表模板的情况下在Excel工作表之间传输数据

源代码是
.xls
;设计为
.xlsm

我有一个powershell脚本,它可以将工作表从源文件传输到目标文件,并进行一些重命名,使其向最终用户显示,就像只传输数据一样,但实际上,它是将工作表复制到目标文件中,然后重命名原始工作表,然后重命名复制的工作表以替换原始工作表,然后删除现在重命名但为原始的工作表

这是一个问题,因为工作簿中的某些单元格引用了原始工作表(该工作表会被重命名然后被删除),因此引用会中断并变成
#REF

是否有一种方法可以简单地将源工作表的内容转移到空的目标工作表中,而不必实际复制/重命名工作表

如果没有,我如何保留我的脚本,但确保Excel中的引用不会被破坏

如果您对我当前的脚本感到好奇,请看以下内容:

$file1 = $args[0]

$file2 = $args[1]

    <#
        $file1 = 'c:\source.xls' # source's fullpath
        $file2 = 'c:\destination.xlsm' # destination's fullpath
    #>

    $xl = new-object -c excel.application
    $xl.displayAlerts = $false # don't prompt the user

    $wb1 = $xl.workbooks.open($file1, $null, $true) # open source, readonly
    $wb2 = $xl.workbooks.open($file2) # open target
    $sh2_wb2 = $wb2.sheets.item('SheetOfInterest') # sheet in destination workbook
    $sheetToCopy = $wb1.sheets.item('SheetOfInterest') # source sheet to copy

    $sh2_wb2.Name = "OldSheetOfInterest" #Rename original sheet in template
    $sheetToCopy.copy($sh2_wb2)  # copy source sheet to destination workbook

    $sh2_wb2 = $wb2.sheets | where {$_.name -eq "OldSheetOfInterest"}
    $sh2_wb2.delete() #Delete original sheet in template

    $wb1.close($false) # close source workbook w/o saving
    $wb2.close($true) # close and save destination workbook
    $xl.quit()
    spps -n excel
$file1=$args[0]
$file2=$args[1]
$xl=新对象-c excel.application
$xl.displayAlerts=$false#不提示用户
$wb1=$xl.workbooks.open($file1,$null,$true)#开源,只读
$wb2=$xl.workbooks.open($file2)#open target
$sh2_wb2=$wb2.sheets.item('SheetOfInterest')#目标工作簿中的工作表
$sheetToCopy=$wb1.sheets.item('SheetOfInterest')#要复制的源工作表
$sh2_wb2.Name=“OldSheetOfInterest”#重命名模板中的原始图纸
$sheetToCopy.copy($sh2_wb2)#将源工作表复制到目标工作簿
$sh2_wb2=$wb2.sheets |其中{$\u.name-eq“OldSheetOfInterest”}
$sh2_wb2.delete()#删除模板中的原始工作表
$wb1.close($false)#关闭不保存的源工作簿
$wb2.close($true)#关闭并保存目标工作簿
$xl.quit()
spps-n excel
试试这个

$file1 = $args[0]

$file2 = $args[1]

    <#
        $file1 = 'c:\source.xls' # source's fullpath
        $file2 = 'c:\destination.xlsm' # destination's fullpath
    #>

$xl = new-object -c excel.application
$xl.displayAlerts = $false # don't prompt the user

$wb1 = $xl.workbooks.open($file1, $null, $true) # open source, readonly
$wb2 = $xl.workbooks.open($file2) # open target
$destination = $wb2.sheets.item('SheetOfInterest') # sheet in destination workbook
$source = $wb1.sheets.item('SheetOfInterest') # source sheet to copy

[void]$destination.UsedRange.Clear() # Clear cells that have data in the destination
[void]$source.UsedRange.Copy() # Copy range of cells with data in them on source sheet
[void]$destination.Range("A1","A1").Select() # Set first cell of destination as active cell
[void]$destination.paste() # Paste data into destination sheet starting at active cell (A1)
[void]$destination.Range("A1","A1").Select() # Set first cell of destination as active cell, otherwise is has everything selected

$wb1.close($false) # close source workbook w/o saving
$wb2.close($true) # close and save destination workbook
$xl.quit()
spps -n excel
$file1=$args[0]
$file2=$args[1]
$xl=新对象-c excel.application
$xl.displayAlerts=$false#不提示用户
$wb1=$xl.workbooks.open($file1,$null,$true)#开源,只读
$wb2=$xl.workbooks.open($file2)#open target
$destination=$wb2.sheets.item('SheetOfInterest')#目标工作簿中的工作表
$source=$wb1.sheets.item('SheetOfInterest')#要复制的源表
[void]$destination.UsedRange.Clear()#清除目标中包含数据的单元格
[void]$source.UsedRange.Copy()#复制源工作表中包含数据的单元格范围
[void]$destination.Range(“A1”、“A1”).Select()#将目标的第一个单元格设置为活动单元格
[void]$destination.paste()#从活动单元格(A1)开始将数据粘贴到目标工作表中
[void]$destination.Range(“A1”、“A1”).Select()#将目标的第一个单元格设置为活动单元格,否则将选中所有单元格
$wb1.close($false)#关闭不保存的源工作簿
$wb2.close($true)#关闭并保存目标工作簿
$xl.quit()
spps-n excel