Skip to content

Instantly share code, notes, and snippets.

@frekac frekac/EPPlus_Sample2.ps1 Secret

Last active Oct 26, 2016
What would you like to do?
# 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"
# Save the Excel file when referencing a file in the package initiation
# Dispose of the Excel Pacakge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.