这是使用
的代码$key1 = $this->uri->segment(3);
$letter1 = "B";
for($i=0;$i<$key1;$i++){
//$letter1++;
$letter=$letter1++;
echo($letter);
$s = $letter+'3';
echo($s);}
这个输出为B3C3D3 .....
当我像这样使用时
$key1 = $this->uri->segment(3);
$letter1 = "B";
for($i=0;$i<$key1;$i++){
//$letter1++;
$letter=$letter1++;
echo($letter);
$s = $letter+'3';
echo($s);
$this->excel->getActiveSheet()->setCellValue($s, 'State');
$this->excel->getActiveSheet()->getColumnDimension($letter)->setWidth(20);
$this->excel->getActiveSheet()->getStyle($s)->getAlignment()->setWrapText(true);
$this->excel->getActiveSheet()->getStyle($s)->getFont()->setSize(10);
$this->excel->getActiveSheet()->getStyle($s)->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle($s)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
}
我没有得到excel表,也只得到输出只有B3
这里出了什么问题有人可以帮助我,谢谢。
答案 0 :(得分:0)
如果你想说出&#34; State&#34;进入B3,C3和D3列,试试这个:
<?php
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
/** Include PHPExcel */
require_once '../Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$sheet = $objPHPExcel->getActiveSheet();
$letter = "B";
for($i=0; $i<3; $i++){
$s = $letter . '3';
echo($s);
$sheet->setCellValue($s, 'State');
$letter++;
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("test.xlsx");
这将创建包含适当数据的test.xlsx文件。我写了骨架代码,我想你可以自己添加样式。