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 setup>
import '@mescius/spread-sheets-vue'
import { ref } from "vue";
import GC from "@mescius/spread-sheets";
const spreadRef = ref(null);
const startRangeFormulaTextBox = ref(null);
const wholeRangeFormulaTextBox = ref(null);
const fillDirectionSet = ref(false);
const fillDateUnitSet = ref(false);
const fillStepAndStop = ref(false);
const btnFillAutobyDirection = ref(false);
const btnFillLinear = ref(false);
const btnFillGrowth = ref(false);
const btnFillDate = ref(false);
const fillSeriesSet = ref(true);
const fillMethods = ref(0);
const fillSeries = ref(0);
const fillDirection = ref(0);
const fillDateUnit = ref(0);
const step = ref("");
const stop = ref("");
const btnFillAuto = ref(true);
const getRange = (sheet, rangeString) => {
try {
let rangeObject = GC.Spread.Sheets.CalcEngine.formulaToExpression(sheet, rangeString).getRange(0, 0);
let 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");
}
}
function fillMethodChangedHandle() {
switch (fillMethods.value) {
case 0:
fillSeriesSet.value = true;
btnFillAuto.value = true;
fillDateUnitSet.value = false;
fillDirectionSet.value = false;
btnFillAutobyDirection.value = false;
btnFillLinear.value = false;
btnFillGrowth.value = false;
btnFillDate.value = false;
fillStepAndStop.value = false;
break;
case 1:
fillDirectionSet.value = true;
btnFillAutobyDirection.value = true;
fillDateUnitSet.value = false;
fillSeriesSet.value = false;
btnFillAuto.value = false;
btnFillLinear.value = false;
btnFillGrowth.value = false;
btnFillDate.value = false;
fillStepAndStop.value = false;
break;
case 2:
fillSeriesSet.value = true;
btnFillLinear.value = true;
fillStepAndStop.value = true;
fillDateUnitSet.value = false;
fillDirectionSet.value = false;
btnFillAuto.value = false;
btnFillAutobyDirection.value = false;
btnFillGrowth.value = false;
btnFillDate.value = false;
break;
case 3:
fillSeriesSet.value = true;
btnFillGrowth.value = true;
fillStepAndStop.value = true;
fillDateUnitSet.value = false;
fillDirectionSet.value = false;
btnFillAuto.value = false;
btnFillAutobyDirection.value = false;
btnFillLinear.value = false;
btnFillDate.value = false;
break;
case 4:
fillSeriesSet.value = true;
btnFillDate.value = true;
fillStepAndStop.value = true;
fillDateUnitSet.value = true;
fillDirectionSet.value = false;
btnFillAuto.value = false;
btnFillAutobyDirection.value = false;
btnFillGrowth.value = false;
btnFillLinear.value = false;
break;
}
}
function initSpread(spread) {
spreadRef.value = 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);
startRangeFormulaTextBox.value = _startRangeFormulaTextBox;
wholeRangeFormulaTextBox.value = _wholeRangeFormulaTextBox;
spread.options.newTabVisible = false;
let sheet = spread.getSheet(0);
sheet.setValue(0, 0, 1);
}
function btnFillAutoHandler() {
let sheet = spreadRef.value.getActiveSheet();
let startRange = getRange(sheet, startRangeFormulaTextBox.value.text());
let wholeRange = getRange(sheet, wholeRangeFormulaTextBox.value.text());
if (fillSeries.value === 1) {
wholeRange.rowCount = startRange.rowCount;
} else {
wholeRange.colCount = startRange.colCount;
}
sheet.fillAuto(startRange, wholeRange, {
series: fillSeries.value,
fillType: GC.Spread.Sheets.Fill.FillType.auto
});
}
function btnFillAutobyDirectionHandler() {
let sheet = spreadRef.value.getActiveSheet();
let startRange = getRange(sheet, startRangeFormulaTextBox.value.text());
let wholeRange = getRange(sheet, wholeRangeFormulaTextBox.value.text());
sheet.fillAuto(startRange, wholeRange, {
direction: fillDirection.value,
fillType: GC.Spread.Sheets.Fill.FillType.direction
});
}
function btnFillLinearHandler() {
let sheet = spreadRef.value.getActiveSheet();
let startRange = getRange(sheet, startRangeFormulaTextBox.value.text());
let wholeRange = getRange(sheet, wholeRangeFormulaTextBox.value.text());
let _stop;
if (stop.value !== "") {
_stop = parseInt(stop.value);
}
sheet.fillAuto(startRange, wholeRange, {
series: fillSeries.value,
step: step.value,
stop: _stop,
fillType: GC.Spread.Sheets.Fill.FillType.linear
});
}
function btnFillGrowthHandler() {
let sheet = spreadRef.value.getActiveSheet();
let startRange = getRange(sheet, startRangeFormulaTextBox.value.text());
let wholeRange = getRange(sheet, wholeRangeFormulaTextBox.value.text());
let _stop;
if (stop.value !== "") {
_stop = parseInt(stop.value);
}
sheet.fillAuto(startRange, wholeRange, {
series: fillSeries.value,
step: step.value,
stop: _stop,
fillType: GC.Spread.Sheets.Fill.FillType.growth
});
}
function btnFillDateHandler() {
let sheet = spreadRef.value.getActiveSheet();
let startRange = getRange(sheet, startRangeFormulaTextBox.value.text());
let wholeRange = getRange(sheet, wholeRangeFormulaTextBox.value.text());
let _stop;
if (stop.value !== "") {
_stop = parseInt(stop.value);
}
sheet.fillAuto(startRange, wholeRange, {
series: fillSeries.value,
unit: fillDateUnit.value,
step: step.value,
stop: _stop,
fillType: GC.Spread.Sheets.Fill.FillType.date
});
}
</script>
<style scoped>
.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;
}
</style>
<!DOCTYPE html>
<html style="height:100%;font-size:14px;">
<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$/en/vue3/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/en/vue3/node_modules/systemjs/dist/system.src.js"></script>
<script src="./systemjs.config.js"></script>
<script src="./compiler.js" type="module"></script>
<script>
var System = SystemJS;
System.import("./src/app.js");
System.import('$DEMOROOT$/en/lib/vue3/license.js');
</script>
</head>
<body>
<div id="app" style="height: 100%;"></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/@mescius/*/package.json",
"./node_modules/@babel/*/package.json",
"./node_modules/@vue/*/package.json"
],
map: {
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-io': 'npm:@mescius/spread-sheets-io/index.js',
'@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js',
'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",
},
meta: {
'*.css': { loader: 'systemjs-plugin-css' },
'*.vue': { loader: "../plugin-vue/index.js" }
}
});
})(this);