# 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