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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:13:56+00:00 2026-06-07T02:13:56+00:00

I want to have my excel file filled with some data which I get

  • 0

I want to have my excel file filled with some data which I get from my database, for example the name and age of someone.

Say there are 10 people in my database. I want those 10 people in my Excel file.

So basically, you would get:

NAME AGE

Person1 20 years

Person2 25 years

And so on. I know how to set the NAME and AGE stuff, but how would I go about looping the data and writing it inside the excel file? I couldn’t find anything about it in PHPExcel’s documentation.

This is my MySQL:

$query = "SELECT * FROM bestelling"; 

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
    $name = $row['name'];
    $age = $row['age'];
}
  • 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-07T02:13:58+00:00Added an answer on June 7, 2026 at 2:13 am

    I’m assuming you already have the excel object created. I’ll call it $objPHPExcel to conform to their examples. In that case you can loop your result set and populate the spreadsheet this way:

    $objPHPExcel = new PHPExcel();
    $objPHPExcel->setActiveSheetIndex(0);
    $rowCount = 1;
    while($row = mysql_fetch_array($result)){
        $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $row['name']);
        $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['age']);
        $rowCount++;
    }
    $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
    $objWriter->save('some_excel_file.xlsx');
    

    EDIT: I have updated the example to provide a complete solution.

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

Sidebar

Related Questions

I have an Excel file which contains some data in a 2d array. What
I have an Excel file with data in it. I want to write some
I have an excel file(VSTO), which will be uploaded with data. However I want
I have an Excel file containing data(list of Phone numbers), and i want that
I have an Excel file in which i have 50 questions i want to
I want to put some numbers from Excel to array. Let's say I have
I have an excel sheet which has some huge data. Data is organized as
I have exported data from a text file to an excel sheet, with the
I have an excel file with urls of type http://test.example.com/anything ... i want to
I am getting data from my database and I want to have that data

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.