cvs: pear /Spreadsheet_Excel_Writer Writer.php

From: Date: Wed, 01 Oct 2003 13:05:53 +0000
Subject: cvs: pear /Spreadsheet_Excel_Writer Writer.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-13216@lists.php.net to get a copy of this message
xnoguer Wed Oct 1 09:05:53 2003 EDT Modified files: /pear/Spreadsheet_Excel_Writer Writer.php Log: adding rowcolToCell() (JT Hughes) Index: pear/Spreadsheet_Excel_Writer/Writer.php diff -u pear/Spreadsheet_Excel_Writer/Writer.php:1.7 pear/Spreadsheet_Excel_Writer/Writer.php:1.8 --- pear/Spreadsheet_Excel_Writer/Writer.php:1.7 Mon Mar 17 19:17:36 2003 +++ pear/Spreadsheet_Excel_Writer/Writer.php Wed Oct 1 09:05:52 2003 @@ -71,5 +71,34 @@ header("Pragma: public"); } + /** + * Utility function for writing formulas + * Converts a cell's coordinates to the A1 format. + * + * @access public + * @static + * @param integer $row Row for the cell to convert (0-indexed). + * @param integer $col Column for the cell to convert (0-indexed). + * @return string The cell identifier in A1 format + */ + function rowcolToCell($row, $col) + { + if ($col > 255) { //maximum column value exceeded + return new PEAR_Error("Maximum column value exceeded: $col"); + } + + $int = (int)($col / 26); + $frac = $col % 26; + $chr1 = ''; + + if ($int > 0) { + $chr1 = chr(ord('A') + $int - 1); + } + + $chr2 = chr(ord('A') + $frac); + $row++; + + return $chr1.$chr2.$row; + } } ?>

« previous php.pear.cvs (#13216) next »