May 6, 2020 at 7:58 pm #226140ParticipantTopics: 3Replies: 1Points: 36Rank: Member
I am wanting to create a script that would basically add the sum of what is in excel and save it as a variable so i can input it somewhere else.
Excel looks like this:
Count Store_Name 5 Store 1 10 Store 2 5 Store 3
So i would just need to add everything in column A and store it in a variable (5+10+5) = 20, $Count = 20
$excelObj = New-Object -ComObject Excel.Application
$excelObj.Visible = $false
$workBook = $excelObj.Workbooks.Open($filePath)
$workSheet = $workBook.sheets.Item(1)
#Select the range of rows should read
This is what i have learned so far, but im sure there are better ways than me copying $worksheet.Range ("A1").Textfor the whole column until 300, and then trying to find out how to add them together.
- This topic was modified 7 months ago by KarolSweats.
May 7, 2020 at 11:35 am #226383Senior ModeratorTopics: 9Replies: 1422Points: 5,290Rank: Community MVP
You could use the fantastic ImportExcel module, then use Import-Excel cmdlet to import the xlsx file.
then use Measure-Object cmdlet to calculate the sum of any property.PowerShell1Import-Excel -Path c:\temp\test.xlsx | Measure-Object -Property count -Sum
- This reply was modified 7 months ago by kvprasoon. Reason: post correction
- The topic ‘Select and add excel values’ is closed to new replies.