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.
import { Component, NgModule, enableProdMode } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { SpreadSheetsModule } from '@mescius/spread-sheets-angular';
import GC from '@mescius/spread-sheets';
import './styles.css';
@Component({
selector: 'app-component',
templateUrl: 'src/app.component.html'
})
export class AppComponent {
spread: GC.Spread.Sheets.Workbook;
fillDirectionSet = false;
fillDateUnitSet = false;
fillStepAndStop = false;
btnFillAutobyDirection = false;
btnFillLinear = false;
btnFillGrowth = false;
btnFillDate = false;
fillSeriesSet = true;
btnFillAuto = true;
fillMethods = 0;
fillSeries = 0;
fillDirection = 0;
fillDateUnit = 0;
step = "";
stop = "";
startRangeFormulaTextBox: GC.Spread.Sheets.FormulaTextBox.FormulaTextBox;
wholeRangeFormulaTextBox: GC.Spread.Sheets.FormulaTextBox.FormulaTextBox;
hostStyle = {
width: '100%',
height: '100%',
overflow: 'hidden',
float: 'left'
};
fillMethodChangedHandle($event: any) {
this.fillMethods = parseInt($event.target.value, 10);
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($event: any) {
this.spread = $event.spread;
let spread = this.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 (parseInt(this.fillSeries) === 1) {
wholeRange.rowCount = startRange.rowCount;
} else {
wholeRange.colCount = startRange.colCount;
}
sheet.fillAuto(startRange, wholeRange, {
series: parseInt(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: parseInt(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);
}
var options={
series: parseInt(this.fillSeries),
step: parseInt(this.step),
stop: stop,
fillType: GC.Spread.Sheets.Fill.FillType.linear
};
sheet.fillAuto(startRange, wholeRange,options);
}
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);
}
var options={
series: parseInt(this.fillSeries),
step: parseInt(this.step),
stop: stop,
fillType: GC.Spread.Sheets.Fill.FillType.growth
};
sheet.fillAuto(startRange, wholeRange,options );
}
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);
}
var options= {
series: parseInt(this.fillSeries),
unit: parseInt(this.fillDateUnit),
step: parseInt(this.step),
stop: stop,
fillType: GC.Spread.Sheets.Fill.FillType.date
}
sheet.fillAuto(startRange, wholeRange,options);
}
}
const getRange = (sheet: GC.Spread.Sheets.Worksheet, rangeString: string) => {
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");
}
}
@NgModule({
imports: [BrowserModule, SpreadSheetsModule, FormsModule],
declarations: [AppComponent],
exports: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!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/angular/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<!-- Polyfills -->
<script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script>
<script src="$DEMOROOT$/en/angular/node_modules/zone.js/fesm2015/zone.min.js"></script>
<script src="$DEMOROOT$/spread/source/data/ellipsis.js" type="text/javascript"></script>
<!-- SystemJS -->
<script src="$DEMOROOT$/en/angular/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.import('@angular/compiler');
System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators));
System.import('$DEMOROOT$/en/lib/angular/license.ts');
System.import('./src/app.component');
});
</script>
</head>
<body>
<app-component></app-component>
</body>
</html>
<div class="sample-tutorial">
<gc-spread-sheets class="sample-spreadsheets" [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)">
</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($event)" [value]="fillMethods|number" >
<option value='0' >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" *ngIf="fillSeriesSet">
<label>FillSeries</label>
<select id="fillSeries" [(ngModel)] = "fillSeries" [value] = "fillSeries|number">
<option value=0>Column</option>
<option value=1>Row</option>
</select>
</div>
<div id="fillDirectionSet" *ngIf="fillDirectionSet">
<label>FillDirection</label>
<select id="fillDirection" [(ngModel)]="fillDirection" [value]="fillDirection|number">
<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" *ngIf="fillDateUnitSet">
<label>FillDateUnit</label>
<select id="fillDateUnit" [(ngModel)]="fillDateUnit" [value] = "fillDateUnit|number">
<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" *ngIf="fillStepAndStop">
<label>Step</label>
<input type="text" id="step"[(ngModel)]="step" [value] = "step|number" />
<label>Stop</label>
<input type="text" id="stop" [(ngModel)]="stop" [value] = "stop|number" />
</div>
<div class="option-row">
<label></label>
<input type="button" id="btnFillAuto" value="fillAuto" *ngIf="btnFillAuto" (click)="btnFillAutoHandler()" />
<input type="button" id="btnFillAutobyDirection" value="fillAutobyDirection" *ngIf="btnFillAutobyDirection" (click)="btnFillAutobyDirectionHandler()" />
<input type="button" id="btnFillLinear" value="fillLinear" *ngIf="btnFillLinear" (click)="btnFillLinearHandler()" />
<input type="button" id="btnFillGrowth" value="fillGrowth" *ngIf="btnFillGrowth" (click)="btnFillGrowthHandler()" />
<input type="button" id="btnFillDate" value="fillDate" *ngIf="btnFillDate" (click)="btnFillDateHandler()" />
</div>
</div>
</div>
.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: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
},
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'core-js': 'npm:core-js/client/shim.min.js',
'zone': 'npm:zone.js/fesm2015/zone.min.js',
'rxjs': 'npm:rxjs/dist/bundles/rxjs.umd.min.js',
'@angular/core': 'npm:@angular/core/fesm2022',
'@angular/common': 'npm:@angular/common/fesm2022/common.mjs',
'@angular/compiler': 'npm:@angular/compiler/fesm2022/compiler.mjs',
'@angular/platform-browser': 'npm:@angular/platform-browser/fesm2022/platform-browser.mjs',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/fesm2022/platform-browser-dynamic.mjs',
'@angular/common/http': 'npm:@angular/common/fesm2022/http.mjs',
'@angular/router': 'npm:@angular/router/fesm2022/router.mjs',
'@angular/forms': 'npm:@angular/forms/fesm2022/forms.mjs',
'jszip': 'npm:jszip/dist/jszip.min.js',
'typescript': 'npm:typescript/lib/typescript.js',
'ts': './plugin.js',
'tslib':'npm:tslib/tslib.js',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js',
'@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js',
'@mescius/spread-sheets-angular': 'npm:@mescius/spread-sheets-angular/fesm2020/mescius-spread-sheets-angular.mjs',
'@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
"node_modules/@angular": {
defaultExtension: 'mjs'
},
"@mescius/spread-sheets-angular": {
defaultExtension: 'mjs'
},
'@angular/core': {
defaultExtension: 'mjs',
main: 'core.mjs'
}
}
});
})(this);