Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
it work for MS-OFFICE EXCEL 2007 BUT IT DOES NOT WORK ON EXCEL 2010 OR LATER VERSION

1. var dataType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

this works for excel 2007, but doesnot workout for excel 2010. please i need help

What I have tried:

I have tried all this but it doesnot work for MS-OFFICE 2010

1. var dataType = 'application/vnd.ms-excel.12'
2. var dataType = 'application/vnd.ms-excel;base64,';
3. var dataType = 'application/octet-stream';
4. var dataType = 'application/vnd.ms-excel';
Posted
Updated 14-May-19 2:11am

1 solution

The MIME code for XLSX files is
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
 
Share this answer
 
Comments
Member 14367500 14-May-19 8:33am    
var dataType ="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Member 14367500 14-May-19 8:46am    
jsp file
Excel js file

function exportExcel(tableID, filename = ''){

var downloadLink;
//var dataType = 'application/vnd.ms-excel.12'
//Response.ContentType ="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
// var dataType ="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

var dataType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
var tableSelect = document.getElementById(tableID);
var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');

// Specify file name
filename = filename?filename:'excel_data';

// Create download link element
downloadLink = document.createElement("a");

document.body.appendChild(downloadLink);

if(navigator.msSaveOrOpenBlob){
var blob = new Blob(['\ufeff', tableHTML], {
type: dataType
});
navigator.msSaveOrOpenBlob( blob, filename);
}else{
// Create a link to the file
downloadLink.href = 'data:' + dataType + ', ' + tableHTML;

// Setting the file name
downloadLink.download = filename;

//triggering the function
downloadLink.click();

}
}

it didn't work out as for Office 2010 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
MadMyche 14-May-19 9:40am    
It looks like the problem is not with the Content-Type, the problem looks to be the content itself; which is not a valid Excel file.
Yes, the HTML table would work (sloppily) in the older format; but that was not valid either in all reality
Member 14367500 14-May-19 10:34am    
I Hope contenttype meants MIME Type
.xlsx
MadMyche 14-May-19 10:56am    
No, it actually means Content-Type. Often used interchangeably with MIME type but they are different

Content-Type in this context is an HTTP header to indicate the media type of a resource, consisting of up to 3 parts
1. media-type: A two part identifier for file formats and contents
2. charset: Character Encoding Standard.
3. boundary: required for multipart entities

MIME is a standard for extending the format of email, and has headers providing similar information
1. MIME version
2. Content-Type
3. Content-Disposition
4. ...and so on

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900