使用Powershell将表添加到Excel文件(最后一行)的末尾 [英] Using Powershell to Append a table to the end of an Excel File (The Last Row)

查看:292
本文介绍了使用Powershell将表添加到Excel文件(最后一行)的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个Powershell脚本,它从Microsoft Word中复制一个表,并将它们粘贴到一个excel文档中。我想在列A中最后一行使用行后面追加它。



我到目前为止,我得到了这段代码:

  $ Excel = New-Object -ComObject Excel.Application 

$ Excel.Visible = $ True

$ ExcelWordBook = $ Excel。 Workbooks.Open($ ExcelPath)

$ ExcelWorkSheet = $ Excel.WorkSheets.item(Sheet1)

$ ExcelWorkSheet.activate()

这是我感到困惑的地方,我想要找到Excel WorkSheet中使用的最后一行。 >

  $ lastRow = $ ExcelWorkSheet.UsedRange.rows(A)。count 

$ nextRow = $ lastRow + 1

$ ExcelWorkSheet.Range(A $ nextRow)。选择

$ ExcelWorkSheet.Paste()






我觉得我这么近,我试图在Office Interlop中使用UsedRange属性来确定Excel WorkSheet中的最后一行。 ( http ://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.usedrange(v = vs80).aspx )任何想法?

$ b $谢谢我最后走了一条更加动态的路线,而不是使用A9924082480198作为范围的结尾。

  $ Excel = New-Object -ComObject Excel.Application 
$ Excel.Visible = $ True
$ ExcelWordBook = $ Excel.Workbooks。打开($ ExcelPath)
$ ExcelWorkSheet = $ Excel.WorkSheets.item(sheet1)
$ ExcelWorkSheet.activate()

$ lastRow = $ ExcelWorkSheet.UsedRange.rows .count + 1
$ Excel.Range(A+ $ lastrow).Activate()
$ ExcelWorksheet.Paste()


I've written a Powershell script that copies a table from Microsoft Word and pastes them to an excel document. I want to append it after the last used row in column A.

I got this code so far:

$Excel = New-Object -ComObject Excel.Application

$Excel.Visible = $True

$ExcelWordBook = $Excel.Workbooks.Open($ExcelPath)

$ExcelWorkSheet = $Excel.WorkSheets.item("Sheet1")

$ExcelWorkSheet.activate()

This is where I get confused, I want to be able to find the last row that is used in the Excel WorkSheet.

$lastRow = $ExcelWorkSheet.UsedRange.rows("A").count

$nextRow = $lastRow + 1

$ExcelWorkSheet.Range("A$nextRow").Select

$ExcelWorkSheet.Paste()  


I feel like I'm so close after this. I was trying to use the UsedRange property in the Office Interlop to determine the last row in the Excel WorkSheet. (http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.usedrange(v=vs.80).aspx) Any ideas?

解决方案

Thanks I ended up going a different route that's more dynamic instead of using "A9924082480198" as the end of the range.

$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $True
$ExcelWordBook = $Excel.Workbooks.Open($ExcelPath)
$ExcelWorkSheet = $Excel.WorkSheets.item("sheet1")
$ExcelWorkSheet.activate()

$lastRow = $ExcelWorkSheet.UsedRange.rows.count + 1
$Excel.Range("A" + $lastrow).Activate()
$ExcelWorksheet.Paste()

这篇关于使用Powershell将表添加到Excel文件(最后一行)的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆