Setting the number format on cells as currency

Following the example of this page:

https://ej2.syncfusion.com/aspnetmvc/documentation/spreadsheet/illustrations?cs-save-lang=1&cs-lang=razor


I've created a function to set the number format of cells like currency. I do not want to hard code the format of the currency, because I want this to be dynamic and adapt to the user's language. 

function spreadsheet_Created() {

            this.numberFormat(getFormatFromType("Currency"), "C3:J15");

        }

But when I run this code I get a error, saying that getFormatFromType is not defined:

Uncaught ReferenceError: getFormatFromType is not defined

    at t.spreadsheet_Created ((index):299:18)

    at e.notify (ej2.min.js:10:737776)

    at e.trigger (ej2.min.js:10:766841)

    at e.triggerCreatedEvent (ej2.min.js:10:16590345)

    at ej2.min.js:10:16589940

    at ej2.min.js:10:652892


How can this be configuration achieved (either of server or client side)?


1 Reply

SP Sangeetha Priya Murugan Syncfusion Team June 23, 2022 12:24 PM UTC

Hi ShareValue,


You have called the importable method in JavaScript by without referring the spreadsheet instance, so only the issue occurs. To resolve this issue please refer the below code example.


Code Block:


  

<script>

    // Triggers once the control is loaded

    function createdHandler() {

        // Applies cell and number formatting to specified range of the active sheet

        this.cellFormat({ fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:F1');

        this.numberFormat(ej.spreadsheet.getFormatFromType("Currency"), 'D2:D31');

    }

</script>


For your convenience we have prepared the sample based on our suggestion. Please find the link below.


Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SpreadsheetMVC-74066511


Could you please check the above links and get back to us, if you need any further assistance on this.


Regards,

Sangeetha M


Loader.
Up arrow icon