Rahul Kumar

Rahul Kumar

  • 1.9k
  • 43
  • 1.5k

How to Import Excel into SQL In Angular 5

Aug 28 2018 5:29 AM
HTML:
 
<form class="form-horizontal" [formGroup]="UploadCodeBlockExcelForm" (submit)="onSubmit()" novalidate>
<div class="box-body">
<fieldset>
<div class="row">
<div class="col-md-2 upload">
<label>Upload Excel :</label>
</div>
<div class="col-md-3">
<input type="file" formControlName="FileUpload" id="uploadexcel" (change)="UploadExcel($event)" accept=".xlsx" />
</div>
<div class="col-md-5"></div>
<div class="col-md-3">
<!--[disabled]="!firmForm.valid"-->
<input type="submit" class="btn btn-info" value="Upload" name="submit"/>
<!--<button type="submit" class="btn btn-secondary">Save</button>
<button type="button" routerLink="/" class="btn btn-secondary">Cancel</button>-->
</div>
</div>
<div>&nbsp;</div>
</fieldset>
</div>
</form>
 
UploadExcel(event) {
debugger;
let fileReader = new FileReader();
this.file = event.target.files[0];
var filename = this.file.name;
if (event.target.files && event.target.files.length > 0) {
let file = event.target.files[0];
fileReader.readAsDataURL(file);
fileReader.onload = () => {
this.UploadCodeBlockExcelForm.get('uploadexcel').setValue({
filename: file.name,
filetype: file.type,
value: fileReader.result.slice(0)
})
};
}
}
onSubmit(filename) {
const formModel = this.UploadCodeBlockExcelForm.value;
//this.loading = true;
// In a real-world app you'd have a http request / service call here like
// this.http.post('apiUrl', formModel)
setTimeout(() => {
console.log(formModel);
alert('done!');
//this.loading = false;
}, 1000);
}
 

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (1)