本帖最后由 Mrluo 于 2023-12-6 10:03 编辑
透视表设置GC.Spread.Pivot.PivotTableFieldType.valueField的样式
想要设置这个值类型的几个列的数字格式是万为单位 ,按照 数据透视表字段标签格式 | 功能例子 | SpreadJS JavaScript 学习指南 (grapecity.com.cn) 这个例子做的设置,样例的代码如下 :(怕链接发不了,就贴出来官方给的样例代码)
- <template>
- <div class="sample-tutorial">
- <gc-spread-sheets
- class="sample-spreadsheets"
- @workbookInitialized="initSpread"
- >
- </gc-spread-sheets>
- <div class="options-container">
- <div>Field Name:</div>
- <select
- name="fieldName"
- id="fieldName"
- class="field-name"
- v-model="fieldName"
- @change="changeFormatter"
- >
- <option value="Salesperson" selected>Salesperson</option>
- <option value="Cars">Cars</option>
- <option value="Date">Date</option>
- <option value="Quantity">Quantity</option>
- </select>
- <div>Formatter:</div>
- <input
- type="text"
- class="label-filter-input filter-input"
- id="formatter"
- v-model="formatter"
- />
- <input
- type="button"
- class="format-button"
- value="Set"
- id="set"
- @click="setFormatter"
- />
- <input
- type="button"
- class="format-button"
- value="Reset"
- id="reset"
- @click="resetFormatter"
- />
- </div>
- </div>
- </template>
- <script>
- import Vue from "vue";
- import "@grapecity/spread-sheets-vue";
- import GC from "@grapecity/spread-sheets";
- import "@grapecity/spread-sheets-shapes";
- import "@grapecity/spread-sheets-pivot-addon";
- import '@grapecity/spread-sheets-resources-zh';
- GC.Spread.Common.CultureManager.culture("zh-cn");
- import "./styles.css";
- let App = Vue.extend({
- name: "app",
- data: function () {
- return {
- spread: null,
- pivotTable: null,
- fieldName: "Salesperson",
- formatter: "",
- };
- },
- methods: {
- initSpread: function (spread) {
- this.spread = spread;
- spread.suspendPaint();
- spread.setSheetCount(2);
- let sheet1 = spread.getSheet(0);
- let sheet2 = spread.getSheet(1);
- let tableName = this.getSource(sheet2, pivotSales);
- let pivotTable = this.addPivotTable(sheet1, tableName);
- this.pivotTable = pivotTable;
- spread.resumePaint();
- },
- getSource: function (sheet, tableSource) {
- sheet.name("DataSource");
- sheet.setRowCount(117);
- sheet.setColumnWidth(0, 120);
- sheet.getCell(-1, 0).formatter("YYYY-mm-DD");
- sheet.getRange(-1, 4, 0, 2).formatter("$ #,##0");
- let table = sheet.tables.add("table", 0, 0, 117, 6);
- for (let i = 2; i <= 117; i++) {
- sheet.setFormula(i - 1, 5, "=D" + i + "*E" + i);
- }
- table.style(GC.Spread.Sheets.Tables.TableThemes["none"]);
- sheet.setArray(0, 0, tableSource);
- return table.name();
- },
- addPivotTable: function (sheet, source) {
- sheet.suspendPaint();
- sheet.name("PivotTable");
- sheet.setRowCount(10000);
- let pivotTable = sheet.pivotTables.add(
- "PivotTable",
- source,
- 1,
- 1,
- GC.Spread.Pivot.PivotTableLayoutType.outline,
- GC.Spread.Pivot.PivotTableThemes.light8
- );
- pivotTable.suspendLayout();
- pivotTable.add(
- "salesperson",
- "Salesperson",
- GC.Spread.Pivot.PivotTableFieldType.rowField
- );
- pivotTable.add(
- "car",
- "Cars",
- GC.Spread.Pivot.PivotTableFieldType.rowField
- );
- pivotTable.add(
- "date",
- "Date",
- GC.Spread.Pivot.PivotTableFieldType.columnField
- );
- let groupInfo = {
- originFieldName: "date",
- dateGroups: [{ by: GC.Pivot.DateGroupType.quarters }],
- };
- pivotTable.group(groupInfo);
- pivotTable.add(
- "quantity",
- "Quantity",
- GC.Spread.Pivot.PivotTableFieldType.valueField,
- GC.Pivot.SubtotalType.sum
- );
- let carsStyle = new GC.Spread.Sheets.Style();
- carsStyle.formatter = "[red]@";
- let valueStyle = new GC.Spread.Sheets.Style();
- valueStyle.formatter = "#0.00";
- pivotTable.setStyle(this.initArea("Cars", pivotTable), carsStyle);
- pivotTable.setStyle(this.initArea("Quantity", pivotTable), valueStyle);
- pivotTable.resumeLayout();
- sheet.resumePaint();
- pivotTable.autoFitColumn();
- return pivotTable;
- },
- initArea: function (fieldName, pt) {
- let fieldArea = pt.getField(fieldName).pivotArea;
- if (fieldArea === 1 || fieldArea === 2) {
- return {
- labelOnly: true,
- references: [
- {
- fieldName,
- },
- ],
- };
- } else if (fieldArea === 3) {
复制代码
我的关键代码如下:
要怎么设置这个样式啊,头疼,样例中的说明有个参数
是这样的
但是api文档中又是这样的
我真的搞麻了
|