Convert Microsoft Excel to PNG in Python

Hi. When I’m converting an xlsx file to png (python request) the result I see is file is approximately as whole a4 page format. Is there possibility to convert only nonempty part of spreadsheet (for example, current selection, a range of cells or so on)?

@fogofhedgehog

You may use convertRange and skipEmptyRowsAndColumns properties of LoadOptions to print your required area, when you convert Microsoft Excel to PNG with GroupDocs.Conversion Cloud API. Please check the following documentation for more details. It will help you to accomplish the task

How to Convert XLSX to PNG in Python

# Import module
import groupdocs_conversion_cloud
from shutil import copyfile

# Get your app_sid and app_key at https://dashboard.groupdocs.cloud (free registration is required).
app_sid = "xxxxxxx-xxxxx-xxxx-xxxxx-xxxxxxxxxx"
app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Create instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(app_sid, app_key)
file_api = groupdocs_conversion_cloud.FileApi.from_keys(app_sid, app_key)

try:

        #upload soruce file to storage
        filename = 'Book1.xlsx'
        remote_name = 'Book1.xlsx'
        output_name= 'Book1_LoadOptions.png'
        strformat='png'

        request_upload = groupdocs_conversion_cloud.UploadFileRequest(remote_name,filename)
        response_upload = file_api.upload_file(request_upload)
        
        #Convert XLSX to PNG
        settings = groupdocs_conversion_cloud.ConvertSettings()
        settings.file_path =remote_name
        settings.format = strformat
        settings.output_path = output_name

        loadOptions = groupdocs_conversion_cloud.SpreadsheetLoadOptions()
        loadOptions.hide_comments = True
        loadOptions.one_page_per_sheet = True
        loadOptions.convert_range = 'I5:K6'

        settings.load_options = loadOptions

        convertOptions = groupdocs_conversion_cloud.PngConvertOptions()
        convertOptions.from_page = 1
        convertOptions.pages_count = 1
            
        settings.convert_options = convertOptions
                
        requestConvertXLSXtoPngPython = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
        responseConvertXLSXtoPngPython = convert_api.convert_document(requestConvertXLSXtoPngPython)
        print("Document converted successfully: " + str(responseConvertXLSXtoPngPython))
        
        #Download Document from Storage        
        request_download = groupdocs_conversion_cloud.DownloadFileRequest(output_name)
        response_download = file_api.download_file(request_download)
       
        copyfile(response_download, output_name)
        print("Result {}".format(response_download))
        
except groupdocs_conversion_cloud.ApiException as e:
        print("Exception when calling get_supported_conversion_types: {0}".format(e.message))

Thanks a lot, Tilal. It was perfectly useful for me. Unfortunately the whole navigation on this service is very uncomfortable and unfriendly - thats why I’ve asked this question here. I’ve tried to find it by myself, but failed. Fortunately you helped me. Many thanks once more!

1 Like