There are five types of fill data:
Auto: The auto fill type.
Direction: The direction fill type.
Linear: The linear fill type.
Growth: The growth fill type.
Date: The date fill type.
SpreadJS provides methods to perform the fill.
<template>
<div class="sample-tutorial">
<gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread">
</gc-spread-sheets>
<div class="options-container">
<p>
Use the "Start Range" field to select a range to start the fill, "Whole Range" to select the entire range to fill, and the "Fill Methods" and "Fill Series" fields to change how the fill happens.
</p>
<p>
Try selecting Sheet1!A1 as the start range and Sheet1!A1:C2 as the whole range, keep fillAuto as the fill method and column as fill series. Then click the "fillAuto" button and see the sheet fill those cells.
</p>
<div class="option-row">
<label>Start Range</label>
<div id="startRange" spellcheck="false" style="display:inline-block;border: 1px solid #808080;width:134px;vertical-align: middle;">
</div>
</div>
<div class="option-row">
<label>Whole Range</label>
<div id="wholeRange" spellcheck="false" style="display:inline-block;border: 1px solid #808080;width:134px;vertical-align: middle;">
</div>
</div>
<div class="option-row">
<label>Fill Methods</label>
<select id="fillMethods" @change="fillMethodChangedHandle" v-model.number="fillMethods">
<option value='0' selected>fillAuto</option>
<option value='1'>fillAutobyDirection</option>
<option value='2'>fillLinear</option>
<option value='3'>fillGrowth</option>
<option value='4'>fillDate</option>
</select>
</div>
<div class="option-row">
<div id="fillSeriesSet" v-show="fillSeriesSet">
<label>FillSeries</label>
<select id="fillSeries" v-model.number="fillSeries">
<option value='0'>Column</option>
<option value='1'>Row</option>
</select>
</div>
<div id="fillDirectionSet" v-show="fillDirectionSet">
<label>FillDirection</label>
<select id="fillDirection" v-model.number="fillDirection">
<option value='0'>Left</option>
<option value='1'>Right</option>
<option value='2'>Up</option>
<option value='3'>Down</option>
</select>
</div>
</div>
<div class="option-row" id="fillDateUnitSet" v-show="fillDateUnitSet">
<label>FillDateUnit</label>
<select id="fillDateUnit" v-model.number="fillDateUnit">
<option value='0'>Day</option>
<option value='1'>Weekday</option>
<option value='2'>Month</option>
<option value='3'>Year</option>
</select>
</div>
<div class="option-row" id="fillStepAndStop" v-show="fillStepAndStop">
<label>Step</label>
<input type="text" id="step" v-model.number="step" />
<label>Stop</label>
<input type="text" id="stop" v-model.number="stop" />
</div>
<div class="option-row">
<label></label>
<input type="button" id="btnFillAuto" value="fillAuto" v-show="btnFillAuto" @click="btnFillAutoHandler" />
<input type="button" id="btnFillAutobyDirection" value="fillAutobyDirection" v-show="btnFillAutobyDirection" @click="btnFillAutobyDirectionHandler" />
<input type="button" id="btnFillLinear" value="fillLinear" v-show="btnFillLinear" @click="btnFillLinearHandler" />
<input type="button" id="btnFillGrowth" value="fillGrowth" v-show="btnFillGrowth" @click="btnFillGrowthHandler" />
<input type="button" id="btnFillDate" value="fillDate" v-show="btnFillDate" @click="btnFillDateHandler" />
</div>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import '@mescius/spread-sheets-vue'
import GC from '@mescius/spread-sheets';
import './styles.css';
let App = Vue.extend({
name: "app",
data: function () {
return {
fillDirectionSet: false,
fillDateUnitSet: false,
fillStepAndStop: false,
btnFillAutobyDirection: false,
btnFillLinear: false,
btnFillGrowth: false,
btnFillDate: false,
fillSeriesSet: true,
fillMethods: 0,
fillSeries: 0,
fillDirection: 0,
fillDateUnit: 0,
step: "",
stop: "",
btnFillAuto:true
};
},
methods: {
fillMethodChangedHandle() {
switch (this.fillMethods) {
case 0:
this.fillSeriesSet = true;
this.btnFillAuto = true;
this.fillDateUnitSet = false;
this.fillDirectionSet = false;
this.btnFillAutobyDirection = false;
this.btnFillLinear = false;
this.btnFillGrowth = false;
this.btnFillDate = false;
this.fillStepAndStop = false;
break;
case 1:
this.fillDirectionSet = true;
this.btnFillAutobyDirection = true;
this.fillDateUnitSet = false;
this.fillSeriesSet = false;
this.btnFillAuto = false;
this.btnFillLinear = false;
this.btnFillGrowth = false;
this.btnFillDate = false;
this.fillStepAndStop = false;
break;
case 2:
this.fillSeriesSet = true;
this.btnFillLinear = true;
this.fillStepAndStop = true;
this.fillDateUnitSet = false;
this.fillDirectionSet = false;
this.btnFillAuto = false;
this.btnFillAutobyDirection = false;
this.btnFillGrowth = false;
this.btnFillDate = false;
break;
case 3:
this.fillSeriesSet = true;
this.btnFillGrowth = true;
this.fillStepAndStop = true;
this.fillDateUnitSet = false;
this.fillDirectionSet = false;
this.btnFillAuto = false;
this.btnFillAutobyDirection = false;
this.btnFillLinear = false;
this.btnFillDate = false;
break;
case 4:
this.fillSeriesSet = true;
this.btnFillDate = true;
this.fillStepAndStop = true;
this.fillDateUnitSet = true;
this.fillDirectionSet = false;
this.btnFillAuto = false;
this.btnFillAutobyDirection = false;
this.btnFillGrowth = false;
this.btnFillLinear = false;
break;
}
},
initSpread(spread) {
this.spread = spread;
let startRangeFormulaTextBox = new GC.Spread.Sheets.FormulaTextBox.FormulaTextBox(document.getElementById('startRange'), {
rangeSelectMode: true
});
let wholeRangeFormulaTextBox = new GC.Spread.Sheets.FormulaTextBox.FormulaTextBox(document.getElementById('wholeRange'), {
rangeSelectMode: true
});
startRangeFormulaTextBox.workbook(spread);
wholeRangeFormulaTextBox.workbook(spread);
this.startRangeFormulaTextBox = startRangeFormulaTextBox;
this.wholeRangeFormulaTextBox = wholeRangeFormulaTextBox;
spread.options.newTabVisible = false;
let sheet = spread.getSheet(0);
sheet.setValue(0, 0, 1);
},
btnFillAutoHandler() {
var sheet = this.spread.getActiveSheet();
var startRange = getRange(sheet, this.startRangeFormulaTextBox.text());
var wholeRange = getRange(sheet, this.wholeRangeFormulaTextBox.text());
if (this.fillSeries === 1) {
wholeRange.rowCount = startRange.rowCount;
} else {
wholeRange.colCount = startRange.colCount;
}
sheet.fillAuto(startRange, wholeRange, {
series: this.fillSeries,
fillType: GC.Spread.Sheets.Fill.FillType.auto
});
},
btnFillAutobyDirectionHandler() {
var sheet = this.spread.getActiveSheet();
var startRange = getRange(sheet, this.startRangeFormulaTextBox.text());
var wholeRange = getRange(sheet, this.wholeRangeFormulaTextBox.text());
sheet.fillAuto(startRange, wholeRange, {
direction: this.fillDirection,
fillType: GC.Spread.Sheets.Fill.FillType.direction
});
},
btnFillLinearHandler() {
var sheet = this.spread.getActiveSheet();
var startRange = getRange(sheet, this.startRangeFormulaTextBox.text());
var wholeRange = getRange(sheet, this.wholeRangeFormulaTextBox.text());
var stop;
if(this.stop!==""){
stop=parseInt(this.stop);
}
sheet.fillAuto(startRange, wholeRange, {
series: this.fillSeries,
step: this.step,
stop: stop,
fillType: GC.Spread.Sheets.Fill.FillType.linear
});
},
btnFillGrowthHandler() {
var sheet = this.spread.getActiveSheet();
var startRange = getRange(sheet, this.startRangeFormulaTextBox.text());
var wholeRange = getRange(sheet, this.wholeRangeFormulaTextBox.text());
var stop;
if(this.stop!==""){
stop=parseInt(this.stop);
}
sheet.fillAuto(startRange, wholeRange, {
series: this.fillSeries,
step: this.step,
stop: stop,
fillType: GC.Spread.Sheets.Fill.FillType.growth
});
},
btnFillDateHandler() {
var sheet = this.spread.getActiveSheet();
var startRange = getRange(sheet, this.startRangeFormulaTextBox.text());
var wholeRange = getRange(sheet, this.wholeRangeFormulaTextBox.text());
var stop;
if(this.stop!==""){
stop=parseInt(this.stop);
}
sheet.fillAuto(startRange, wholeRange, {
series: this.fillSeries,
unit: this.fillDateUnit,
step: this.step,
stop: stop,
fillType: GC.Spread.Sheets.Fill.FillType.date
});
}
}
});
const getRange = (sheet, rangeString) => {
try {
var rangeObject = GC.Spread.Sheets.CalcEngine.formulaToExpression(sheet, rangeString).getRange(0, 0);
var range = new GC.Spread.Sheets.Range(rangeObject.row, rangeObject.col, rangeObject.rowCount, rangeObject.colCount);
return range;
} catch (e) {
throw new Error("Select Ranges are not right");
}
}
new Vue({
render: h => h(App)
}).$mount('#app');
</script>
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/vue/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- SystemJS -->
<script src="$DEMOROOT$/en/vue/node_modules/systemjs/dist/system.src.js"></script>
<script src="$DEMOROOT$/spread/source/data/ellipsis.js" type="text/javascript"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('./src/app.vue');
System.import('$DEMOROOT$/en/lib/vue/license.js');
</script>
</head>
<body>
<div id="app" style="height: 100%;"></div>
</body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
input, select {
padding: 4px 8px;
}
input {
width: 100%;
margin-top: 6px;
box-sizing: border-box;
}
label {
display: inline-block;
min-width: 85px;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
meta: {
'*.css': { loader: 'css' },
'*.vue': { loader: 'vue-loader' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js',
'jszip': 'npm:jszip/dist/jszip.js',
'css': 'npm:systemjs-plugin-css/css.js',
'vue': 'npm:vue/dist/vue.min.js',
'vue-loader': 'npm:systemjs-vue-browser/index.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'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
}
}
});
})(this);