This function converts an Excel worksheet to an image.

function Convert-ExcelToImage {
    param (
        # The path for the Excel workbook file.
        [Parameter(Mandatory=$true, Position=0)]
        [ValidateScript({(Test-Path -Path $_ -ErrorAction SilentlyContinue)})]

        # The path for the image file.
        [Parameter(Mandatory=$true, Position=1)]
        [ValidateScript({(Test-Path -Path (Split-Path $_ -Parent) -ErrorAction SilentlyContinue)})]

        # The path for the folder containing the XLS Converter program installation.
        [Parameter(Mandatory=$true, Position=2)]
        [ValidateScript({(Test-Path -Path $_ -ErrorAction SilentlyContinue)})]

        # The name of worksheet to convert.
        [Parameter(Mandatory=$true, Position=3)]

    try {
        # Import the XLS Converter Functions from the Spire DLL
        ImportXLSConverterFunctions -XlsConverterFolderPath $xlsConverterFolderPath

        # Create Spire.XLS workbook and load it with the template contents
        Write-Information "Creating a Spire.XLS workbook with the Excel file contents."
        $workbook = [Spire.Xls.Workbook]::new()
        $workbook.LoadFromFile($excelWorkbookFilePath, [Spire.Xls.ExcelVersion]::Version2016)

        # Perform the conversion
        $workbook.ConverterSetting.SheetFitToPage = $true

        # Success
        return $true
    catch {
        Write-Error "Error on line $($_.InvocationInfo.ScriptLineNumber) while converting Excel workbook to an image. `r`n$($_.Exception.Message)"
        return $false