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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:47:26+00:00 2026-06-11T21:47:26+00:00

I used PHPExcel library to generate excel files based on the table created by

  • 0

I used PHPExcel library to generate excel files based on the table created by the mysql query. I created multiple tabs with individual data from different queries.

I need to align the data in the all the cells in all the tabs (worksheets) to center.

This is my code:

$mysql_xls = new MySqlExcelBuilder($mysql_db,$mysql_user,$mysql_pass);

// Add the SQL statements to the spread sheet

$tab_name = "tabname";
$mysql_xls->add_page($tab_name,$sql_statement,NULL,'A',1);

$phpExcel = $mysql_xls->getExcel();

$phpExcel->setActiveSheetIndex(0); // Set the sheet to the first page (default first page).

I tried the following to align the text in the cells but no change:

$phpExcel->getActiveSheet(0)->getStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  • 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-11T21:47:27+00:00Added an answer on June 11, 2026 at 9:47 pm

    Option #1

    Set a default style for the entire workbook

    $objPHPExcel->getDefaultStyle()
        ->getAlignment()
        ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    

    Option #2

    Apply the style to a range of cells (the entire worksheet in this case) on each individual worksheet

    $phpExcel->getActiveSheet()
        ->getStyle( $phpExcel->getActiveSheet()->calculateWorksheetDimension() )
        ->getAlignment()
        ->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PHPExcel for transferring data between MySQL DB and Excel 2007 worksheets. It
currently, I used PHPExcel to import excel file, there is a function $cell->getCoordinate(); I
When I create an Excel Sheet with PHPEXCEL based on the 01simple-download-xlsx.php example, I
Used code I found on SO to use the COM based Acrobat Reader to
Anybody used Neural Network approaches for clustering data? Particularly ART Neural Network (Adaptive Resonance
I used Session[EmpName] = Convert.ToString(Request.QueryString[1]); lblEmployeeName.Text = Session[EmpName].ToString; to show the data in label
I am using phpexcel class to read .xls, .ods and .xlsx files, I need
I used the follwoing statement to copy over files from one folder to another...
Used http://www.ilbcfreeware.org/software.html - I only get static from the files that ilbc_test.exe creates. Does
I used the WCat Scenario Creator (http://fiddler2wcat.codeplex.com/) to generate the scripts of many requests

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.