グリッド:Excel入出力

FlexGridXlsxConverterクラスのsaveAsync/loadAsyncメソッドで非同期にExcel(.xlsx)ファイルとの間でFlexGridコンテンツをエクスポートまたはインポートする方法を示します。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './style.css'; import * as wjCore from '@grapecity/wijmo'; import * as wjGrid from '@grapecity/wijmo.grid'; import * as wjGridXlsx from '@grapecity/wijmo.grid.xlsx'; import { getProductOrders } from './data'; document.readyState === 'complete' ? init() : window.onload = init; function init() { let data = getProductOrders(500); let customContent = false; let includeColumnHeader = false; let grid = new wjGrid.FlexGrid('#flexgrid', { itemsSource: data, itemFormatter: itemFormatter, columns: [ { binding: 'id', header: 'ID' }, { binding: 'start', header: '開始', format: 'd' }, { binding: 'end', header: '終了', format: 'd' }, { binding: 'country', header: '国' }, { binding: 'product', header: '商品' }, { binding: 'color', header: '色' }, { binding: 'amount', header: '金額', format: 'c', aggregate: 'Sum' }, { binding: 'amount2', header: '保留', format: 'c', aggregate: 'Sum' }, { binding: 'discount', header: '値引', format: 'p1', aggregate: 'Avg' }, { binding: 'active', header: '有効', width: 185 } ] }); updateGroup(); onClick('customCellContent', (e) => { customContent = e.target.checked; grid.invalidate(); }); onClick('importIncludeColumnHeader', (e) => { includeColumnHeader = e.target.checked; document.querySelector('#exportIncludeColumnHeader').checked = includeColumnHeader; }); onClick('exportIncludeColumnHeader', (e) => { includeColumnHeader = e.target.checked; document.querySelector('#importIncludeColumnHeader').checked = includeColumnHeader; }); onClick('loadXlsx', () => { let inputEle = document.querySelector('#importFile'); if (inputEle.files[0]) { wjGridXlsx.FlexGridXlsxConverter.loadAsync(grid, inputEle.files[0], { includeColumnHeaders: includeColumnHeader }); } }); onClick('saveXlsx', () => { wjGridXlsx.FlexGridXlsxConverter.saveAsync(grid, { includeColumnHeaders: includeColumnHeader, includeCellStyles: false, formatItem: customContent ? exportFormatItem : null }, 'FlexGrid.xlsx'); }); // update group setting for the flex grid function updateGroup() { let groupNames = ['Product', 'Country', 'Amount'], cv, propName, groupDesc; if (grid) { // get the collection view, start update cv = grid.collectionView; cv.beginUpdate(); // clear existing groups cv.groupDescriptions.clear(); // add new groups for (let i = 0; i < groupNames.length; i++) { propName = groupNames[i].toLowerCase(); if (propName == 'amount') { // group amounts in ranges // (could use the mapping function to group countries into continents, // names into initials, etc) groupDesc = new wjCore.PropertyGroupDescription(propName, function (item, prop) { let value = item[prop]; if (value > 1000) return '多い'; if (value > 100) return '普通'; if (value > 0) return '少ない'; return 'マイナス'; }); cv.groupDescriptions.push(groupDesc); } else if (propName) { // group other properties by their specific values groupDesc = new wjCore.PropertyGroupDescription(propName); cv.groupDescriptions.push(groupDesc); } } // done updating cv.endUpdate(); } } function itemFormatter(panel, r, c, cell) { if (panel.cellType === wjGrid.CellType.Cell) { let binding = grid.columns[c].binding, row = grid.rows[r]; if (row instanceof wjGrid.GroupRow) { if (row._level <= 2) { if (binding === "active") { if (customContent) { let amount_val = grid.getCellData(r, c - 3, false), pending_val = grid.getCellData(r, c - 2, false), persentage_val = (pending_val / amount_val); cell.innerHTML = '保留/金額: ' + Math.round(persentage_val * 100) / 100; } else { cell.innerHTML = ''; } } } } else { if (binding === 'color') { if (customContent) { cell.style.color = grid.getCellData(r, c, true); } else { cell.style.color = ''; } } } } } function exportFormatItem(args) { let p = args.panel, row = args.row, col = args.col, xlsxCell = args.xlsxCell, cell, color; if (p.cellType === wjGrid.CellType.Cell) { if (p.columns[col].binding === 'color') { if (xlsxCell.value) { if (!xlsxCell.style.font) { xlsxCell.style.font = {}; } xlsxCell.style.font.color = xlsxCell.value.toLowerCase(); } } else if (p.columns[col].binding === 'active' && p.rows[row] instanceof wjGrid.GroupRow) { cell = args.getFormattedCell(); xlsxCell.value = cell.textContent.trim(); } } } function onClick(id, fn) { document.querySelector('#' + id).addEventListener('click', fn); } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Import Export Excel Asynchronous</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <!-- the flex grid --> <div class="row"> <div id="flexgrid"></div> </div> <div class="row"> <div class="col-md-6 col-xs-12"> <div class="form-inline well well-lg"> <input type="file" class="form-control" style="width: 250px;" id="importFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel.sheet.macroEnabled.12" /> <button id="loadXlsx" class="btn btn-default">インポート</button> <div class="checkbox"> <label> <input id="importIncludeColumnHeader" type="checkbox"> 列ヘッダーを含む </label> </div> </div> </div> <div class="col-md-6 col-xs-12"> <div class="form-inline well well-lg"> <button id="saveXlsx" class="btn btn-default">エクスポート</button> <div class="checkbox"> <label> <input id="exportIncludeColumnHeader" type="checkbox"> 列ヘッダーを含む </label> </div> <div class="checkbox"> <label> <input id="customCellContent" type="checkbox"> カスタムセルコンテンツ </label> </div> </div> </div> </div> </div> </body> </html> // data used to generate random items let countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ'], products = ['ウィジェット', 'ガジェット', 'ツール'], colors = ['Black', 'Orange', 'Red', 'Green', 'Blue']; export function getProductOrders(count) { let data = [], dt = new Date(); // add count items for (let i = 0; i < count; i++) { // constants used to create data items let date = new Date(dt.getFullYear(), i % 12, 25), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); // create the item let item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], amount: Math.random() * 10000, amount2: Math.random() * 10000, discount: Math.random() / 4, active: i % 4 == 0, }; // add the item to the list data.push(item); } return data; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import { Component, enableProdMode, NgModule, Inject, ViewChild } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { WjGridModule } from '@grapecity/wijmo.angular2.grid'; import * as wjcCore from '@grapecity/wijmo'; import * as wjcGrid from '@grapecity/wijmo.grid'; import * as wjcXlsx from '@grapecity/wijmo.xlsx'; import * as wjcGridXlsx from '@grapecity/wijmo.grid.xlsx'; import { DataService } from './app.data'; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { data: any[]; fileName: string = ''; includeColumnHeader = true; customContent = false; constructor(@Inject(DataService) dataSvc: DataService) { this.data = dataSvc.getProductOrders(500); } @ViewChild('flex') flex: wjcGrid.FlexGrid; initializeFlexSheet(flex: wjcGrid.FlexGrid) { let groupNames = ['Product', 'Country', 'Amount'], cv, propName, groupDesc; // get the collection view, start update cv = flex.collectionView; cv.beginUpdate(); // clear existing groups cv.groupDescriptions.clear(); // add new groups for (let i = 0; i < groupNames.length; i++) { propName = groupNames[i].toLowerCase(); if (propName == 'amount') { // group amounts in ranges // (could use the mapping function to group countries into continents, // names into initials, etc) groupDesc = new wjcCore.PropertyGroupDescription(propName, (item: any, prop: string) => { let value = item[prop]; if (value > 1000) return '多い'; if (value > 100) return '普通'; if (value > 0) return '少ない'; return 'マイナス'; }); cv.groupDescriptions.push(groupDesc); } else if (propName) { // group other properties by their specific values groupDesc = new wjcCore.PropertyGroupDescription(propName); cv.groupDescriptions.push(groupDesc); } } // done updating cv.endUpdate(); } save() { wjcGridXlsx.FlexGridXlsxConverter.saveAsync(this.flex, { includeColumnHeaders: this.includeColumnHeader, includeCellStyles: false, formatItem: this.customContent ? this._exportFormatItem : null }, 'FlexGrid.xlsx'); } load() { let fileInput = <HTMLInputElement>document.getElementById('importFile'); if (fileInput.files[0]) { this.customContent = false; wjcGridXlsx.FlexGridXlsxConverter.loadAsync(this.flex, fileInput.files[0], { includeColumnHeaders: this.includeColumnHeader }); } } private _exportFormatItem(args: wjcGridXlsx.XlsxFormatItemEventArgs) { var p = args.panel, row = args.row, col = args.col, xlsxCell = args.xlsxCell, cell: HTMLElement, color: string; if (p.cellType === wjcGrid.CellType.Cell) { if (p.columns[col].binding === 'color') { //color = p.rows[row].dataItem['color']; if (xlsxCell.value) { if (!xlsxCell.style.font) { xlsxCell.style.font = {}; } xlsxCell.style.font.color = (<string>xlsxCell.value).toLowerCase(); } } else if (p.columns[col].binding === 'active' && p.rows[row] instanceof wjcGrid.GroupRow) { cell = args.getFormattedCell(); xlsxCell.value = cell.textContent.trim(); xlsxCell.style.hAlign = wjcXlsx.HAlign.Left; } } } } @NgModule({ imports: [WjGridModule, BrowserModule, FormsModule], providers: [DataService], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Import Export Excel Asynchronous</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <div class="row"> <!-- the grid --> <wj-flex-grid #flex [(itemsSource)]="data" (initialized)="initializeFlexSheet(flex)"> <wj-flex-grid-column header="ID" binding="id"></wj-flex-grid-column> <wj-flex-grid-column header="開始" binding="start" format="d"></wj-flex-grid-column> <wj-flex-grid-column header="終了" binding="end" format="d"></wj-flex-grid-column> <wj-flex-grid-column header="国" binding="country"></wj-flex-grid-column> <wj-flex-grid-column header="商品" binding="product"></wj-flex-grid-column> <wj-flex-grid-column header="色" binding="color" [width]="70"> <ng-template wjFlexGridCellTemplate [cellType]="'Cell'" let-cell="cell" *ngIf="customContent"> <div [ngStyle]="{color: cell.item.color.toLowerCase()}"> {{cell.item.color}} </div> </ng-template> </wj-flex-grid-column> <wj-flex-grid-column header="金額" binding="amount" format="c" aggregate="Sum"></wj-flex-grid-column> <wj-flex-grid-column header="保留" binding="amount2" format="c2" aggregate="Sum"></wj-flex-grid-column> <wj-flex-grid-column header="値引" binding="discount" format="p1" aggregate="Avg"></wj-flex-grid-column> <wj-flex-grid-column header="有効" binding="active" [width]="170"> <ng-template wjFlexGridCellTemplate [cellType]="'Group'" let-cell="cell" *ngIf="customContent"> <div style="text-align:left"> 保留/金額: {{ cell.row.grid.getCellData(cell.row.index, 'amount', false) / cell.row.grid.getCellData(cell.row.index, 'amount2', false) | number:'1.2-2' }} </div> </ng-template> </wj-flex-grid-column> </wj-flex-grid> </div> <div class="row"> <div class="col-md-6 col-xs-12"> <div class="form-inline well well-lg"> <input type="file" class="form-control" style="width: 250px;" id="importFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel.sheet.macroEnabled.12" /> <button (click)="load()" class="btn btn-default">インポート</button> <div class="checkbox"> <label> <input [(ngModel)]="includeColumnHeader" type="checkbox"> 列ヘッダーを含む </label> </div> </div> </div> <div class="col-md-6 col-xs-12"> <div class="form-inline well well-lg"> <button (click)="save()" class="btn btn-default">エクスポート</button> <div class="checkbox"> <label> <input [(ngModel)]="includeColumnHeader" type="checkbox"> 列ヘッダーを含む </label> </div> <div class="checkbox"> <label> <input [(ngModel)]="customContent" type="checkbox"> カスタムセルコンテンツ </label> </div> </div> </div> </div> </div> import { Injectable } from '@angular/core'; @Injectable() export class DataService { getProductOrders(count: number) { let countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ'], products = ['ウィジェット', 'ガジェット', 'ツール'], colors = ['Black', 'Orange', 'Red', 'Green', 'Blue'], data = [], dt = new Date(); // add count items for (let i = 0; i < count; i++) { // constants used to create data items let date = new Date(dt.getFullYear(), i % 12, 25), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); // create the item let item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], amount: Math.random() * 10000, amount2: Math.random() * 10000, discount: Math.random() / 4, active: i % 4 == 0, }; // add the item to the list data.push(item); } return data; } } .wj-flexgrid { height: 400px; margin: 6px 0; } import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import "./app.css"; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjcCore from "@grapecity/wijmo"; import * as wjcGrid from "@grapecity/wijmo.react.grid"; import * as wjGrid from "@grapecity/wijmo.grid"; import * as wjcXlsx from "@grapecity/wijmo.xlsx"; import * as wjcGridXlsx from "@grapecity/wijmo.grid.xlsx"; import { getProductOrders } from "./data"; class App extends React.Component { constructor(props) { super(props); this.state = { data: getProductOrders(500), fileName: "", includeColumnHeader: true, customContent: false }; } render() { return <div className="container-fluid"> <div className="row"> <wjcGrid.FlexGrid itemsSource={this.state.data} initialized={this.initializeFlexSheet.bind(this)}> <wjcGrid.FlexGridColumn header="ID" binding="id"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="開始" binding="start" format="d"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="終了" binding="end" format="d"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="国" binding="country"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="商品" binding="product"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="色" binding="color" width={70}></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="金額" binding="amount" format="c" aggregate="Sum"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="保留" binding="amount2" format="c2" aggregate="Sum"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="値引" binding="discount" format="p1" aggregate="Avg"></wjcGrid.FlexGridColumn> <wjcGrid.FlexGridColumn header="有効" binding="active" width={70}></wjcGrid.FlexGridColumn> </wjcGrid.FlexGrid> </div> <div className="row"> <div className="col-md-6 col-xs-12"> <div className="form-inline well well-lg"> <input type="file" className="form-control" style={{ width: '250px' }} id="importFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel.sheet.macroEnabled.12"/> <button onClick={this.load.bind(this)} className="btn btn-default">インポート</button> <div className="checkbox"> <label> <input defaultChecked type="checkbox"/> 列ヘッダーを含む </label> </div> </div> </div> <div className="col-md-6 col-xs-12"> <div className="form-inline well well-lg"> <button onClick={this.save.bind(this)} className="btn btn-default">エクスポート</button> <div className="checkbox"> <label> <input defaultChecked type="checkbox"/> 列ヘッダーを含む </label> </div> <div className="checkbox"> <label> <input v-model="customContent" type="checkbox"/> カスタムセルコンテンツ </label> </div> </div> </div> </div> </div>; } initializeFlexSheet(flex) { this.flex = flex; let groupNames = ["Product", "Country", "Amount"], cv, propName, groupDesc; // get the collection view, start update cv = flex.collectionView; cv.beginUpdate(); // clear existing groups cv.groupDescriptions.clear(); // add new groups for (let i = 0; i < groupNames.length; i++) { propName = groupNames[i].toLowerCase(); if (propName == "amount") { // group amounts in ranges // (could use the mapping function to group countries into continents, // names into initials, etc) groupDesc = new wjcCore.PropertyGroupDescription(propName, (item, prop) => { let value = item[prop]; if (value > 1000) return "多い"; if (value > 100) return "普通"; if (value > 0) return "少ない"; return "マイナス"; }); cv.groupDescriptions.push(groupDesc); } else if (propName) { // group other properties by their specific values groupDesc = new wjcCore.PropertyGroupDescription(propName); cv.groupDescriptions.push(groupDesc); } } // done updating cv.endUpdate(); } save() { wjcGridXlsx.FlexGridXlsxConverter.saveAsync(this.flex, { includeColumnHeaders: this.state.includeColumnHeader, includeCellStyles: false, formatItem: this.state.customContent ? this.state._exportFormatItem : null }, "FlexGrid.xlsx"); } load() { let fileInput = document.getElementById("importFile"); if (fileInput.files[0]) { this.setState({ customContent: false }); wjcGridXlsx.FlexGridXlsxConverter.loadAsync(this.flex, fileInput.files[0], { includeColumnHeaders: this.state.includeColumnHeader }); } } exportFormatItem(args) { var p = args.panel, row = args.row, col = args.col, xlsxCell = args.xlsxCell, cell, color; if (p.cellType === wjGrid.CellType.Cell) { if (p.columns[col].binding === "color") { //color = p.rows[row].dataItem['color']; if (xlsxCell.value) { if (!xlsxCell.style.font) { xlsxCell.style.font = {}; } xlsxCell.style.font.color = xlsxCell.value.toLowerCase(); } } else if (p.columns[col].binding === "active" && p.rows[row] instanceof wjGrid.GroupRow) { cell = args.getFormattedCell(); xlsxCell.value = cell.textContent.trim(); xlsxCell.style.hAlign = wjcXlsx.HAlign.Left; } } } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Grapecity Wijmo OLAP Pivot Chart Overview</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-flexgrid { height: 400px; margin: 6px 0; } export function getProductOrders(count) { let countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ'], products = ['ウィジェット', 'ガジェット', 'ツール'], colors = ['Black', 'White', 'Red', 'Green', 'Blue'], data = [], dt = new Date(); // add count items for (let i = 0; i < count; i++) { // constants used to create data items let date = new Date(dt.getFullYear(), i % 12, 25), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); // create the item let item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], amount: Math.random() * 10000, amount2: Math.random() * 10000, discount: Math.random() / 4, active: i % 4 == 0, }; // add the item to the list data.push(item); } return data; } <template> <div class="container-fluid"> <div class="row"> <!-- the grid --> <wj-flex-grid :itemsSource="data" :initialized="initializeFlexSheet"> <wj-flex-grid-column header="ID" binding="id"></wj-flex-grid-column> <wj-flex-grid-column header="開始" binding="start" format="d"></wj-flex-grid-column> <wj-flex-grid-column header="終了" binding="end" format="d"></wj-flex-grid-column> <wj-flex-grid-column header="国" binding="country"></wj-flex-grid-column> <wj-flex-grid-column header="商品" binding="product"></wj-flex-grid-column> <wj-flex-grid-column header="色" binding="color" :width="70"></wj-flex-grid-column> <wj-flex-grid-column header="金額" binding="amount" format="c" aggregate="Sum"></wj-flex-grid-column> <wj-flex-grid-column header="保留" binding="amount2" format="c2" aggregate="Sum"></wj-flex-grid-column> <wj-flex-grid-column header="値引" binding="discount" format="p1" aggregate="Avg" ></wj-flex-grid-column> <wj-flex-grid-column header="有効" binding="active" :width="170"></wj-flex-grid-column> </wj-flex-grid> </div> <div class="row"> <div class="col-md-6 col-xs-12"> <div class="form-inline well well-lg"> <input type="file" class="form-control" style="width: 250px;" id="importFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel.sheet.macroEnabled.12" > <button @click="load()" class="btn btn-default">インポート</button> <div class="checkbox"> <label> <input v-model="includeColumnHeader" type="checkbox"> 列ヘッダーを含む </label> </div> </div> </div> <div class="col-md-6 col-xs-12"> <div class="form-inline well well-lg"> <button @click="save()" class="btn btn-default">エクスポート</button> <div class="checkbox"> <label> <input v-model="includeColumnHeader" type="checkbox"> 列ヘッダーを含む </label> </div> <div class="checkbox"> <label> <input v-model="customContent" type="checkbox"> カスタムセルコンテンツ </label> </div> </div> </div> </div> </div> </template> <script> import "@grapecity/wijmo.styles/wijmo.css"; import "bootstrap.css"; import Vue from "vue"; import { getProductOrders } from "./data"; import { WjGridModule } from "@grapecity/wijmo.vue2.grid"; import * as wjcCore from '@grapecity/wijmo'; import * as wjcGrid from '@grapecity/wijmo.grid'; import * as wjcXlsx from '@grapecity/wijmo.xlsx'; import * as wjcGridXlsx from '@grapecity/wijmo.grid.xlsx'; import * as gridPdf from "@grapecity/wijmo.grid.pdf"; new Vue({ el: "#app", data: { data: getProductOrders(500), fileName: "", includeColumnHeader: true, customContent: false }, methods: { initializeFlexSheet: function(flex) { this.flex = flex; let groupNames = ["Product", "Country", "Amount"], cv, propName, groupDesc; // get the collection view, start update cv = flex.collectionView; cv.beginUpdate(); // clear existing groups cv.groupDescriptions.clear(); // add new groups for (let i = 0; i < groupNames.length; i++) { propName = groupNames[i].toLowerCase(); if (propName == "amount") { // group amounts in ranges // (could use the mapping function to group countries into continents, // names into initials, etc) groupDesc = new wjcCore.PropertyGroupDescription( propName, (item, prop) => { let value = item[prop]; if (value > 1000) return "多い"; if (value > 100) return "普通"; if (value > 0) return "少ない"; return "マイナス"; } ); cv.groupDescriptions.push(groupDesc); } else if (propName) { // group other properties by their specific values groupDesc = new wjcCore.PropertyGroupDescription(propName); cv.groupDescriptions.push(groupDesc); } } // done updating cv.endUpdate(); }, save() { wjcGridXlsx.FlexGridXlsxConverter.saveAsync( this.flex, { includeColumnHeaders: this.includeColumnHeader, includeCellStyles: false, formatItem: this.customContent ? this._exportFormatItem : null }, "FlexGrid.xlsx" ); }, load: function() { let fileInput = document.getElementById("importFile"); if (fileInput.files[0]) { this.customContent = false; wjcGridXlsx.FlexGridXlsxConverter.loadAsync( this.flex, fileInput.files[0], { includeColumnHeaders: this.includeColumnHeader } ); } }, exportFormatItem: function(args) { var p = args.panel, row = args.row, col = args.col, xlsxCell = args.xlsxCell, cell, color; if (p.cellType === wjcGrid.CellType.Cell) { if (p.columns[col].binding === "color") { //color = p.rows[row].dataItem['color']; if (xlsxCell.value) { if (!xlsxCell.style.font) { xlsxCell.style.font = {}; } xlsxCell.style.font.color = xlsxCell.value.toLowerCase(); } } else if ( p.columns[col].binding === "active" && p.rows[row] instanceof wjcGrid.GroupRow ) { cell = args.getFormattedCell(); xlsxCell.value = cell.textContent.trim(); xlsxCell.style.hAlign = wjcXlsx.HAlign.Left; } } } } }); </script> <style> .wj-flexgrid { height: 400px; margin: 6px 0; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Using a custom font</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> export function getProductOrders(count) { let countries = ['アメリカ', 'ドイツ', 'イギリス', '日本', 'イタリア', 'ギリシャ'], products = ['ウィジェット', 'ガジェット', 'ツール'], colors = ['Black', 'White', 'Red', 'Green', 'Blue'], data = [], dt = new Date(); // add count items for (let i = 0; i < count; i++) { // constants used to create data items let date = new Date(dt.getFullYear(), i % 12, 25), countryId = Math.floor(Math.random() * countries.length), productId = Math.floor(Math.random() * products.length), colorId = Math.floor(Math.random() * colors.length); // create the item let item = { id: i, start: date, end: date, country: countries[countryId], product: products[productId], color: colors[colorId], amount: Math.random() * 10000, amount2: Math.random() * 10000, discount: Math.random() / 4, active: i % 4 == 0, }; // add the item to the list data.push(item); } return data; }