Closed georgechr closed 6 years ago
I'm not able to reproduce this. What version of Office are you on?
@Rick-Kirkham thanks for your reply. I am on Excel 2016 16.0.7726.1059
Below are the screenshots from the debugger and actual selected content language
I have, same results. Office.context.contentLanguage
still prints "en-US"
The issue happens in Excel, not Word. Nevertheless, the content language is not part of the Excel API and can be accessed synchronously so just printing Office.context.contentLanguage
should work.
So, is this an actual issue? Should we come up with a workaround until is fixed? It is causing issues when our add-ins are sorting and then displaying dates in Excel worksheets (half of them on average - the ones that can get parsed as US dates - are displayed wrong)
@georgechr I've been on vacation. If you're still experiencing this issue could you provide me with a complete Excel.run? Just enough to illustrate the issue. I cannot reproduce this error with my own code.
This reproduces it for me i.e. it always prints 'en-US' in the selected cell.
Excel.run((context) => {
const range = context.workbook.getSelectedRange();
range.values = [[Office.context.contentLanguage]];
await context.sync();
}).catch(function(_) {
})
Your code works perfectly for me. I get en-GB when I switch to English United Kingdom. You do have to close Excel and reopen it for the change to take effect. I'm on subscription Office (Click-to-Run). You are on Office 2016 MSI. This looks like a bug, so please raise the issue on the repo office-js
. Be sure to specify your Excel version.
At any rate, its not a documentation problem, and that's what the issues for this repo are intended to track, so I'm going to have to close this here.
According to the documentation
Office.context.contentLanguage
should get the locale as specified in the Office host application. Instead, it seems to always return 'en-US' no matter what the editing language is set as. The same issue appears for displayLanguage as well.Article URL
https://dev.office.com/reference/add-ins/shared/office.context.contentlanguage