Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bolding a cell in PHPExcel leaves it selected

Tags:

php

phpexcel

I am updating an Excel5 formatted spreadsheet with PHPExcel. After retrieving and setting some cells I have the following code:

$objPHPExcel->getActiveSheet()->getStyle("A$total_row:N$total_row")->getFont()->setBold(true);

The range of cells does get bolded. But it also is selected when the spreadsheet is opened in Excel, which I don't want. As a workaround I ended up selecting cell A1 by bolding it, but what is the correct way to select a cell in PHPExcel?

like image 915
George Avatar asked Oct 22 '13 18:10

George


People also ask

How do I make text bold in Excel using php?

The setBold() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the boldness of the text.

How do I merge cells in Excel using PHPExcel?

In code it would look a little something like this: $workbook = new PHPExcel; $sheet = $workbook->getActiveSheet(); $sheet->setCellValue('A1','A pretty long sentence that deserves to be in a merged cell');

Can php interact with Excel?

PHP provides a library to deal with Excel files. It is called PHP Excel library. It enables you to read and write spreadsheets in various formats including csv, xls, ods, and xlsx. You will need to ensure that you have PHP's upgraded version not older than PHP 5.2 .

How to write in Excel file using php?

We can set the value to the cell by using the setCellValueByColumnAndRow(a,b,c) function. Write the created spreadsheet using the save() function. We can set the cell value using setCellValue() function() by passing cell index name like A1, A2, D3 etc. and value.


1 Answers

The worksheet's setSelectedCells() method:

$objPHPExcel->getActiveSheet()->setSelectedCells('A1');
like image 82
Mark Baker Avatar answered Oct 13 '22 18:10

Mark Baker