Compare commits
2 Commits
7822f074c4
...
b45a6c490a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b45a6c490a | ||
|
|
eb0f2299d3 |
12
MainForm.ps1
12
MainForm.ps1
@ -60,14 +60,6 @@ $btnConvert.Size = New-Object System.Drawing.Size(120, 30)
|
||||
$btnConvert.Text = "Convert to XLSX"
|
||||
$form.Controls.Add($btnConvert)
|
||||
|
||||
# Create Checkbox for Recursive Listing
|
||||
$chkRecursive = New-Object System.Windows.Forms.CheckBox
|
||||
$chkRecursive.Location = New-Object System.Drawing.Point(20, 205)
|
||||
$chkRecursive.Size = New-Object System.Drawing.Size(150, 20)
|
||||
$chkRecursive.Text = "List Recursively"
|
||||
$chkRecursive.Checked = $true # Default to recursive
|
||||
$form.Controls.Add($chkRecursive)
|
||||
|
||||
# Create Status TextBox (Top Right)
|
||||
$txtStatus = New-Object System.Windows.Forms.TextBox
|
||||
$txtStatus.Location = New-Object System.Drawing.Point(450, 20) # Top Right Corner
|
||||
@ -121,8 +113,7 @@ $form.Controls.AddRange(@(
|
||||
$txtFolder,
|
||||
$btnBrowse,
|
||||
$btnSaveConfig,
|
||||
$btnConnect,
|
||||
$chkRecursive # Add the checkbox to the form
|
||||
$btnConnect
|
||||
))
|
||||
|
||||
# Load configuration
|
||||
@ -158,7 +149,6 @@ $btnBrowse.Add_Click({
|
||||
# Store the DataGridView and txtStatus in script scope
|
||||
$script:dataGridView = $dataGridView
|
||||
$script:txtStatus = $txtStatus
|
||||
$script:chkRecursive = $chkRecursive
|
||||
|
||||
# Show form
|
||||
$form.Add_Shown({ $form.Activate() })
|
||||
|
||||
85
README.md
Normal file
85
README.md
Normal file
@ -0,0 +1,85 @@
|
||||
# SharePoint XLS to XLSX Converter
|
||||
|
||||
This tool allows you to convert legacy `.xls` files stored in SharePoint to the modern `.xlsx` format. The converter maintains the original folder structure and automatically uploads the converted files back to SharePoint.
|
||||
|
||||
## Installation Instructions
|
||||
|
||||
### Step 1: Install PowerShell 7.5
|
||||
|
||||
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
|
||||
4. Verify the installation by opening PowerShell 7 from the Start menu
|
||||
|
||||
### Step 2: Install Required Dependencies
|
||||
|
||||
1. Download the XLS to XLSX Converter files to a folder on your computer
|
||||
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\XLS_to_XLSX
|
||||
```
|
||||
4. Run the dependency installer script:
|
||||
```
|
||||
.\Install-Dependencies.ps1
|
||||
```
|
||||
5. The script will install the required Microsoft Graph modules and verify that Excel is installed
|
||||
|
||||
### Step 3: Configure Microsoft Graph Authentication
|
||||
|
||||
1. The first time you run the application, you'll need to authenticate with Microsoft Graph
|
||||
2. Follow the prompts to sign in with your Microsoft 365 account that has access to the SharePoint site
|
||||
|
||||
## Operating the Program
|
||||
|
||||
### Starting the Application
|
||||
|
||||
1. Open PowerShell 7 as administrator
|
||||
2. Navigate to the application folder:
|
||||
```
|
||||
cd C:\path\to\XLS_to_XLSX
|
||||
```
|
||||
3. Run the application in STA mode:
|
||||
```
|
||||
pwsh -STA -File .\MainForm.ps1
|
||||
```
|
||||
|
||||
### Using the Application
|
||||
|
||||
1. **Configure SharePoint Settings**:
|
||||
- Enter your SharePoint site URL (e.g., `https://yourcompany.sharepoint.com/sites/yoursite`)
|
||||
- Enter the document library name (e.g., `Shared Documents` or `Documents`)
|
||||
- Click "Save Config" to save these settings for future use
|
||||
|
||||
2. **Connect to SharePoint**:
|
||||
- Click the "Connect" button to authenticate with SharePoint
|
||||
- Follow any authentication prompts that appear
|
||||
|
||||
3. **Select a Folder** (Optional):
|
||||
- Click "Browse" to navigate to a specific folder in SharePoint
|
||||
- If no folder is selected, the application will work with files in the root of the document library
|
||||
|
||||
4. **List XLS Files**:
|
||||
- Click "List XLS Files" to find all `.xls` files in the selected location
|
||||
- The files will be displayed in the grid at the bottom of the window
|
||||
|
||||
5. **Convert Files**:
|
||||
- Click "Convert to XLSX" to begin the conversion process
|
||||
- The application will:
|
||||
- Download each `.xls` file
|
||||
- Convert it to `.xlsx` format using Excel
|
||||
- Upload the converted file back to the same location in SharePoint
|
||||
- Progress and status messages will appear in the text box on the right
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- **Authentication Issues**: Ensure you have the correct permissions to access the SharePoint site
|
||||
- **Excel Errors**: Make sure Microsoft Excel is installed and properly licensed
|
||||
- **File Access Errors**: Check that you have permission to read and write to the SharePoint libraries
|
||||
- **Conversion Failures**: Some very old or complex Excel files may not convert properly
|
||||
|
||||
## Notes
|
||||
|
||||
- The application requires an active internet connection
|
||||
- Large files may take longer to download, convert, and upload
|
||||
- The original `.xls` files remain unchanged in SharePoint
|
||||
@ -259,24 +259,12 @@ function List-XlsFiles {
|
||||
#$items = Get-MgDriveItemChild -DriveId $drive.Id -DriveItemId $folderItem.id
|
||||
|
||||
# Call the recursive function to process files and subfolders
|
||||
if ($script:chkRecursive.Checked) {
|
||||
$script:txtStatus.Text += "Listing files recursively...`n"
|
||||
$fileList = Get-XlsFilesRecursive -DriveId $drive.Id -DriveItemId $folderItem.id
|
||||
} else {
|
||||
$script:txtStatus.Text += "Listing files in current folder only...`n"
|
||||
$script:txtStatus.Text += "Listing files in current folder...`n"
|
||||
$fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $folderItem.id
|
||||
}
|
||||
} else {
|
||||
$script:txtStatus.Text += "Searching in root folder`n"
|
||||
|
||||
if ($script:chkRecursive.Checked) {
|
||||
$script:txtStatus.Text += "Listing files recursively...`n"
|
||||
$fileList = Get-XlsFilesRecursive -DriveId $drive.Id -DriveItemId $root.Id
|
||||
} else {
|
||||
$script:txtStatus.Text += "Listing files in current folder only...`n"
|
||||
$script:txtStatus.Text += "Searching in root folder...`n"
|
||||
$fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $root.Id
|
||||
}
|
||||
}
|
||||
|
||||
if ($fileList.Count -gt 0) {
|
||||
$script:txtStatus.Text += "Saving file list...`n"
|
||||
@ -299,55 +287,6 @@ function List-XlsFiles {
|
||||
}
|
||||
}
|
||||
|
||||
# Recursive function to get XLS files from a folder and its subfolders
|
||||
function Get-XlsFilesRecursive {
|
||||
param (
|
||||
[string]$DriveId,
|
||||
[string]$DriveItemId
|
||||
)
|
||||
|
||||
$allFiles = @()
|
||||
|
||||
# Check if DriveId or DriveItemId is null or empty
|
||||
if ([string]::IsNullOrEmpty($DriveId)) {
|
||||
$script:txtStatus.Text += "Error: DriveId is null or empty`n"
|
||||
return $allFiles
|
||||
}
|
||||
if ([string]::IsNullOrEmpty($DriveItemId)) {
|
||||
$script:txtStatus.Text += "Error: DriveItemId is null or empty`n"
|
||||
return $allFiles
|
||||
}
|
||||
|
||||
# Get items in the current folder
|
||||
try {
|
||||
$items = Get-MgDriveItemChild -DriveId $DriveId -DriveItemId $DriveItemId -ErrorAction Stop
|
||||
}
|
||||
catch {
|
||||
$script:txtStatus.Text += "Error getting items: $($_.Exception.Message)`n"
|
||||
return $allFiles
|
||||
}
|
||||
|
||||
foreach ($item in $items) {
|
||||
$script:txtStatus.Text += "Checking item: $($item.Name)`n"
|
||||
|
||||
# If it's a folder, recurse into it
|
||||
if ($item.Folder -and $item.Folder.ChildCount -ne $null) { # Check if it's a folder AND has children
|
||||
$script:txtStatus.Text += "Found folder: $($item.Name), recursing...`n"
|
||||
$allFiles += Get-XlsFilesRecursive -DriveId $DriveId -DriveItemId $item.Id
|
||||
}
|
||||
# If it's an Excel file, add it to the list
|
||||
elseif ($item.Name -like "*.xls" -or $item.Name -like "*.xlsx" -or $item.Name -like "*.xlsm") {
|
||||
$script:txtStatus.Text += "Found XLS file: $($item.Name)`n"
|
||||
$allFiles += [PSCustomObject]@{
|
||||
OriginalPath = $item.WebUrl
|
||||
OriginalFileName = $item.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $allFiles
|
||||
}
|
||||
|
||||
# Function to get XLS files from only the current folder
|
||||
function Get-XlsFilesCurrentFolder {
|
||||
param (
|
||||
@ -379,8 +318,8 @@ function Get-XlsFilesCurrentFolder {
|
||||
foreach ($item in $items) {
|
||||
$script:txtStatus.Text += "Checking item: $($item.Name)`n"
|
||||
|
||||
# If it's an Excel file, add it to the list
|
||||
if ($item.Name -like "*.xls" -or $item.Name -like "*.xlsx" -or $item.Name -like "*.xlsm") {
|
||||
# If it's an Excel file, add it to the list - only .xls files, not .xlsx
|
||||
if ($item.Name -like "*.xls" -and -not ($item.Name -like "*.xlsx")) {
|
||||
$script:txtStatus.Text += "Found XLS file: $($item.Name)`n"
|
||||
$allFiles += [PSCustomObject]@{
|
||||
OriginalPath = $item.WebUrl
|
||||
|
||||
Loading…
Reference in New Issue
Block a user