I have this code from phpExel.
$objPHPExcel->setActiveSheetIndex(1)->mergeCells('A1:I1');
This code creates some blank space between columns A1 to I1. Just want to add text in the center blank space(A1:I1).
I am trying this code:
$objPHPExcel->setActiveSheetIndex(1)->mergeCells('A1:I1','add some text here...');
but this code does not work. Can anyone help me please?
Microsoft Excel can wrap text so it appears on multiple lines in a cell. You can format the cell so the text wraps automatically, or enter a manual line break. But this will prevent you from a cell potentially taking up too much room on your worksheet.
If text is too long to be displayed in a single cell, the Spreadsheet allows you to wrap the text to make it display on multiple lines in the cell, or merge cells to combine two or more adjacent cells into a single larger/longer cell.
":I". ($row_count+4)); Where the variable $row_count has some unpredictable dynamic value like 25, 50, 75 and so on (no regular pattern). It merges the cells as shown in the preceding snap shot as can be seen immediately below the Note cell.
You simply write the text value that you want to the top-left cell in the merged cell range
$objPHPExcel->setActiveSheetIndex(1)
->mergeCells('A1:I1');
$objPHPExcel->getActiveSheet()
->getCell('A1')
->setValue('This is the text that I want to see in the merged cells');
EDIT
To centre the text, use
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
again, using the top-left cell of the range
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With