Welcome › Forums › General PowerShell Q&A › Writing Excel file to Azure Storage
- This topic has 0 replies, 1 voice, and was last updated 3 months, 2 weeks ago by
platforminc84.
Viewing 0 reply threads
-
AuthorPosts
-
-
October 14, 2020 at 6:44 am #263244
Hi All.
I have written a script that will do the following.
Export data to 2 csv files.
Combine the csv files onto a single excel workbook.
Password protect the files and save the file onto C:\file.
Now I want to change the script such that it runs within an azure setup, running the code from a pipeline as opposed to my local machine, the excel file should also be saved on an azure storage account.
PowerShell12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879$csvFilePath = "D:\extract\A.csv"$excelFilePath = "D:\extract\B.xls"$csvFilePath2 = "D:\extract\C.csv"$results | export-csv $csvFilePath -NoTypeInformation -Force$results2 | export-csv $csvFilePath2 -NoTypeInformation -Force$filepath='D:\extract\*'$excelfile = "D:\extract\Extract_ $(get-date -format ddMMyyyy).xls"function Add-Worksheet{Param($filepath)Try{Write-Host $_.Fullname -ForegroundColor green$ws=$wb.Sheets.Add($mv,$mv,$mv,$filepath)$ws.Cells.EntireColumn.AutoFit()}Catch{Write-Host "File cannot be loaded: $filepath" -ForegroundColor red}}$mv=[System.Reflection.Missing]::Value$Excel = New-Object -Com Excel.Application$Excel.visible=$false$wb=$Excel.Workbooks.Add()Get-ChildItem $filepath -Include *.csv |Sort-Object Name -desc|ForEach-Object{Add-Worksheet $_.Fullname}$wb.Worksheets.Item('Sheet1').Delete()$xlExcel8 = 56$Excel.DisplayAlerts = $false;$wb.SaveAs($excelfile,$xlExcel8,"password")$wb.Close()$excel.quit()$excel = $null$Attach += $excelFilePath$Attach +=$csvFilePath#Delete the old csv files.Get-ChildItem $filepath -include *.csv -Recurse | Remove-Item-
This topic was modified 3 months, 2 weeks ago by
grokkit. Reason: code formatting - please read the guide
-
This topic was modified 3 months, 2 weeks ago by
-
-
AuthorPosts
Viewing 0 reply threads
- The topic ‘Writing Excel file to Azure Storage’ is closed to new replies.