Hello,
I am trying to convert a worksheet to a .svg file, but aspose is returning a .png file instead. When I look at the specs listed here I can see the svg is a supported format for both ConvertWorksheetRequest and RangeConvertRequest, but the result is a png file. What am I missing? Here is my range convert code:
source_range = Range(
first_row=range_info["first_row"],
first_column=range_info["first_column"],
row_count=range_info["row_count"],
column_count=range_info["column_count"],
worksheet=range_info["worksheet"]
)
image_options = ImageOrPrintOptions(
image_format="svg",
)
range_convert_request = RangeConvertRequest(
source = source_range,
image_type= "svg",
image_or_print_options=image_options,
)
request = PostWorksheetCellsRangeToImageRequest(
name=aspose_file_name,
sheet_name=range_info["worksheet"],
range_convert_request=range_convert_request,
folder=aspose_folder,
storage_name=ASPOSE_STORAGE,
)
tmp_path = cells_api.post_worksheet_cells_range_to_image(request)
logger.info(f"response: {tmp_path}")
mime_type = None
with open(tmp_path, "rb") as temp_file:
file_bytes = temp_file.read()
mime_type = get_mime_type_from_bytes(file_bytes=file_bytes)
logger.info(f"mime_type: {mime_type}")
@jamieMacabacus
To convert a worksheet to an SVG file using Aspose.Cells, you need to ensure that you are correctly specifying the output format in your request. Based on the code snippet you provided, it seems you are using the RangeConvertRequest
to convert a specific range of the worksheet. However, if you are receiving a PNG file instead of SVG, there are a few things to check:
-
Image Format Specification: Ensure that the image_format
in your ImageOrPrintOptions
is set to "svg"
as you have done. This is correct.
-
Request Parameters: Make sure that the image_type
in your RangeConvertRequest
is also set to "svg"
. This should align with the image_format
you specified.
-
API Endpoint: Verify that you are using the correct API endpoint for converting the worksheet to an image format. The endpoint should support SVG as an output format.
-
Check API Documentation: Review the API documentation to confirm that SVG is supported for the specific operation you are trying to perform. Sometimes, certain formats may have limitations based on the context of the request.
Here is a sample code snippet that demonstrates how to convert a worksheet range to SVG:
source_range = Range(
first_row=range_info["first_row"],
first_column=range_info["first_column"],
row_count=range_info["row_count"],
column_count=range_info["column_count"],
worksheet=range_info["worksheet"]
)
image_options = ImageOrPrintOptions(
image_format="svg",
)
range_convert_request = RangeConvertRequest(
source=source_range,
image_type="svg",
image_or_print_options=image_options,
)
request = PostWorksheetCellsRangeToImageRequest(
name=aspose_file_name,
sheet_name=range_info["worksheet"],
range_convert_request=range_convert_request,
folder=aspose_folder,
storage_name=ASPOSE_STORAGE,
)
tmp_path = cells_api.post_worksheet_cells_range_to_image(request)
logger.info(f"response: {tmp_path}")
mime_type = None
with open(tmp_path, "rb") as temp_file:
file_bytes = temp_file.read()
mime_type = get_mime_type_from_bytes(file_bytes=file_bytes)
logger.info(f"mime_type: {mime_type}")
If you continue to receive a PNG file, consider checking the API response for any error messages or warnings that might indicate why the conversion is defaulting to PNG. Additionally, you may want to reach out to Aspose support for further assistance if the issue persists.
For more details on the conversion capabilities, you can refer to the official documentation on converting worksheets to various formats here and here.
If you have any further questions or need additional assistance, feel free to ask!
Thank you bot but you posted the same code as my example lol
@jamieMacabacus The parameters here need to be modified:
image_options = ImageOrPrintOptions(
image_format="svg",
)
Change to
image_options = ImageOrPrintOptions(
Image_type="svg",
)
We have created a complete sample code for this, you can refer to it:aspose-cells-cloud-python/examples/Example_ConvertRangeToImage.py at master · aspose-cells-cloud/aspose-cells-cloud-python · GitHub
1 Like
Awesome, that worked! Thank you so much
@jamieMacabacus
You are welcome! If you has any issue, please feel free to contact us.