put value into last empty cell in specific column?

Topics: Developer Forum, User Forum
Oct 6, 2012 at 1:08 PM

hi guys, using me of this piece of code...(love it)

<?php
error_reporting(E_ALL);
require_once '../misc/Classes/PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load("table.xls");
$objWorksheet = $objPHPExcel->getActiveSheet();
$column = 'A';
$lastRow = $objWorksheet->getHighestRow();
for ($row = 1; $row <= $lastRow; $row++) {
    echo '<tr><td>' .
         $objWorksheet->getCell($column . $row)->getValue() .
         ',</td></tr>';
}

?>

($column . $row) contains the last empty cell in specific column, i want to write a value from this variable: $stock[2] wich includes some numbers and put them to ($column . $row).

and one more thing.... i have difficult to understand how to read dates using the code on top..  dates like "2003-01-01"  becomes "37622"

 

thanks for reply!

Coordinator
Oct 7, 2012 at 9:40 AM
zalasander wrote:

($column . $row) contains the last empty cell in specific column, i want to write a value from this variable: $stock[2] wich includes some numbers and put them to ($column . $row).


Then you want to use the setValue() method for the cell object.

 

zalasander wrote:

and one more thing.... i have difficult to understand how to read dates using the code on top.. dates like "2003-01-01" becomes "37622"


Excel stores dates as a number like this: then uses a number format mask to translate it to a date format. Either use getFormattedValue() to read dates formatted as the human-readable string displayed by Excel; or use the helper methods in the PHPExcel_Shared_Date to convert either to a PHP/unix datetimestamp, or a PHP DateTime object and then format it using the appropriate PHP date formatting functions/methods