我正在使用PHP_XLSXWriter。
我想做以下预期输出:
这是我的代码:
$dataProvider=new CActiveDataProvider('Book', array(
'criteria'=>array(
'with'=>array('author'),
),
'pagination'=>array(
'pageSize'=>20,
),
));
应该如何控制?在我的代码?
答案 0 :(得分:3)
有更好的选择可以做到这一点,但我只能做这种解决方法。它可能对你有所帮助。
<?php
include_once("xlsxwriter.class.php"); //include
$writer = new XLSXWriter(); //new writer
$sheet_name = 'sheets'; //sheetname
$header = array("string","string","string","string","string","string"); // header-made for six columns
$row1 = array("A"," ","B"," ","C"); //column B1, D1 made blank to match formatting
$writer->writeSheetHeader($sheet_name, $header, $suppress_header_row = true); //write header
$writer->markMergedCell($sheet_name, $start_row = 0, $start_col = 0, $end_row = 1, $end_col = 1); //merge cells for A
$writer->markMergedCell($sheet_name, $start_row = 0, $start_col = 2, $end_row = 0, $end_col = 3); //merge cells for B
$writer->markMergedCell($sheet_name, $start_row = 0, $start_col = 4, $end_row = 0, $end_col = 5); //merge cells for C
$writer->writeSheetRow($sheet_name, $row1); //write data
$writer->writeToFile('test.xlsx'); //save file
?>
编辑:如果您需要循环以重复相同的合并方式,请执行此操作
<?php
include_once("xlsxwriter.class.php"); //include
$writer = new XLSXWriter(); //new writer
$sheet_name = 'sheets'; //sheetname
$header = array("string","string","string","string","string","string","string","string","string","string","string","string","string","string","string","string","string","string","string"); // header-made for 19 columns
$row1 = array("A"," ","B"," ","C"," ","D"," ","E"," ","F"," ","G"," ","H"," ","I"," ","J"); //column B1, D1, F1, H1, J1, L1, N1, P1, R1 made blank to match formatting
$writer->writeSheetHeader($sheet_name, $header, $suppress_header_row = true); //write header
$writer->markMergedCell($sheet_name, $start_row = 0, $start_col = 0, $end_row = 1, $end_col = 1); //merge cells for A
$j = 2; //start column
for ($i=0; $i<9; $i++)
{
$writer->markMergedCell($sheet_name, $start_row = 0, $start_col = $j, $end_row = 0, $end_col = $j+1); //merge cells
$j+=2;
}
$writer->writeSheetRow($sheet_name, $row1); //write data
$writer->writeToFile('test.xlsx'); //save file
?>