Compare commits
No commits in common. "b45a6c490a292b6caff9078fed3d6642fc162bd8" and "7822f074c4cf5e07914dbe3e3ce3849b5450db08" have entirely different histories.
b45a6c490a
...
7822f074c4
12
MainForm.ps1
12
MainForm.ps1
@ -60,6 +60,14 @@ $btnConvert.Size = New-Object System.Drawing.Size(120, 30)
|
|||||||
$btnConvert.Text = "Convert to XLSX"
|
$btnConvert.Text = "Convert to XLSX"
|
||||||
$form.Controls.Add($btnConvert)
|
$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)
|
# Create Status TextBox (Top Right)
|
||||||
$txtStatus = New-Object System.Windows.Forms.TextBox
|
$txtStatus = New-Object System.Windows.Forms.TextBox
|
||||||
$txtStatus.Location = New-Object System.Drawing.Point(450, 20) # Top Right Corner
|
$txtStatus.Location = New-Object System.Drawing.Point(450, 20) # Top Right Corner
|
||||||
@ -113,7 +121,8 @@ $form.Controls.AddRange(@(
|
|||||||
$txtFolder,
|
$txtFolder,
|
||||||
$btnBrowse,
|
$btnBrowse,
|
||||||
$btnSaveConfig,
|
$btnSaveConfig,
|
||||||
$btnConnect
|
$btnConnect,
|
||||||
|
$chkRecursive # Add the checkbox to the form
|
||||||
))
|
))
|
||||||
|
|
||||||
# Load configuration
|
# Load configuration
|
||||||
@ -149,6 +158,7 @@ $btnBrowse.Add_Click({
|
|||||||
# Store the DataGridView and txtStatus in script scope
|
# Store the DataGridView and txtStatus in script scope
|
||||||
$script:dataGridView = $dataGridView
|
$script:dataGridView = $dataGridView
|
||||||
$script:txtStatus = $txtStatus
|
$script:txtStatus = $txtStatus
|
||||||
|
$script:chkRecursive = $chkRecursive
|
||||||
|
|
||||||
# Show form
|
# Show form
|
||||||
$form.Add_Shown({ $form.Activate() })
|
$form.Add_Shown({ $form.Activate() })
|
||||||
|
|||||||
85
README.md
85
README.md
@ -1,85 +0,0 @@
|
|||||||
# 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,12 +259,24 @@ function List-XlsFiles {
|
|||||||
#$items = Get-MgDriveItemChild -DriveId $drive.Id -DriveItemId $folderItem.id
|
#$items = Get-MgDriveItemChild -DriveId $drive.Id -DriveItemId $folderItem.id
|
||||||
|
|
||||||
# Call the recursive function to process files and subfolders
|
# Call the recursive function to process files and subfolders
|
||||||
$script:txtStatus.Text += "Listing files in current folder...`n"
|
if ($script:chkRecursive.Checked) {
|
||||||
$fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $folderItem.id
|
$script:txtStatus.Text += "Listing files recursively...`n"
|
||||||
|
$fileList = Get-XlsFilesRecursive -DriveId $drive.Id -DriveItemId $folderItem.id
|
||||||
} else {
|
} else {
|
||||||
$script:txtStatus.Text += "Searching in root folder...`n"
|
$script:txtStatus.Text += "Listing files in current folder only...`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"
|
||||||
$fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $root.Id
|
$fileList = Get-XlsFilesCurrentFolder -DriveId $drive.Id -DriveItemId $root.Id
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($fileList.Count -gt 0) {
|
if ($fileList.Count -gt 0) {
|
||||||
$script:txtStatus.Text += "Saving file list...`n"
|
$script:txtStatus.Text += "Saving file list...`n"
|
||||||
@ -287,6 +299,55 @@ 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 to get XLS files from only the current folder
|
||||||
function Get-XlsFilesCurrentFolder {
|
function Get-XlsFilesCurrentFolder {
|
||||||
param (
|
param (
|
||||||
@ -318,8 +379,8 @@ function Get-XlsFilesCurrentFolder {
|
|||||||
foreach ($item in $items) {
|
foreach ($item in $items) {
|
||||||
$script:txtStatus.Text += "Checking item: $($item.Name)`n"
|
$script:txtStatus.Text += "Checking item: $($item.Name)`n"
|
||||||
|
|
||||||
# If it's an Excel file, add it to the list - only .xls files, not .xlsx
|
# If it's an Excel file, add it to the list
|
||||||
if ($item.Name -like "*.xls" -and -not ($item.Name -like "*.xlsx")) {
|
if ($item.Name -like "*.xls" -or $item.Name -like "*.xlsx" -or $item.Name -like "*.xlsm") {
|
||||||
$script:txtStatus.Text += "Found XLS file: $($item.Name)`n"
|
$script:txtStatus.Text += "Found XLS file: $($item.Name)`n"
|
||||||
$allFiles += [PSCustomObject]@{
|
$allFiles += [PSCustomObject]@{
|
||||||
OriginalPath = $item.WebUrl
|
OriginalPath = $item.WebUrl
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user