Compare commits

..

No commits in common. "38f57938833da6c4d9d4968816a9830fd7146e3d" and "b45a6c490a292b6caff9078fed3d6642fc162bd8" have entirely different histories.

3 changed files with 38 additions and 124 deletions

View File

@ -53,14 +53,14 @@ catch {
1. Microsoft Excel 2013 or newer
2. PowerShell must run in STA mode
Run the main script like this:
pwsh -STA -File .\MainForm.ps1
powershell.exe -STA -File .\MainForm.ps1
"@ -ForegroundColor Red
exit 1
}
Write-Host @"
Installation complete! Run the main application with:
pwsh -STA -File .\MainForm.ps1
powershell.exe -STA -File .\MainForm.ps1
Note: First run might take longer while modules load
"@ -ForegroundColor Green

View File

@ -6,29 +6,9 @@ This tool allows you to convert legacy `.xls` files stored in SharePoint to the
### Step 1: Install PowerShell 7.5
**Option 1: Manual Installation**
1. Visit the [PowerShell GitHub releases page](https://github.com/PowerShell/PowerShell/releases)
2. Download the appropriate installer for your system (e.g., `PowerShell-7.5.0-win-x64.msi` for 64-bit Windows)
3. Run the installer and follow the on-screen instructions
**Option 2: Install using winget (Windows 10/11)**
1. Open a command prompt or PowerShell window
2. Run the following command:
```
winget install --id Microsoft.PowerShell
```
**Option 3: Install using PowerShell script**
1. Open Windows PowerShell as administrator
2. Run the following commands:
```powershell
# Download the installation script
Invoke-WebRequest -Uri https://aka.ms/install-powershell.ps1 -OutFile install-powershell.ps1
# Install PowerShell 7.5
.\install-powershell.ps1 -UseMSI -Quiet
```
4. Verify the installation by opening PowerShell 7 from the Start menu
### Step 2: Install Required Dependencies
@ -37,7 +17,7 @@ This tool allows you to convert legacy `.xls` files stored in SharePoint to the
2. Right-click on PowerShell 7 in the Start menu and select "Run as administrator"
3. Navigate to the folder containing the converter files:
```
cd C:\path\to\SharepointXLS_to_XLSX
cd C:\path\to\XLS_to_XLSX
```
4. Run the dependency installer script:
```
@ -57,7 +37,7 @@ This tool allows you to convert legacy `.xls` files stored in SharePoint to the
1. Open PowerShell 7 as administrator
2. Navigate to the application folder:
```
cd C:\path\to\SharepointXLS_to_XLSX
cd C:\path\to\XLS_to_XLSX
```
3. Run the application in STA mode:
```

View File

@ -473,7 +473,7 @@ function Convert-Files {
try {
# Create a safe temporary path without spaces
$safeTempDir = Join-Path $env:TEMP "XLSConversion"
if (-not (Test-Path -Path $safeTempDir)) {
if (-not (Test-Path $safeTempDir)) {
New-Item -ItemType Directory -Path $safeTempDir -Force | Out-Null
}
@ -495,15 +495,7 @@ function Convert-Files {
$script:txtStatus.Text += "Opening workbook from: $safeOriginalPath`n"
try {
# Try opening with different recovery options
try {
$workbook = $excel.Workbooks.Open($safeOriginalPath)
}
catch {
$script:txtStatus.Text += "Standard open failed, trying with OpenAndRepair...`n"
$workbook = $excel.Workbooks.OpenAndRepair($safeOriginalPath)
}
$workbook = $excel.Workbooks.Open($safeOriginalPath)
$script:txtStatus.Text += "Workbook opened successfully`n"
# Create safe XLSX path
@ -513,99 +505,49 @@ function Convert-Files {
$script:txtStatus.Text += "Attempting to save as XLSX: $safeXlsxPath`n"
# Try multiple SaveAs approaches with progressive fallbacks
$saveSuccess = $false
# Approach 1: Standard SaveAs with explicit format
try {
$script:txtStatus.Text += "Trying standard SaveAs method...`n"
$excel.DisplayAlerts = $false
$workbook.SaveAs([string]$safeXlsxPath, [int]51) # 51 = xlOpenXMLWorkbook
$saveSuccess = $true
# Try different SaveAs approaches
try {
# Approach 1: Use FileFormat property
$excel.DefaultSaveFormat = 51 # xlOpenXMLWorkbook
$workbook.SaveAs($safeXlsxPath)
}
catch {
$script:txtStatus.Text += "First save attempt failed, trying alternate method...`n"
# Approach 2: Use explicit FileFormat
$workbook.SaveAs([string]$safeXlsxPath, [int]51)
}
Start-Sleep -Seconds 2 # Give the file system time to catch up
if (-not (Test-Path -LiteralPath $safeXlsxPath)) {
throw "File was not created after SaveAs operation"
}
$script:txtStatus.Text += "Save successful, verifying file...`n"
$fileInfo = Get-Item -LiteralPath $safeXlsxPath
$script:txtStatus.Text += "Saved file size: $($fileInfo.Length) bytes`n"
# Copy the file back to the original destination with spaces
$script:txtStatus.Text += "Copying to final destination: $xlsxPath`n"
Copy-Item -LiteralPath $safeXlsxPath -Destination $xlsxPath -Force
$script:txtStatus.Text += "Successfully saved XLSX file`n"
}
catch {
$script:txtStatus.Text += "Standard SaveAs failed: $($_.Exception.Message)`n"
}
# Approach 2: Try with compatibility options disabled
if (-not $saveSuccess) {
try {
$script:txtStatus.Text += "Trying SaveAs with compatibility options disabled...`n"
$excel.DisplayAlerts = $false
if ($workbook.PSObject.Properties.Name -contains "CheckCompatibility") {
$workbook.CheckCompatibility = $false
}
$workbook.SaveAs([string]$safeXlsxPath, [int]51)
$saveSuccess = $true
}
catch {
$script:txtStatus.Text += "Compatibility SaveAs failed: $($_.Exception.Message)`n"
$script:txtStatus.Text += "Error during SaveAs: $($_.Exception.Message)`n"
if ($_.Exception.HResult) {
$script:txtStatus.Text += "Error HResult: $($_.Exception.HResult)`n"
}
throw
}
# Approach 3: Try with Excel 2007-2013 format
if (-not $saveSuccess) {
try {
$script:txtStatus.Text += "Trying SaveAs with Excel 2007-2013 format...`n"
$excel.DisplayAlerts = $false
$workbook.SaveAs([string]$safeXlsxPath, [int]52) # 52 = xlExcel12 (Excel 2007-2013)
$saveSuccess = $true
}
catch {
$script:txtStatus.Text += "Excel 2007-2013 SaveAs failed: $($_.Exception.Message)`n"
}
}
# Approach 4: Last resort - try with Excel binary format then convert again
if (-not $saveSuccess) {
try {
$script:txtStatus.Text += "Trying intermediate binary format conversion...`n"
$excel.DisplayAlerts = $false
# First save as Excel Binary Workbook
$safeBinaryPath = [System.IO.Path]::ChangeExtension($safeXlsxPath, ".xlsb")
$workbook.SaveAs([string]$safeBinaryPath, [int]50) # 50 = xlExcel12 (Excel Binary)
$workbook.Close($false)
# Then open the binary and save as XLSX
$binaryWorkbook = $excel.Workbooks.Open($safeBinaryPath)
$binaryWorkbook.SaveAs([string]$safeXlsxPath, [int]51)
$binaryWorkbook.Close($false)
$saveSuccess = $true
}
catch {
$script:txtStatus.Text += "Binary conversion failed: $($_.Exception.Message)`n"
}
}
if (-not $saveSuccess) {
throw "All conversion methods failed. Unable to convert file."
}
Start-Sleep -Seconds 2 # Give the file system time to catch up
if (-not (Test-Path -LiteralPath $safeXlsxPath)) {
throw "File was not created after SaveAs operation"
}
$script:txtStatus.Text += "Save successful, verifying file...`n"
$fileInfo = Get-Item -LiteralPath $safeXlsxPath
$script:txtStatus.Text += "Saved file size: $($fileInfo.Length) bytes`n"
# Copy the file back to the original destination with spaces
$script:txtStatus.Text += "Copying to final destination: $xlsxPath`n"
Copy-Item -LiteralPath $safeXlsxPath -Destination $xlsxPath -Force
$script:txtStatus.Text += "Successfully saved XLSX file`n"
}
catch {
$script:txtStatus.Text += "Error during Excel operations: $($_.Exception.Message)`n"
$script:txtStatus.Text += "Error opening workbook: $($_.Exception.Message)`n"
throw
}
}
finally {
# Thorough cleanup of Excel objects
if ($workbook) {
try {
$workbook.Close($false)
@ -614,14 +556,6 @@ function Convert-Files {
catch { }
$workbook = $null
}
if ($binaryWorkbook) {
try {
$binaryWorkbook.Close($false)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($binaryWorkbook) | Out-Null
}
catch { }
$binaryWorkbook = $null
}
if ($excel) {
try {
$excel.Quit()