cheers all
I'm working on a website that displays excel 2007 files (xlsm) which are written to and stored on our file system.

Users with MS Office 2003 cannot open these files from a webpage, even though they have the compatibility upgrade to see Office 2007 files. Users with Office 2007 can view the files just fine. I figured this has to be a headers issue.

I've added to my script the following header code:

// $ext is the extension parsed from the file name
switch($ext){
case 'xls':  // for older files
	header("Content-Type: application/vnd.ms-excel;");
	break;
case 'xlsm':
	header("Content-Type: application/vnd.ms-excel.sheet.macroEnabled.12");    
break; } // $filename is the file name with path print file_get_contents($filename);

Do I need any other headers with this? Does anyone know why this will not work for Office 2003 users with the compatibility pack?

I know we can save the files as Excel 2003 compatible, but I'd like to get this working as is for Excel 2007 files.

Thanks for any tips.
jc

    Perhaps 2003 Doesn't recognize the "macroEnabled"?

    Have you tried adding xlsx and xlsm as vnd.ms-excel?

    Also, if this is IIS, why don't you add the content type to IIS directly? You can find info Here.

    or with Apache, .htaccess, which I BELIEVE is..

    AddType application/vnd.ms-excel.sheet.macroEnabled.12 .xlsm 
    

    Someone may be able to correct me on it though.

      Hey big.nerd - cool name... 🙂

      I'm not sure what you mean by:

      Have you tried adding xlsx and xlsm as vnd.ms-excel?

      I did try header("Content-type: application/x-msexcel"). This was from a forum for some one with a similar problem. It did not work.

      We are on apache and I had already added the AddTypes for Office 2007. That was my first attempt. But, we are displaying a .html page which then serves up the Excel document. I believe the AddTypes in apache are basically for rendering the matching type of page, i.e: addtype for pdf would be for a page like /somepage.pdf. At least that is my understanding.

      The users with Office 2003 and the compatability pack can see Office 2007 Excel (xlsm) files as long as they do NOT come from a web page. Email attachments - yes, html - no.

      Thanks for the tips.
      jc

        4 days later

        It turns out through trial and error that our best guess is the Compatibility Pack in Office 2003 does not recognize the header:

        header("Content-Type: application/vnd.ms-excel.sheet.macroEnabled.12");
        

        To resolve this I just poured the file to the browser and let the browser be smart enough to determine which application to use to open it. IE and FF can do this. These are the only ones we work in at our shop.

        It works!

            $full_path = // path to the file
            if (file_exists($full_path)) {
               $fp=fopen($full_path, "r");
        	   if($fp){
        		   while(@ob_end_clean());
        		   $parts = preg_split('/\./', $row_data['VC_FILE_NAME']);
        		   $ext = $parts[count($parts)-1];
        		   if ($ext == "xls") {
        			   header("Content-type: application/vnd.ms-excel");
        			   header('Pragma: private');  
        header('Cache-control: private, must-revalidate'); fpassthru($fp); exit; }elseif( $ext == "xlsm") { # The compatibility pack in Office 2003 does not recognize this header type - yet # We'll let the browser determine which app to show it in. # header("Content-Type: application/vnd.ms-excel.sheet.macroEnabled.12"); header("Content-type: application/octet-stream"); header('Pragma: private'); header('Cache-control: private, must-revalidate'); header("Content-Disposition: inline; filename=".preg_replace('/[^a-zA-Z0-9\.]+/', '', $row_data['VC_FILE_NAME'])); fpassthru($fp); exit; }else{ // print message to user that the file can't be seen.... }
          Write a Reply...