PHPExcel如何将对齐方式应用于从mysql表创建的整个文档 [英] PHPExcel how to apply alignment for the whole document created from mysql table
本文介绍了PHPExcel如何将对齐方式应用于从mysql表创建的整个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用PHPExcel
库基于mysql查询创建的表生成excel文件.我使用来自不同查询的单个数据创建了多个选项卡.
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.
这是我的代码:
$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
为整个工作簿设置默认样式
Set a default style for the entire workbook
$objPHPExcel->getDefaultStyle()
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
选项#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);
这篇关于PHPExcel如何将对齐方式应用于从mysql表创建的整个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文