Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:35:35+00:00 2026-06-04T11:35:35+00:00

I have a page that creates an xls file with PHPExcel on post, which

  • 0

I have a page that creates an xls file with PHPExcel on post, which works fine, the file download pops up and everything is golden, but when i try to open the file i get an error saying excel cannot open the file. I checked all the data going in and everything was fine, so i figured it had to be something with the file.

I opened the downloaded xls in notepad++, and sure enough, there was html at the top of the file, the same html for the page, up to where the content was called and the php checking the post ran. As soon as i deleted that it opened up just fine, still missing a few fields, but I’d like to make it actually viewable before i worry about that.

Here’s my code for creating the xls

global $__CMS_CONN__;
error_reporting(E_ALL);
$listmem = $_SESSION['listmem'];
$evtdate1 = date('Y-m-d', strtotime('-1 year', strtotime(date('Y-m-d'))));
$evtdate2 = date('Y-m-d');
require_once('/web/content/wolf/plugins/Classes/PHPExcel.php');
$sql = "SELECT Count(*) AS number FROM (SELECT DISTINCT event_timestamp FROM membership_attendance_log WHERE event_timestamp >= '".$evtdate1."' AND event_timestamp <= '".$evtdate2."') as numevents";
$evtcount = $__CMS_CONN__->prepare($sql);
$evtcount->execute();
$count = $evtcount->fetchAll(PDO::FETCH_ASSOC);
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->mergeCells('A1:C1');
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Date Range: '.$evtdate1." to ".$evtdate2)
            ->setCellValue('D1', 'Total number of events: '.$count['number'])
            ->setCellValue('A2', 'Member')
            ->setCellValue('B2', 'Missed Meetings')
            ->setCellValue('C2', 'Attendance')
            ->setCellValue('D2', 'Business Name')
            ->setCellValue('E2', 'Title')
            ->setCellValue('F2', 'Phone')
            ->setCellValue('G2', 'Email');
$objPHPExcel->getActiveSheet()->getStyle('A1:H1')->getFont()->setBold(true);
$i = 3;
foreach($listmem as $row)
{
    $qry = "SELECT Count(membership_individual_id) AS attendance FROM membership_attendance_log WHERE membership_individual_id=".$row['id']." AND event_timestamp >= '".$evtdate1."' AND event_timestamp <= '".$evtdate2."'";
    $stmt = $__CMS_CONN__->prepare($qry);
    $stmt->execute();
    $attendance = $stmt->fetchAll(PDO::FETCH_ASSOC);

    $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A'.$i, $row['first_name']." ".$row['last_name'])
                ->setCellValue('B'.$i, $attendance['attendance'])
                ->setCellValue('C'.$i, floor($attendance['attendance'] / $count['number']))
                ->setCellValue('D'.$i, $row['business_name'])
                ->setCellValue('E'.$i, $row['title'])
                ->setCellValue('F'.$i, $row['business_phone'])
                ->setCellValue('G'.$i, $row['email']);
    $i++;
}
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->setTitle('Report');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Report-'.date("mdY").'.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;

This is on a site using wolfCMS, just fyi. I tried pulling it out of the file and just having it post to a seperate php file but i still got the same thing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:35:37+00:00Added an answer on June 4, 2026 at 11:35 am

    Try adding this just before sending the header
    ob_end_clean();
    It should solve your problem. I think some data on output buffer is causing the issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .Net application that dynamically creates a small HTML page and pops
I have a class Page that creates an instance of DB , which is
I have a page that creates an associative array, then passes it as a
I have the following method that creates a cookie in the page's response. Immediately
I have a query that is more complicated, but basically creates an HTML page
Today we have a windows application that, using an OCX, creates a web page
My problem is this I have a base page that creates content dynamically. There
I have an aspx page that on a button click creates a BackgroundWorker and
I have a php page that creates page data from two .txt files (one
I have a script that creates a printable page by copying the HTML across

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.