Changing Excel Cells from PowerShell
Modifying a Specific Cell in an Excel Spreadsheet Using PowerShell If you need to change the content of a specific cell in an Excel spreadsheet,...
- Written By: ps1
- Last Updated: April 21, 2025
- 2 minutes read
Modifying a Specific Cell in an Excel Spreadsheet Using PowerShell If you need to change the content of a specific cell in an Excel spreadsheet,...
If you need to change the content of a specific cell in an Excel spreadsheet, take a look at this sample code:
$ExcelPath = 'c:\path..to..some..excel..file.xlst' $excel = New-Object -ComObject Excel.Application $excel.Visible = $true $workbook = $excel.Workbooks.Open($ExcelPath) $workbook.ActiveSheet.Cells.Item(1,3) = 'I added this!'
Make sure you specify an existing Excel file. Or create a new one:
# create new Excel file $excel = New-Object -ComObject Excel.Application $excel.Visible = $true $workbook = $excel.Workbooks.Add() $workbook.ActiveSheet.Cells.Item(1,3) = 'I added this!' $ExcelPath = "$env:temp\newexcel.xlsx" $workbook.SaveAs($ExcelPath) $workbook.Close($false) $excel.Quit() # show new file in Explorer explorer "/select,$ExcelPath"
Contact our sales team to get a personalized demo of our database management software for SQL Server!