Click here to Skip to main content
14,301,556 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

The MIME code for XLSX files is
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
   
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
Member 14367500 14-May-19 10:46am
   
i didn't set a content type [i.e something like this response.setContentType()],
thats everything in my code above
var dataType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
Member 14367500 14-May-19 11:03am
   
i guess this is what you mean
header('Content-Disposition: attachment; filename="name_of_excel_file.xls"');
but just to remind u, am not using .aspx is javascript in spring mvc

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100