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 8182113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:44:49+00:00 2026-06-07T00:44:49+00:00

Okay, next PHPExcel question. I have an HTML form that users fill out and

  • 0

Okay, next PHPExcel question. I have an HTML form that users fill out and the data will be sent to a database. All this works with no problems. I am using PHPExcel to send that information to an Excel worksheet so the President of the organization can view reports that have been sent in (he chose that he wanted it in Excel). When he clicks the button, the information is downloaded to Excel. This all works fine, except for the first line of the worksheet is covered by the Header information. I know that it is the header, because if I change $headings and delete value(s) in the array, part(s) of the hidden query then shows.

I got this code from: http://phpexcel.codeplex.com/discussions/246121/

There may be a coding error, or I may not have uploaded all the files and classes to the internet…

Any help is appreciated. Thanks.

// connection with the database 
$dbhost = "I removed this for privacy"; 
$dbuser = "I removed this for privacy"; 
$dbpass = "I removed this for privacy"; 
$dbname = "I removed this for privacy"; 

mysql_connect($dbhost,$dbuser,$dbpass); 
mysql_select_db($dbname); 

// require the PHPExcel file 
require 'Classes/PHPExcel.php'; 

// simple query 

$query = "

SELECT dueDate, reporterName, program, noReportReason, recentActivity, impacted, fundsGenerated, fundsSpent, volunteers, input, potentialContacts, potentialSources
FROM reports
ORDER BY id

"; 

if ($result = mysql_query($query) or die(mysql_error())) 
{   
// Create a new PHPExcel object 
$objPHPExcel = new PHPExcel(); 
$objPHPExcel->getActiveSheet()->setTitle('Quarterly Project Reports'); 

// Loop through the result set 
$rowNumber = 1; 
while ($row = mysql_fetch_row($result)) 
{ 
$col = 'A'; 
foreach($row as $cell) 
{ 
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$cell); 
$col++; 
} 
$rowNumber++; 
}

$rowNumber = 1;
$headings = array('Due Date','Reporter Name','Name of Program','No Report This Quarter',
    'Recent Activity','Number of People Impacted','Funds Generated',
    'Funds Spent and Fuding Sources','Volunteers Mobilized','WNP Input',
    'Potential Contacts','Potential Sources'); 
$objPHPExcel->getActiveSheet()->fromArray(array($headings),NULL,'A'.$rowNumber);  

$rowNumber++; 
// Loop through the result set 
while ($row = mysql_fetch_row($result)) 
{
$col = 'A';
foreach($row as $cell) 
{
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$cell);
$col++;
}
$rowNumber++; 
}

//bold Header row
$objPHPExcel->getActiveSheet()->getStyle('A1:L1')->getFont()->setBold(true); 

//wrap column D
$objPHPExcel->getActiveSheet()->getStyle('D1:D'.$objPHPExcel->getActiveSheet()->getHighestRow())->getAlignment()->setWrapText(true);

//wrap column E
$objPHPExcel->getActiveSheet()->getStyle('E1:E'.$objPHPExcel->getActiveSheet()->getHighestRow())->getAlignment()->setWrapText(true); 

//set header row height
$objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);

//set column widths
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(30); 

// Save as an Excel BIFF (xls) file 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 

header('Content-Type: application/vnd.ms-excel'); 
header('Content-Disposition: attachment;filename="WNPQuarterlyReports.xls"'); 

$objWriter->save('php://output'); 
exit(); 
} 
echo 'a problem has occurred... no data retrieved from the database'; 
  • 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-07T00:44:51+00:00Added an answer on June 7, 2026 at 12:44 am

    You do have two loops through the resultset in this code, one starting at row #1, you then overwrite row 1 with your headers, then loop through the resultset again (which won’t actually loop because you’ve reached the end of the resultset in the first loop) that starts at row 2

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

Sidebar

Related Questions

Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay, I have looked everywhere and tried almost every suggestion that I could find
Okay so on my homepage http://www.stat-me.com i have a link that when pressed activates
Okay, so basicly I have this website that auto refreshes every couple of seconds,
Okay, I've realized that I really have asked way too many questions without contributing
okay so i have a div and a span right next to each other
Okay, so I have a shopping cart problem. I've decided to roll out my
Okay, my dilemma is this. I have an admin page that I use to
Okay we have a single - sign - on and the user will likely
Okay... We have a contact books in Exchange that gets exported into an XML

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.