Created
September 20, 2021 04:35
-
-
Save hansgafriedzal/89c28db940414a23b66c0a8c6c18ee19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$path = "https://<tenant>.sharepoint.com/sites/<site>/<library>/<file>.xlsx" | |
$worksheetNames = "" | |
$save = $true | |
$excel = new-object -comobject excel.application | |
$timestamp = Get-Date -format "yyyyMMddHHmmss" | |
try | |
{ | |
$workbook = $excel.Workbooks.Open($path) | |
if (!$workbook) {continue} | |
$workbook.Worksheets | %{ | |
$_.activate() | |
$_.Range('d6').Value2 = $timestamp | |
$_.usedrange.rows | %{ | |
$_.cells | %{ | |
$_.Value2 | |
} | |
} | |
} | |
} | |
catch | |
{ | |
$_ | |
$excel.visible = $true | |
} | |
$workbook.Close($save) | |
$excel.DisplayAlerts = $false | |
$excel.Quit() | |
if (!$test) | |
{ | |
while([System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbook)){} | |
while([System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)){} | |
} | |
[System.GC]::Collect() | |
[System.GC]::WaitForPendingFinalizers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment