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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:34:08+00:00 2026-06-13T17:34:08+00:00

I have this PHPExcel code: /** Error reporting */ error_reporting(E_ALL); date_default_timezone_set(‘Europe/London’); /** Include PHPExcel

  • 0

I have this PHPExcel code:

/** Error reporting */
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');

/** Include PHPExcel */
require_once '../Classes/PHPExcel.php';
    $objPHPExcel = new PHPExcel();
    //$objPHPExcel->setActiveSheetIndex(0)
               // ->setCellValue('A1', 'Hello')
               // ->setCellValue('A2', 'world!')

$row = 2; 
while($row_data = mysql_fetch_assoc($result)) {
    $col = 1;
    foreach($row_data as $key=>$value) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$col++;
    }
        $row++;
    }

// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Results');

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Output.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;

Basically I am dynamically querying the database and placing it into an excel file.

I just want to hardcode in a few headers. So for A1 I’d like to hardcode in “Hello” and A2: “World!” while querying the database and putting the data starting in Column B

  • 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-13T17:34:08+00:00Added an answer on June 13, 2026 at 5:34 pm
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A1', 'Hello')
                ->setCellValue('A2', 'world!');
    
    $col = 1; 
    while($row_data = mysql_fetch_assoc($result)) {
        $row = 1;
        foreach($row_data as $value) {
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
            $row++;
        }
        $col++;
    }
    

    Note that Excel5 has a limit of 256 columns, so if you have more than 255 data records the additional columns will de dropped from the saved workbook if you’re saving to that format.

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

Sidebar

Related Questions

The code I currently have: <?php /** PHPExcel */ require_once '../Classes/PHPExcel.php'; /** PHPExcel_IOFactory */
I have encountered this error Fatal error: Class 'PHPExcel_Shared_ZipStreamWrapper' not found in \VBOXSVR\ACACIASOFT\apc\spreadsheet\lib\phpexcel\PHPExcel\Autoloader.php on
I am new to PHPExcel, first time I've used it. I have written this
Have have this line of code in my form when I create a new
have this code: $products = $feed->_xpath->query( //cf:vehicle ); foreach( $products as $product ) {
Have this code: var gradient = ctx.createLinearGradient(0,0, 20, 0); gradient.addColorStop(0.8, rgb(250,250,0)); gradient.addColorStop(1, rgb(150,150,0)); ctx.fillStyle
Have this code: <sj:head compressed=false jqueryui=true jquerytheme=custom/> <s:url id=link action=ABC namespace=/DEF escapeAmp=false/> <sj:a openDialog=_dialog
have this code import threading def Thread(f): def decorator(*args,**kargs): print(args) thread = threading.Thread(target=f, args=args)
I have this code in jQuery, that I want to reimplement with the prototype
Have this code: set_time_limit(100); ini_set('user_agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20100101

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.