Wrong number format in embedded graphs

Hi,

we’ve noticed the number format does not respect the locale when embedded graphs are converted to images. Graphs data comes from Excel and we’ve made sure both Word and Excel have appropriate languages, locale and number format settings. When viewing graph inside Word the number format is correct, but when your service converts graph to image, the number format is always in en-US format. The endpoint we are using is https://api.aspose.cloud/v4.0/words/online/put/saveAs.

Can you advise on how to achieve the number format being in desired locale?

Thanks.

@futurarazvoj

Why the numbers are always shown in en‑US format

When a DOCX that contains an embedded Excel chart is rendered to an image, Aspose.Words uses the culture (locale) that is supplied to the conversion engine.
If no locale is provided the engine falls back to the default en‑US culture, so decimal separators, thousands separators, etc., are formatted in the US style.

How to make the chart use your own locale

Pass a loadOptions object with the locale property (a valid .NET culture name such as de-DE, fr-FR, ja-JP, …) to the PUT /words/online/put/saveAs endpoint. The locale is applied while the document (and the embedded chart) is loaded, and the rendered image will contain numbers formatted according to that culture.


1. Request body (multipart/form‑data)

Part name Content
document The original .docx (binary)
loadOptions JSON, e.g. { "locale": "de-DE" }
saveOptions JSON that tells the API to render an image, e.g. { "saveFormat": "png" }

2. cURL example

curl -X PUT "https://api.aspose.cloud/v4.0/words/online/put/saveAs" \
     -H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \
     -F "document=@MyDocument.docx;type=application/vnd.openxmlformats-officedocument.wordprocessingml.document" \
     -F 'loadOptions={"locale":"de-DE"};type=application/json' \
     -F 'saveOptions={"saveFormat":"png"};type=application/json' \
     -o MyDocument_page1.png

Replace <YOUR_ACCESS_TOKEN> with a valid OAuth token.
Change "de-DE" to the locale you need (fr-FR, es-ES, etc.). The resulting PNG will show the chart with numbers formatted for that culture.


3. Using the Aspose.Words Cloud .NET SDK

using Aspose.Words.Cloud.Sdk;
using Aspose.Words.Cloud.Sdk.Model;
using System.IO;

// 1. Configure the client
var config = new Configuration
{
    ClientId = "<YOUR_CLIENT_ID>",
    ClientSecret = "<YOUR_CLIENT_SECRET>"
};
var wordsApi = new WordsApi(config);

// 2. Load the DOCX as a stream
using var docStream = File.OpenRead("MyDocument.docx");

// 3. Prepare load options with the required locale
var loadOptions = new LoadOptions
{
    Locale = "de-DE"          // <-- your desired culture
};

// 4. Prepare save options for an image
var saveOptions = new ImageSaveOptionsData
{
    SaveFormat = "png"
};

// 5. Call the online conversion endpoint
var result = wordsApi.PutSaveAsOnline(
    document: docStream,
    saveOptions: saveOptions,
    loadOptions: loadOptions);

// 6. Write the returned image to disk
File.WriteAllBytes("MyDocument_page1.png", result);
  • LoadOptions – contains the Locale property.
  • ImageSaveOptionsData – tells the service to produce a PNG (or any other image format supported by SaveFormat).

4. If you cannot modify the request (e.g., a third‑party service)

Approach How it works
Convert via PDF first :one: Convert DOCX → PDF using the same loadOptions.locale. :two: Convert the PDF → PNG (or another image). The PDF already contains the correctly formatted chart, so the second step does not need any locale handling.
Post‑process the image Render the chart as SVG (or a high‑resolution PNG) and run a script that replaces the numeric strings with the desired formatting. This is a fragile fallback and should be used only when the locale option cannot be set.

TL;DR

  1. Add loadOptions.locale (e.g., "de-DE") to the PUT /words/online/put/saveAs request.
  2. The locale is applied while the document (and its embedded chart) is loaded, so the rendered image shows numbers in the correct format.
  3. Use the cURL snippet or the .NET SDK example above to see the exact request structure.

If the output still appears in en‑US format, double‑check that the loadOptions part is correctly named and that the JSON is well‑formed. Feel free to share the exact request you are sending for further troubleshooting.

We’re actually converting to html, but for the sake of testing, we’ve tried to use your cURL approach with png. The PHP code:

$ch = curl_init();

// Set the URL
curl_setopt($ch, CURLOPT_URL, 'https://api.aspose.cloud/v4.0/words/online/put/saveAs');

// Set method to PUT
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

// Set authorization header
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer <YOUR_ACCESS_TOKEN>',
]);

// Build multipart form data
$postFields = [
    'document' => '<PATH_TO_DOCUMENT>',
    'loadOptions' => json_encode(['locale' => 'de-DE']),
    'saveOptions' => json_encode(['saveFormat' => 'png']),
];

curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

// Return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute request
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    dump( 'Error:' . curl_error($ch) );
} else {
    // Save response to file
    file_put_contents('MyDocument_page2.png', $response);
}

// Close cURL handle
curl_close($ch);

The file is created, but its content is a response indicating error:

{
  "Error": {
    "Code": "ErrorInvalidInputData",
    "Message": "SaveFormat is required.",
    "Description": "Operation Failed. The input data is not valid."
  },
  "RequestId": "3253a18ffef23562eda0af25345af369"
}

I will check it and share the information.

1 Like