# XL2.app – Access-Export für Windows (Version 0.1) # # Exportiert aus einer Access-Datenbank alles, was unter Linux nicht lesbar ist: # - vollständiges SQL aller Abfragen (inkl. JOIN, GROUP BY, Parameter) # - Formulare, Berichte, Makros und VBA-Module als Text (SaveAsText) # Es werden KEINE Tabellendaten exportiert. Ergebnis: _xl2-export.zip # neben der Datenbank – diese Datei im XL2.app-Portal zusätzlich hochladen. # # Aufruf (PowerShell, Access muss installiert sein): # powershell -ExecutionPolicy Bypass -File .\xl2-access-export_v0.1.ps1 -Datenbank "C:\Pfad\Datei.accdb" # # Kennwortgeschützte Datenbanken: -Kennwort "…" angeben (wird nicht gespeichert). param( [Parameter(Mandatory = $true)][string]$Datenbank, [string]$Kennwort = "" ) $ErrorActionPreference = "Stop" $db = (Resolve-Path $Datenbank).Path $name = [IO.Path]::GetFileNameWithoutExtension($db) $ziel = Join-Path ([IO.Path]::GetTempPath()) ("xl2-" + [guid]::NewGuid().ToString("N")) New-Item -ItemType Directory -Path $ziel | Out-Null foreach ($d in "queries", "forms", "reports", "macros", "modules") { New-Item -ItemType Directory -Path (Join-Path $ziel $d) | Out-Null } function Sicher([string]$s) { return ($s -replace '[\\/:*?"<>|]', '_') } Write-Host "Öffne $db …" $acc = New-Object -ComObject Access.Application $acc.Visible = $false $acc.AutomationSecurity = 3 # msoAutomationSecurityForceDisable: keine Makros ausführen try { if ($Kennwort) { $acc.OpenCurrentDatabase($db, $false, $Kennwort) } else { $acc.OpenCurrentDatabase($db, $false) } $cdb = $acc.CurrentDb() $n = 0 foreach ($q in $cdb.QueryDefs) { if ($q.Name.StartsWith("~")) { continue } $datei = Join-Path $ziel ("queries\" + (Sicher $q.Name) + ".sql") "-- name: " + $q.Name + "`r`n-- type: " + $q.Type + "`r`n" + $q.SQL | Out-File -FilePath $datei -Encoding utf8 $n++ } Write-Host " $n Abfragen" $typen = @( @{ Sammlung = $acc.CurrentProject.AllForms; Typ = 2; Ordner = "forms"; Endung = ".txt" }, @{ Sammlung = $acc.CurrentProject.AllReports; Typ = 3; Ordner = "reports"; Endung = ".txt" }, @{ Sammlung = $acc.CurrentProject.AllMacros; Typ = 4; Ordner = "macros"; Endung = ".txt" }, @{ Sammlung = $acc.CurrentProject.AllModules; Typ = 5; Ordner = "modules"; Endung = ".bas" } ) foreach ($t in $typen) { $n = 0 foreach ($o in $t.Sammlung) { $datei = Join-Path $ziel ($t.Ordner + "\" + (Sicher $o.Name) + $t.Endung) $acc.SaveAsText($t.Typ, $o.Name, $datei) $n++ } Write-Host (" {0} {1}" -f $n, $t.Ordner) } @{ datenbank = $name; exportiert = (Get-Date -Format s); werkzeug = "xl2-access-export 0.1" } | ConvertTo-Json | Out-File -FilePath (Join-Path $ziel "manifest.json") -Encoding utf8 } finally { $acc.CloseCurrentDatabase() $acc.Quit() [void][Runtime.InteropServices.Marshal]::ReleaseComObject($acc) } $zip = Join-Path ([IO.Path]::GetDirectoryName($db)) ($name + "_xl2-export.zip") if (Test-Path $zip) { Remove-Item $zip } Compress-Archive -Path (Join-Path $ziel "*") -DestinationPath $zip Remove-Item -Recurse -Force $ziel Write-Host "Fertig: $zip" Write-Host "Bitte diese Datei im XL2.app-Portal zusätzlich hochladen. Sie enthält keine Tabellendaten."