Powershell and Excel

Ask your 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.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
danarstevenson
Posts: 8
Last visit: Wed Mar 20, 2024 5:41 am

Powershell and Excel

Post by danarstevenson »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell and Excel

Post by jvierra »

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
Last visit: Wed Mar 20, 2024 5:41 am

Re: Powershell and Excel

Post by danarstevenson »

Thank you for the quick response.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Powershell and Excel

Post by mxtrinidad »

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.

:)
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked