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?
The setBold() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the boldness of the text.
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');
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 .
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.
The worksheet's setSelectedCells() method:
$objPHPExcel->getActiveSheet()->setSelectedCells('A1');
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