Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localized Formatting via FormattedNumberCellValue #5070

Open
e16n opened this issue Feb 25, 2025 · 4 comments
Open

Localized Formatting via FormattedNumberCellValue #5070

e16n opened this issue Feb 25, 2025 · 4 comments
Assignees
Labels
Area: Excel Feedback on Excel content Needs: attention 👋 Waiting on Microsoft to provide feedback Type: product question Question about the Office Add-ins platform or Office JavaScript APIs

Comments

@e16n
Copy link

e16n commented Feb 25, 2025

Hello, can you please confirm that it is not currently possible to use FormattedNumberCellValue with a localized date format? I cannot find an equivalent to Excel.Range.numberFormatLocal. Therefore, I cannot reliably format my customFunction output via FormattedNumberCellValue for all locales. It must be done via Excel.RequestContext.sync which is not ideal with numerous simultaneous custom functions.

e.g., I am in the US and am returning the following from a custom function:

const fmtNumCellVal: Excel.FormattedNumberCellValue = {
  type: Excel.CellValueType.formattedNumber,
  basicValue: 45708,
  basicType: Excel.RangeValueType.double,
  numberFormat: storedShortDatePattern,
}

...where storedShortDatePattern is retrieved from application.cultureInfo.datetimeFormat.shortDatePattern
(shortDatePattern).

When my Excel-for-Web Regional Settings (File > Options) are set to 'English (United States)' (en-US; "m/d/yyyy") the static serial date is rendered and formatted properly. However, if I change my Excel-for-Web Regional Settings to 'French (France)' (fr-FR; jj/mm/aaaa'), #VALUE! is rendered in the cell.

From the documentation, it seems like this is not possible. numberFormat appears to only support a localized accessor.

Thanks.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label Feb 25, 2025
@isabela-dominguez isabela-dominguez added Area: Excel Feedback on Excel content Type: product question Question about the Office Add-ins platform or Office JavaScript APIs Needs: attention 👋 Waiting on Microsoft to provide feedback and removed Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP labels Mar 3, 2025
@isabela-dominguez
Copy link
Collaborator

Thank you for sharing this issue @e16n. Connecting you with @XuanZhouMSFT who may be able to help.

@AlexJerabek
Copy link
Collaborator

Hi @e16n,

Have you tried using valuesAsJsonLocal? That should let you set a FormattedNumberCellValue with a localized numberFormat string.

That said, while this will work if you set the FormattedNumberCellValue using valuesAsJsonLocal, it won't work if you try to return the same value as a result of a custom function. Custom functions always use "en-us" locale for parsing its results while valuesAsJsonLocal uses the current user locale. This is a gap in the custom functions platform.

@e16n
Copy link
Author

e16n commented Mar 5, 2025

Hi @e16n,

Have you tried using valuesAsJsonLocal? That should let you set a FormattedNumberCellValue with a localized numberFormat string.

That said, while this will work if you set the FormattedNumberCellValue using valuesAsJsonLocal, it won't work if you try to return the same value as a result of a custom function. Custom functions always use "en-us" locale for parsing its results while valuesAsJsonLocal uses the current user locale. This is a gap in the custom functions platform.

Thanks for the response, but the question pertains to a FormattedNumberCellValue, not a Range.

@AlexJerabek
Copy link
Collaborator

AlexJerabek commented Mar 5, 2025

Thanks for the response, but the question pertains to a FormattedNumberCellValue, not a Range.

Right, but how are you getting your CellValue objects if not through a Range object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Excel Feedback on Excel content Needs: attention 👋 Waiting on Microsoft to provide feedback Type: product question Question about the Office Add-ins platform or Office JavaScript APIs
Projects
None yet
Development

No branches or pull requests

4 participants