Powershell and Excel

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
danarstevenson
Posts: 8
Joined: Fri May 13, 2016 12:19 pm

Powershell and Excel

Post by danarstevenson » Fri Feb 23, 2018 1:12 pm

I have recently purchased Powershell Studio and love it. But now im trying script everything I can. I ran across a little repeatable process that outputs to an excel spreadsheet. So I am trying to edit a single cell in an existing spreadsheet. My googlefu must be bad, i cant find an example. Would anyone have a simple example of a script to open and edit a single cell and save then email the spreadsheet.

Thanks in advance
Dana

jvierra
Posts: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Powershell and Excel

Post by jvierra » Fri Feb 23, 2018 1:20 pm

Code: Select all

$xl = New-Object -Com Excel.Application
$doc = $xl.Workbooks.Open(<path to workbook>)
$xl.ActiveSheet.Cells.Item(2,3) = 'My value'
$doc.Save()
$doc.Close()
$xl.Quit()
See: https://stackoverflow.com/questions/394 ... powershell

Search for examples and you will find hundreds.

User avatar
danarstevenson
Posts: 8
Joined: Fri May 13, 2016 12:19 pm

Re: Powershell and Excel

Post by danarstevenson » Fri Feb 23, 2018 2:10 pm

Thank you for the quick response.

User avatar
mxtrinidad
Site Admin
Posts: 368
Joined: Sun Mar 03, 2013 12:42 pm

Re: Powershell and Excel

Post by mxtrinidad » Fri Feb 23, 2018 2:18 pm

Please feel free to check out my blog post at: http://www.maxtblog.com/2014/06/powersh ... into-excel

Look into the Excel section. You may find additional code that may interest you.

:)

Locked