Write text between merged cells using phpExcel - phpexcel

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?

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

$objPHPExcel->getActiveSheet()->mergeCells('A1:A2');
$objPHPExcel->getActiveSheet()->getCell('A1')->setValue('Your lable');
$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

Related

Remove all numbers in the text column but error

I have a material A, and I use "select()" to pick out text column,and then using "str_replace_all()" to delete all numbers.
This is the code I wrote. I expect text column will not appear any of numbers, showing only text column without other columns.
B<-select(A,text)%>%
text = str_replace_all(text,
pattern ="\d",
replacement="")
B
I'm not sure what's wrong in it...
Besides, if i want to reserve other columns,how can I cancel "select()" function and reserve text column which has revised?

PHPExcel - cell formating

if I fill a cell with the value "0.07" and then define it as a percentage, excel turns this value into "7,00". Can someone tell me how to work correctly? thanks
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowCount,'0.07');
$objPHPExcel->getActiveSheet()->getStyle($col.$rowCount)->getNumberFormat()->applyFromArray(array('code' => PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00));
if i change and set the value to "0,07" - excel means that the value is formatted as text.
ok, i found a simple solution:
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowCount, 0.07/100);
$objPHPExcel->getActiveSheet()->getStyle($col.$rowCount)->getNumberFormat()->setFormatCode('0.00%');
i am happy if it helps others.

Display cumulative value of each column in balloon text

I built a cumulative line graph using context.cumulativeCol() in the Value field and I am interested in displaying the cumulated value of the current column in the ballon text.
This is what I have, which only shows the value of the column:
I tried to change the default value [[Row]], [[Column]]: [[Value]] from the Ballon Text field and tried to use something like context.cumulativeCol() but I could not achieve my goal.
If it is possible, how am I supposed to do it?
I've just tried to put:
return "Cumulative: " + context.cumulativeCol();
to the balloon function and it worked fine in the latest version. Perhaps you are trying to return a number instead of a string from the balloon function?

How can i make bullets list in PHPExcel

I was trying to convert the html tags from php to excel using PHPExcel, everything is going alright except that I can't find how to make bulletted list. is this feature exist in PHPExcel? i already scan some of the documentary of PHPExcel but i can't find anything about bullets.
i want to place the bulletted inside one cell
Thank you
You simply want a string containing newline characters, and then to set the cell to wrap
$value = "• Foo\n• Bar";
$objPHPExcel->getActiveSheet()
->setCellValue('A10', $value);
$objPHPExcel->getActiveSheet()
->getRowDimension(10)
->setRowHeight(-1);
$objPHPExcel->getActiveSheet()
->getStyle('A10')
->getAlignment()
->setWrapText(true);

turning text into paginated two-column format and pipe this into less

I want to read a long text file in two-column format on my terminal. This means that the columns must be page-aware, so that text at the bottom of the first column continues at the top of the second column, but text at the bottom of the second column continues at the beginning of the first column after a page-down.
I tried column and less to get this result, but with no luck. If I pipe the text into column, it produces two columns but truncates the text before it reaches the end of the file. And if I pipe the output of column into less, it also reverts back to single-column.
a2ps does what I want in the way of reformatting, but I would rather have the output in pure plain text, readable from the terminal, rather than a PostScript file that I would need to read in a PDF reader.
You can use pr for this, eg.
ls /usr/src/linux/drivers/char/ | pr -2 |less

Resources