☝️Small business or a startup? See if you qualify for our special offer.
+

Export to Excel - Formatting to remove .0

Answered
Lance Coffman asked on January 10, 2025

Have tried multiple formats to remove .0 decimal in column cant see to remove.
Below is formatting

    const format = {
      name: 'removeDecimal',
      decimalPlaces: 0,
   };

this.citationPivot.flexmonster.setFormat(format);

6 answers

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster January 13, 2025

Hello,

Thank you for contacting us.

Kindly note that if you want to set the default format for all the fields, the name property of the format object should be set to "":

  const format = {
name: "",
decimalPlaces: 0,
}

Also, you should use the refresh() API call after setting a format to see changes. Please check the following example for reference: https://jsfiddle.net/flexmonster/Lft15349/.

Please let us know if it works for you. Looking forward to hearing from you.

Kind regards,
Nadia

Public
Lance Coffman January 17, 2025

1. your fiddle example is also broken on Export to Excel. it has .0 decimal.


Please let me know how to fix as soon as you can.

My code with refresh

  exportExcel(whichTab) {

    let currentTitleExcel =

      '<center><h1>' + this.customLabel + '</h1></center>';

    const format = {

      name: '',

      decimalPlaces: 0,

    };

    switch (whichTab) {

      case 'TAB1':

        {

          this.testPivot.flexmonster.setFormat(format);

          this.testPivot.flexmonster.refresh();

          this.testPivot.flexmonster.exportTo('excel', {

            header: testTitleExcel.toString(),

          });

        }

        break;

      case 'TAB2':

        {

          this.test2Pivot.flexmonster.setFormat(format);

          this.test2Pivot.flexmonster.refresh();

          this.test2Pivot.flexmonster.exportTo('excel', {

            header: currentTitleExcel.toString(),

          });

        }

        break;

  

      default:

        {

          //do nothing

        }

        break;

    }

  }

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster January 20, 2025

Hello Lance,

Thank you for the response.

We could not reproduce the described behavior on our side. Please see the following example: https://jsfiddle.net/flexmonster/n0ao4jd3/. When you click the "Set format and export" button, the grid is exported without decimal places.

Alternatively, you can set the format directly in the report object. For example:

report: {
// other configs
formats: [
{
name: "",
decimalPlaces: 0
}
],
}

This way, the format will be applied to all the measures. You are welcome to use the following JSFiddle for reference: https://jsfiddle.net/flexmonster/1v62rf3q/.

Please let us know if it works for you. Looking forward to hearing your feedback.

Kind regards,
Nadia

Public
Lance Coffman January 20, 2025

Seems I need to code for Default Value since not set initially
Though I put code as stated

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster January 21, 2025

Hello Lance,

Thank you for the response.

To set the cell format for the default value, you can use the following code:

let pivot = new Flexmonster({
// other properties
report: {
// other report configurations
formats: [
{
name: "",
decimalPlaces: 0,
},
],
},
});

The name property of the Format object should be specified as "". This way, the format will be applied to all the measures. You can see the illustration in the following JSFiddle: https://jsfiddle.net/flexmonster/1v62rf3q/. In the example, if you click on the Format cells tab and choose the Default value, you can see that Decimal places are set to 0 instead of None. This way, there will be no decimal places in the exported Excel file. Please see the following guide for more details and examples: https://www.flexmonster.com/doc/number-formatting/#default

You are welcome to contact us if other questions arise.

Kind regards,
Nadia

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster 5 days ago

Hello Lance,

Hope you are doing well.

We were wondering if you had a chance to test a suggested approach. Could you please confirm if it works for you?

Looking forward to hearing your feedback.

Kind regards,
Nadia

Please login or Register to Submit Answer