OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
657 stars 94 forks source link

How to access the currently displayed / rounded off value of a cell in Excel #4625

Closed DipanshuJuneja closed 3 days ago

DipanshuJuneja commented 1 week ago

How can I access the currently displayed value of a given cell range but not the actual value of that cell? For example - see this below image, where I have not increased the width of the cell enough to display the actual value which is getting rounded off.

If I try to get the Rangefor this cell and access the valuesproperty, it gives back 12.001123. I tried the textproperty as well from the documentation, but it gives back the 12.001123as well. I want to access the value that is showing up right now in the UI i.e. 12.00112 after the rounding off

image

shanshanzheng-dev commented 1 week ago

Hi, @DipanshuJuneja Thanks for reaching us. Could you provide more detail scenario? If you want to set values property, let it show up the rounding off value, just like this: image Or you want to set rounding off value use some JS API?

DipanshuJuneja commented 1 week ago

Hi @shanshanzheng-dev thanks for your quick response on the query. I simply want to get/access the rounded off value through Office JS, in this case 12.00112, since the values property on the Range class gives back the actual 12.001123.

shanshanzheng-dev commented 1 week ago

Hi @DipanshuJuneja Thanks for confirming. Could you take a look this reference if it can meet your need: https://learn.microsoft.com/en-us/javascript/api/excel/excel.formattednumbercellvalue?view=excel-js-preview? And this is an example: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-formatted-number.yaml

microsoft-github-policy-service[bot] commented 6 days ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

microsoft-github-policy-service[bot] commented 3 days ago

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.