none
How to write a number value in the excel cell in Text Format using office js? RRS feed

  • Question

  • Hello , 

       I am currently developing the task pane apps for Excel 2013 using office js 1.0.

       When i write the data "07054","08902" into excel cells , it is treated by the excel in Number format and displayed as 7054, 8902 (with preceding 0's removed). I tried adding single quotes(') before value .. it works but comes out with warning symbol on the excel cell.. 

        is there a way to achieve this with office js .. without using quotes ?? 

    Find my sample code here 

    Office.context.document.setSelectedDataAsync("'04567", 
                                                  function (asyncResult) {
      if (asyncResult.status == "failed") {
        showMessage("Action failed with error: " + asyncResult.error.message);
      }
    });

    regards,
    Ram

     

    Wednesday, November 26, 2014 7:01 AM

Answers

  • Hi Ram,

    Based on the description, you want to set the data with text format which was using setSelectedDataAsync method to write to cell.

    As far as I know, adding single quotes is the simplest way to achieve the goal.

    >>it works but comes out with warning symbol on the excel cell.. <<

    The waring symbol means that numbers stored as text, this feature is provied by Excel applicaiton. You can disable this feature as figure below:

    I also suggest that you update JavaScript API for Office and manifest schema files to 1.1 because the latest version provide more powerful API.

    You can get more detail about how to update from link below:

    How to: Update the JavaScript API for Office and manifest schema files in your Visual Studio project from version 1.0 to 1.1

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, November 27, 2014 7:06 AM
    Moderator
  • Hi Ram1989,

    >>Any alternative idea to get it with Office JS ?<<

    No, the feature is provied by Excel application. We can only use Office.JS to write the data into spreadsheet, but we can't change the feature provieded by Excel appliction.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 3, 2014 7:11 AM
    Moderator

All replies

  • Hi Ram,

    Based on the description, you want to set the data with text format which was using setSelectedDataAsync method to write to cell.

    As far as I know, adding single quotes is the simplest way to achieve the goal.

    >>it works but comes out with warning symbol on the excel cell.. <<

    The waring symbol means that numbers stored as text, this feature is provied by Excel applicaiton. You can disable this feature as figure below:

    I also suggest that you update JavaScript API for Office and manifest schema files to 1.1 because the latest version provide more powerful API.

    You can get more detail about how to update from link below:

    How to: Update the JavaScript API for Office and manifest schema files in your Visual Studio project from version 1.0 to 1.1

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, November 27, 2014 7:06 AM
    Moderator
  • Thanks Fei. 

    Solution is working fine!! But we can not insist on users going for this option above. 

    Any alternative idea to get it with Office JS ?

    Tuesday, December 2, 2014 1:19 PM
  • Hi Ram1989,

    >>Any alternative idea to get it with Office JS ?<<

    No, the feature is provied by Excel application. We can only use Office.JS to write the data into spreadsheet, but we can't change the feature provieded by Excel appliction.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 3, 2014 7:11 AM
    Moderator