TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
637
1.6k
281.9k
when export data to excel error excel file not readable cont
May 9 2020 5:45 PM
problem
Note main issue related to type script because i can get data but i cannot display on Excel when export
I work on angular 7 app I click button to export data from database to Excel it create file when i open it
give me error ( excel file not readable content ) why and how to solve issue this my problem .
I pass parameter value to stored procedure and execute it and get result from database then export it to excel .
Exec exec dbo.getRevision 19253747
Main issue why not export data to excel and how to make export correct this actually what i need .
web API
[HttpPost]
public
IActionResult GetDataBasedOnDynamicSp([FromBody] dynamic DataObjectRevision)
{
string SpName = DataObjectRevision[0].downLoadProcedureName;
string revid = DataObjectRevision[0].revisionID;
var
PostRevision = _reportservice.GetSpByRevisionId(revid, SpName);
return
Ok(PostRevision);
}
Angular service.ts
GetSpByRevisionId(datarevision : any){
return
this
.http.post<any>(
'http://localhost:61265/api/report'
,datarevision)
}
component.ts
public
exportJsonAsExcelFile(json: any[], excelFileName: string):
void
{
const
worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
const
workbook: XLSX.WorkBook = { Sheets: {
'data'
: worksheet }, SheetNames: [
'data'
] };
const
excelBuffer: any = XLSX.write(workbook, { bookType:
'xlsx'
, type:
'array'
});
this
.saveAsExcelFile(excelBuffer, excelFileName);
}
private
saveAsExcelFile(buffer: any, fileName: string):
void
{
const
data: Blob =
new
Blob([buffer], { type: EXCEL_TYPE });
FileSaver.saveAs(data, fileName +
new
Date().getTime() + EXCEL_EXTENSION);
}
getDataByRevision(RevId : any)
{
this
.ReportData.forEach(
function
(e) { e.revisionID=RevId });
this
._displayreport.GetSpByRevisionId(
this
.ReportData).subscribe(data=>{
console.log(data)
this
.exportJsonAsExcelFile(
this
.ReportData ,
'datarevision'
);
});
}
component .html
<td> <button (click)=
"getDataByRevision(rep[0])"
>Download</button> </td>
Data below is result of API and angular above and this data Exactly must show on Excel But this Not Done
(3) [{…}, {…}, {…}]
0: {revisionid: 19253747, revisionname:
"parts"
, revisioncity:
"usa"
}
1: {revisionid: 19253747, revisionname:
"company"
, revisioncity:
"russia"
}
2: {revisionid: 19253747, revisionname:
"family"
, revisioncity:
"german"
}
length: 3
__proto__: Array(0)
Reply
Answers (
1
)
Export to excel not working when export any json data object
How to pass data from component to another on angular 7 ?