я использую PHP_XLSXWriter.
Я хочу сделать следующий ожидаемый результат:
Вот мой код:
<?php
include_once('./PHP_XLSXWriter-master/xlsxwriter.class.php');
$writer = new XLSXWriter();
$sheet_name = 'Sheet1';
$header = array("A", "B", "C");
$writer->writeSheetRow($sheet_name, $header);
$writer->markMergedCell($sheet_name, $start_row = ?, $start_col = ?, $end_row = ?, $end_col = ?);
$writer->writeToFile('test.xlsx');
?>
Как контролировать? в моем коде?
Для этого могут быть лучшие варианты, но я мог бы сделать только такой обходной путь. Это может быть полезно для вас.
<?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
?>
Других решений пока нет …