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
NA
1.6k
278.7k
Export to excel not working when export any json data object
May 9 2020 12:27 PM
I work on angular 7 app i export data to excel it generate file excel but cannot open it
why and how to solve issue
my code used as below
public
exportAsExcelFile(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:
'buffer'
});
this
.saveAsExcelFile(excelBuffer, excelFileName);
}
private
saveAsExcelFile(buffer: any, fileName: string):
void
{
const
data: Blob =
new
Blob([buffer], {
type: EXCEL_TYPE
});
const
today =
new
Date();
const
date = today.getFullYear() +
''
+ (today.getMonth() + 1) +
''
+ today.getDate() +
'_'
;
const
time = today.getHours() +
"-"
+ today.getMinutes() +
"-"
+ today.getSeconds();
const
name = fileName + date + time;
FileSaver.saveAs(data, name + EXCEL_EXTENSION);
}
getDataByRevision(RevId : any)
{
console.log(
this
.reportdetailslist);
this
.exportAsExcelFile(
this
.reportdetailslist,
'datarevision'
);
}
it download and generate file excel but it is not open
I think problem on excel it self so i open new angular app and export to excel
it is ok exporting without any issue
this meaning i have some issue on my code above
can you help me please
Excel generating attached with post or thread
Attachment:
datarevision202059_19-14-18.zip
Reply
Answers (
0
)
How to convert this code from angular js to typescript angu7
when export data to excel error excel file not readable cont