Benutzer-Werkzeuge

Webseiten-Werkzeuge


epplus

Dies ist eine alte Version des Dokuments!


Inhaltsverzeichnis

EPPlus ist die Standalone DLL für das Powershell Modul ImportExcel.

Lesen

$epplusDllPath = "C:\Users\manuel.zarat\Desktop\Aktuell\DB Backups\EPPlus.dll"
$excelFilePath = "C:\Users\manuel.zarat\Desktop\Aktuell\DB Backups\Databases.xlsx"
 
Add-Type -Path $epplusDllPath
 
$package = New-Object OfficeOpenXml.ExcelPackage
$package.Load([System.IO.File]::OpenRead($excelFilePath))
 
foreach ($ws in $package.Workbook.Worksheets) {
 
    Write-Output "Arbeitsblattname: $($ws.Name)"
 
    for ($row = 1; $row -le $ws.Dimension.End.Row; $row++) {
        $rowValues = @()
        for ($col = 1; $col -le $ws.Dimension.End.Column; $col++) {
            $cellValue = $ws.Cells[$row, $col].Text
            $rowValues += $cellValue
        }
 
        #Write-Output ("Zeile $row : " + ($rowValues -join ", "))
        Write-Output "$($rowValues[0]) - $($rowValues[1])"
    }
 
    break
 
}

Schreiben

# Pfad zur EPPlus-DLL
$epplusDllPath = "C:\Users\manuel.zarat\Desktop\Aktuell\DB Backups\EPPlus.dll"
$excelFilePath = "C:\Users\manuel.zarat\Desktop\Aktuell\DB Backups\Test.xlsx"
 
# EPPlus-DLL laden
Add-Type -Path $epplusDllPath
 
# Neue Excel-Datei erstellen
$package = New-Object OfficeOpenXml.ExcelPackage
 
# Erstellen und Schreiben in das erste Arbeitsblatt
$worksheet1 = $package.Workbook.Worksheets.Add("Sheet1")
$worksheet1.Cells[1, 1].Value = "Name"
$worksheet1.Cells[1, 2].Value = "Alter"
$worksheet1.Cells[2, 1].Value = "John Doe"
$worksheet1.Cells[2, 2].Value = 30
 
# Erstellen und Schreiben in das zweite Arbeitsblatt
$worksheet2 = $package.Workbook.Worksheets.Add("Sheet2")
$worksheet2.Cells[1, 1].Value = "Produkt"
$worksheet2.Cells[1, 2].Value = "Preis"
$worksheet2.Cells[2, 1].Value = "Laptop"
$worksheet2.Cells[2, 2].Value = 999.99
 
# Erstellen und Schreiben in das dritte Arbeitsblatt
$worksheet3 = $package.Workbook.Worksheets.Add("Sheet3")
$worksheet3.Cells[1, 1].Value = "Land"
$worksheet3.Cells[1, 2].Value = "Hauptstadt"
$worksheet3.Cells[2, 1].Value = "Deutschland"
$worksheet3.Cells[2, 2].Value = "Berlin"
 
# Datei speichern
$package.SaveAs([System.IO.File]::Create($excelFilePath))
 
# Bestätigungsausgabe
Write-Output "Excel-Datei erfolgreich erstellt unter: $excelFilePath"
epplus.1724658505.txt.gz · Zuletzt geändert: 2024/08/26 09:48 von jango