使用Powershell将Excel工作簿(在Sharepoint上)复制/粘贴到另一个工作簿(在桌面上)
我正在尝试使用任务计划程序运行Powershell脚本(如下所示),该脚本从Excel文件(托管在Sharepoint网站上)复制一系列单元格,并每天早上将这些单元格粘贴到另一个Excel工作簿(在我的桌面上)中 这仅仅是我所理解的漫长过程中的一个步骤,除了最后一块 有什么见解吗使用Powershell将Excel工作簿(在Sharepoint上)复制/粘贴到另一个工作簿(在桌面上),excel,powershell,scheduled-tasks,vba,Excel,Powershell,Scheduled Tasks,Vba,我正在尝试使用任务计划程序运行Powershell脚本(如下所示),该脚本从Excel文件(托管在Sharepoint网站上)复制一系列单元格,并每天早上将这些单元格粘贴到另一个Excel工作簿(在我的桌面上)中 这仅仅是我所理解的漫长过程中的一个步骤,除了最后一块 有什么见解吗 #This opens a new Excel object and makes it visible $excel=new-object -comobject excel.application; $excel.vi
#This opens a new Excel object and makes it visible
$excel=new-object -comobject excel.application;
$excel.visible=$true;
#This identifies the source workbook (the one from which the data will be copied).
$SourceWorkBook=$Excel.Workbooks.open("\\sites\DavWWWRoot\RM\data\MS Reports\PathName");
#This identifies the target workbook (the one to which the data will be pasted)
$TargetWorkBook=$excel.workBooks.Open("\\rmhso-ss1\HSO-Share\Team folders\Accounting Team\Matt\Reporting\NewDailySales\Test.xlsx");
#This activates the source workbook
$SourceWorkBook.WorkSheets.item("Daily Sales - Current Week").activate();
#This specifies the range that we want to copy
$SourceRange=$SourceWorkBook.WorkSheets.item("Daily Sales - Current Week").range("A8:BI1200");
#This copies that range. It will say "true" if the copy is successful, but we're not interested in seeing that.
#Because of this, we will use the out-null cmdlet, which discards any info that is piped to it.
$SourceRange.copy() | out-null;
#This identifies the destination where we want the information copied.
#Here, it pastes the information in the tab named "Sheet2" of the target workbook
#First, identify where you want it pasted
$TargetRange=$TargetWorkbook.Worksheets.item("Sheet2").range("L90:BT1200");
#Then, paste that into the target workbook
$TargetWorkbook.ActiveSheet.Paste($TargetRange);
你的剧本是做什么的?我的意思是,它是否成功地复制了部分或全部内容,并粘贴了这些内容?还是你有错误?如果是,在哪里?另外,您是否考虑过让目标工作表直接引用源工作表?然后,您可以通过让任务使用一致的名称将源电子表格复制到已知位置,并让目标工作表引用该名称来简化。我认为这应该像用
$TargetRange.Activate()| Out Null;替换最后一行一样简单$Excel.ActiveSheet.Paste()
Oh-wow-是的,按照@TheMadTechnician的建议更改最后一行很简单。非常感谢!你的剧本是做什么的?我的意思是,它是否成功地复制了部分或全部内容,并粘贴了这些内容?还是你有错误?如果是,在哪里?另外,您是否考虑过让目标工作表直接引用源工作表?然后,您可以通过让任务使用一致的名称将源电子表格复制到已知位置,并让目标工作表引用该名称来简化。我认为这应该像用$TargetRange.Activate()| Out Null;替换最后一行一样简单$Excel.ActiveSheet.Paste()
Oh-wow-是的,按照@TheMadTechnician的建议更改最后一行很简单。非常感谢!