/EPPlus_Sample2.ps1 Secret
Last active
October 26, 2016 20:18
Star
You must be signed in to star a gist
This file contains 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
# Add the EPPlus library | |
Add-Type -Path C:\scripts\EPPlus\EPPlus.dll | |
# Create the Excel Package | |
$newFile = "C:\scripts\Sample.xlsx" | |
[OfficeOpenXml.ExcelPackage]$excelPackage = New-Object OfficeOpenXML.ExcelPackage($newFile) | |
# Create the Excel WorkBook | |
[OfficeOpenXml.ExcelWorkbook]$book = $excelPackage.Workbook | |
# Create a reference to the first worksheet | |
$dataSheet = [OfficeOpenXml.ExcelWorksheet]$book.Worksheets[1] | |
# Get value of cell A1 and add information | |
$newValue = ($dataSheet.Cells["A1"].Value) + " and more info" | |
$datasheet.Cells["A1"].Value = "$newValue" | |
# Add data to A2 | |
$dataSheet.Cells["A2"].Value = "A second cell filled with information" | |
# Change background color/style of cells. | |
$addStyle = $dataSheet.Cells["A1:E1"].Style.Fill | |
$addStyle.PatternType = "Solid" | |
$addStyle.BackgroundColor.SetColor("LightSkyBlue") | |
# Save the Excel file when referencing a file in the package initiation | |
$excelPackage.SaveAs($newFile) | |
# Dispose of the Excel Pacakge | |
$excelPackage.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment