Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Feb 01, 2024 5:08 pm

Hi,

I am using FreeSpire.XLS to (attempt to) export all charts, in all sheets, of an XLSX file to .PNGs. In this example, my XLSX has 6 sheets, each containing a single graph. Below is my code (written in PowerShell). When running this code, it only exports up to sheet 3 (2). It can see up to sheet 6 (5), but doesn't export an image for anything above sheet 3 (2). More specifically, it doesn't seem to see that there is a chart on anything above sheet 3 (2), despite the fact that there is. Is this a bug?

Code: Select all
# Load the Spire.XLS assembly
Add-Type -Path "C:\schubgus\Spire.XLS.dll"

# Create an instance of the Workbook class
$workbook = New-Object Spire.Xls.Workbook

# Load a sample Excel file
$workbook.LoadFromFile("C:\schubgus\BD.xlsx")

# Iterate through all worksheets
foreach ($sheet in $workbook.Worksheets)
{
    Write-Host "Processing worksheet $($sheet.Name) with index $($sheet.Index)"
   
    # Check if the worksheet has charts
    if ($sheet.Charts.Count -gt 0)
    {
       # Save charts in the current worksheet as images
$imgs = $workbook.SaveChartAsImage($sheet)

# Output the count of images returned
Write-Host "Number of images returned: $($imgs.Length)"

# Save the images to png files
for ($i = 0; $i -lt $imgs.Length; $i++)
        {
            # Check if the current image is not null before saving
            if ($imgs[$i] -ne $null)
            {
                $fileName = "C:\schubgus\chart-$($sheet.Name)-$($sheet.Index).png"
                $imgs[$i].Save($fileName, [System.Drawing.Imaging.ImageFormat]::Png)
                Write-Host "Image $i saved for worksheet $($sheet.Name) with index $($sheet.Index) to $fileName"
            }
            else
            {
                Write-Host "Image $i is null and cannot be saved for worksheet $($sheet.Name) with index $($sheet.Index)."
            }
        }
    }
    else
    {
        Write-Host "No charts found in worksheet $($sheet.Name) with index $($sheet.Index)."
    }
}


Note that I have already validated that there is nothing wrong with my XLSX file, or my installation of FreeSpire.XLS. I have full administrative rights on this computer.

thereeltgb
 
Posts: 1
Joined: Thu Feb 01, 2024 5:00 pm

Fri Feb 02, 2024 1:36 am

Hello,

Thank you for your inquiry.
Please note that our free version of Spire.XLS has a 3-page limit for Excel to image conversion, so the result of your test is only 3 images. Also, we do not maintain the free version, so I suggest you to use our commercial version (Spire.XLS Pack Version:14.1) to test it, it contains more fixes and new features than the free version, and there is no page limitation for converting images just a warning watermark.
If you want to remove the warning watermark and other limitations, we can offer you a free one-month temporary license, please apply through this link:https://www.e-iceblue.com/TemLicense.html

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS