Display measures as integers in the exported Excel file

Export and print

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div>
  <h2>Display measures as integers in the exported Excel file</h2>
  <p>
    When exporting to Excel, a measure will be displayed without the decimal
    part only if the measure has a number format where the
    <a
      href="https://www.flexmonster.com/api/format-object/#decimalplaces"
      target="_blank"
    >decimalPlaces</a> is <code>0</code>.
  </p>
  <p>
    See the difference between the reports exported to Excel when the
    <code>decimalPlaces</code> is set to <code>0</code> and when it is not.
  </p>
</div>

<button onclick="setDecimals()">Set decimal places</button>
<button onclick="clearDecimals()">Clear decimal places</button>
<button onclick="excel()">Export to excel</button>

<div id="pivot-container"></div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

JavaScript

const pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    formats: [{
      name: "decimalFormat"
    }],
    slice: {
    	rows: [{
        uniqueName: "Category",
      }],
      columns: [{
        uniqueName: "[Measures]"
      }],
      measures: [{
        uniqueName: "Price",
        aggregation: "sum",
        format: "decimalFormat"
      }],
    }
  }
});

function setDecimals() {
  pivot.setFormat({
  	name: "decimalFormat",
    decimalPlaces: 0
  });
  pivot.refresh();
  console.log("decimalPlaces has been set to 0");
}

function clearDecimals() {
  pivot.setFormat({
  	name: "decimalFormat"
  });
  pivot.refresh();
  console.log("decimalPlaces has been reset to the default value");
}

function excel() {
  pivot.exportTo("excel", {
    excelSheetName: "Pivot Table"
  });
}