本文介绍了PHPExcel使第一行加粗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使第一行中的单元格为粗体.
I am trying to make cells in first row are bold.
这是我为此目的创建的方法.
This is the method I have created for that purpose.
function ExportToExcel($tittles,$excel_name)
{
$objPHPExcel = new PHPExcel();
$objRichText = new PHPExcel_RichText();
// Set properties
$objPHPExcel->getProperties()->setCreator("SAMPLE1");
$objPHPExcel->getProperties()->setLastModifiedBy("SAMPLE1");
$objPHPExcel->getProperties()->setTitle("SAMPLE1");
$objPHPExcel->getProperties()->setSubject("SAMPLE1");
$objPHPExcel->getProperties()->setDescription("SAMPLE1");
// Add some data
$objPHPExcel->setActiveSheetIndex(0);
$letters = range('A','Z');
$count =0;
$cell_name="";
foreach($tittles as $tittle)
{
$cell_name = $letters[$count]."1";
$count++;
$value = $tittle;
$objPHPExcel->getActiveSheet()->SetCellValue($cell_name, $value);
// Make bold cells
$objPHPExcel->getActiveSheet()->getStyle($cell_name)->getFont()->setBold(true);
}
// Save Excel 2007 file
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
//$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$objWriter->save($excel_name.".xlsx");
}
问题出在输出excel文件中,单元格未加粗.
The problem is in output excel file the cells are not bold.
推荐答案
尝试此操作以获取单元格范围:
Try this for range of cells:
$from = "A1"; // or any value
$to = "B5"; // or any value
$objPHPExcel->getActiveSheet()->getStyle("$from:$to")->getFont()->setBold( true );
或单个单元格
$cell_name = "A1";
$objPHPExcel->getActiveSheet()->getStyle( $cell_name )->getFont()->setBold( true );
希望有帮助
这篇关于PHPExcel使第一行加粗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!