在新窗口中打开演示可以打开设计器:
SpreadJS 的报表包含两个重要部分:ReportSheet(报表)和TemplateSheet(模板,包含各种与报表相关的设置)。报表可以使用 TemplateSheet(模板)中的报表相关设置和 DataManager 中的数据来生成相应的报表。报表还提供数据输入 API。
要使用报表,请将 JS 文件链接添加到文档的头部部分:
然后,您可以将表绑定到 TemplateSheet 并生成行式报表。
<template>
<gc-spread-sheets-designer class="demo" v-if="showDesigner" @designerInitialized="initDesigner" />
<gc-spread-sheets class="demo" v-else @workbookInitialized="initSpread" />
</template>
<script setup>
import GC from '@grapecity-software/spread-sheets';
import '@grapecity-software/spread-sheets-resources-zh';
GC.Spread.Common.CultureManager.culture("zh-cn");
import '@grapecity-software/spread-sheets-print';
import '@grapecity-software/spread-sheets-shapes';
import '@grapecity-software/spread-sheets-charts';
import '@grapecity-software/spread-sheets-reportsheet-addon';
import '@grapecity-software/spread-sheets-tablesheet';
import '@grapecity-software/spread-sheets-formula-panel';
import '@grapecity-software/spread-sheets-vue';
import '@grapecity-software/spread-sheets-designer-resources-cn';
import '@grapecity-software/spread-sheets-designer-vue';
import { ref } from 'vue';
import '$DEMOROOT$/spread/source/js/react_vue/license.js';
import { registerlic } from '$DEMOROOT$/spread/source/js/designer/react_vue/license.js';
registerlic(GC);
const showDesigner = top === window;
const spreadRef = ref(null);
const designerRef = ref(null);
async function initDesigner(designer) {
designerRef.value = designer;
await initSpread(designer.getWorkbook());
designer.refresh();
}
async function initSpread(spread) {
spreadRef.value = spread;
spread.suspendPaint();
spread.setSheetCount(1);
const loadingTip = addLoadingTip();
const res = await fetch('$DEMOROOT$/zh/sample/features/report-sheet/overview/spread.json');
await spread.fromJSON(await res.json());
loadingTip.remove();
spread.resumePaint();
}
function addLoadingTip() {
const div = document.createElement('div');
div.style.position = 'absolute';
div.style.inset = '0';
div.style.display = 'flex';
div.style.alignItems = 'center';
div.style.justifyContent = 'center';
div.style.background = 'white';
div.style.zIndex = '100';
div.textContent = 'Loading data from server ...';
document.body.appendChild(div);
return div;
}
</script>
<style scoped>
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#app {
height: 100%;
}
.demo {
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>SpreadJS VUE</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/zh/vue3/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<link rel="stylesheet" type="text/css"
href="$DEMOROOT$/zh/vue3/node_modules/@grapecity-software/spread-sheets-designer/styles/gc.spread.sheets.designer.min.css">
<script src="$DEMOROOT$/zh/vue3/node_modules/systemjs/dist/system.src.js"></script>
<script src="./systemjs.config.js"></script>
<script src="./compiler.js" type="module"></script>
<script>
System.import("./src/app.js");
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
(function(global) {
SystemJS.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
packageConfigPaths: [
'./node_modules/*/package.json',
"./node_modules/@grapecity-software/*/package.json",
"./node_modules/@babel/*/package.json",
"./node_modules/@vue/*/package.json"
],
map: {
'vue': "npm:vue/dist/vue.esm-browser.js",
'tiny-emitter': 'npm:tiny-emitter/index.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
"systemjs-babel-build": "npm:systemjs-plugin-babel/systemjs-babel-browser.js",
'@grapecity-software/spread-sheets-designer-resources-cn': 'npm:@grapecity-software/spread-sheets-designer-resources-cn/index.js',
'@grapecity-software/spread-sheets-designer-vue': 'npm:@grapecity-software/spread-sheets-designer-vue/index.js',
'@grapecity-software/spread-sheets-designer': 'npm:@grapecity-software/spread-sheets-designer/index.js',
'@grapecity-software/spread-excelio': 'npm:@grapecity-software/spread-excelio/index.js',
'@grapecity-software/spread-sheets-barcode': 'npm:@grapecity-software/spread-sheets-barcode/index.js',
'@grapecity-software/spread-sheets-charts': 'npm:@grapecity-software/spread-sheets-charts/index.js',
'@grapecity-software/spread-sheets-languagepackages': 'npm:@grapecity-software/spread-sheets-languagepackages/index.js',
'@grapecity-software/spread-sheets-print': 'npm:@grapecity-software/spread-sheets-print/index.js',
'@grapecity-software/spread-sheets-pdf': 'npm:@grapecity-software/spread-sheets-pdf/index.js',
'@grapecity-software/spread-sheets-shapes': 'npm:@grapecity-software/spread-sheets-shapes/index.js',
'@grapecity-software/spread-sheets-io': 'npm:@grapecity-software/spread-sheets-io/index.js',
'@grapecity-software/spread-sheets-reportsheet-addon': 'npm:@grapecity-software/spread-sheets-reportsheet-addon/index.js',
'@grapecity-software/spread-sheets-tablesheet': 'npm:@grapecity-software/spread-sheets-tablesheet/index.js',
'@grapecity-software/spread-sheets-ganttsheet': 'npm:@grapecity-software/spread-sheets-ganttsheet/index.js',
'@grapecity-software/spread-sheets-formula-panel': 'npm:@grapecity-software/spread-sheets-formula-panel/index.js',
'@grapecity-software/spread-sheets-vue': 'npm:@grapecity-software/spread-sheets-vue/index.js',
'@grapecity-software/spread-sheets': 'npm:@grapecity-software/spread-sheets/index.js',
'@grapecity-software/spread-sheets-resources-zh': 'npm:@grapecity-software/spread-sheets-resources-zh/index.js',
},
meta: {
'*.css': { loader: 'systemjs-plugin-css' },
'*.vue': { loader: "../plugin-vue/index.js" }
}
});
})(this);