Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.4

Bug #2346 SetColumn - Format not set
Submitted: 2004-09-16 01:57 UTC
From: derrickbtan dot lists at gmail dot com Assigned:
Status: No Feedback Package: Spreadsheet_Excel_Writer
PHP Version: 5.0.1 OS: Windows 2000
Roadmaps: (Not assigned)    
Subscription  


 [2004-09-16 01:57 UTC] derrickbtan dot lists at gmail dot com
Description: ------------ Spreadsheet_Excel_Writer 0.8 OLE 0.5 The sample code provided is a just a little bit of the data I want to write, but it should be enough to reproduce the problem. I have tried putting the setcolumns and format call before the data is written as well (the sample code tries formatting after). Reproduce code: --------------- $empName = $emp->getEmployeeName(); $reportDate = date( "Y/m/d", $rep->getReportDate() ); $ws = $this->xls->addWorkSheet( "$empName - $reportDate" ); // Write the data $col = 0; $row = 0; // Print the date (A1) $ws->write( $row, $col++, $this->configArray['l_date'] ); $ws->write( $row++, $col--, $reportDate ); // Print the division (A2) $ws->write( $row, $col++, $this->configArray['l_division'] ); $ws->write( $row++, $col--, $div->getName() ); /////////////// // . . . ////////////// // Data format $this->format['data'] = $this->xls->addFormat( array( 'size' => 10, 'align' => 'right' ) ); ////////////// // Set column $ws->setColumn( 0, 2, 20, $this->format['data'] ); Expected result: ---------------- In the example provided, I would expect all alignment to be down the right side of the columns 0-2 with the column width set to 20. Actual result: -------------- The width is ok, but the format does not occur.

Comments

 [2004-09-16 02:04 UTC] derrickbtan dot lists at gmail dot com
different email.
 [2005-01-06 15:25 UTC] ohrmann
Hello, your replace code sucks, because nobody can't do a copy and paste for an easy testing. If you did look at the code of the Worksheet::setColumn() function, then you would recognize that this feature isn't implemented until now. To solve your Problem you have to give the format to each write command as shown in the following: <?php require_once 'Spreadsheet/Excel/Writer.php'; $xls =& new Spreadsheet_Excel_Writer('Test_Bug_2346.xls'); $empName = 'Test'; $reportDate = date( "Y/m/d", time() ); $ws =& $xls->addWorkSheet( "$empName - $reportDate" ); // Data format $format =& $xls->addFormat(array( 'size' => 10, 'Align' => 'right')); ////////////// // Write the data $col = 0; $row = 0; // Print the date (A1) $ws->write( $row, $col++, 'Date:', $format); $ws->write( $row++, $col--, $reportDate, $format); // Print the division (A2) $ws->write( $row, $col++, 'Division', $format); $ws->write( $row++, $col--, 'Big Boss', $format); // Set column $ws->setColumn( 0, 2, 20, $format); $xls->close(); ?> But the main point is the use of the "=&" for the returning of the addWorksheet() function.
 [2005-06-28 05:05 UTC] g at funk dot com
the version is 5.0.1, meaning that the object model shouldn't require the &.
 [2005-08-23 14:24 UTC] daniel dot chafen at virgin dot no dot spam
Seting the format works but it is reset if any data is added using the write or writeFormula even when no format attribute is used. It is very frustrating to have to keep adding the format with every write command.
 [2005-11-08 13:33 UTC] xnoguer at php dot net
sample code can't work, so I'm putting this in feedback status until provided a proper sample code.
 [2008-06-12 08:54 UTC] jkoenig (Jane Koenig)
Hello! I'm providing sample code. Hopefully, its proper. <?php require_once("Spreadsheet/Excel/Writer.php"); $xls_wbk =& new Spreadsheet_Excel_Writer(); $xls_wbk->setVersion(8); // use excel97/2000 format $xls_wbk->send( 'setColumn_'.date('dmYHis',time()).'.xls' ); $xls_wst =& $xls_wbk->addWorksheet('setColumn'); //def cell format $cf_sumc =& $xls_wbk->addFormat(); $cf_sumc->setFgColor('green'); $cf_sumc->setBold(); $cf_sumc->setNumFormat(2); $cf_test =& $xls_wbk->addFormat(array('NumFormat' => 1, 'FgColor' => 'red')); $xls_wst->setColumn(0,0,40,$cf_test); $int_row = 0; //row counter $int_col = 0; //col counter $int_number = 71010080115000000; for ( $int_row=0; $int_row < 10; $int_row += 1) { $xls_wst->write($int_row,0,$int_number); } $xls_wst->write(0,1,"Hello, I'am text"); $xls_wst->setColumn(0,0,40,$cf_sumc); $xls_wbk->close(); ?> I would be happy to get help for the problem - use setColumn together with $format parameter. kind regards
 [2008-06-12 09:02 UTC] jkoenig (Jane Koenig)
Hello! I'm providing sample code for the described problem. <?php require_once("../../PEAR/Spreadsheet/Excel/Writer.php"); $xls_wbk =& new Spreadsheet_Excel_Writer(); $xls_wbk->setVersion(8); // use excel97/2000 format $xls_wbk->send( 'setColumn_'.date('dmYHis',time()).'.xls' ); $xls_wst =& $xls_wbk->addWorksheet('setColumn'); //def cell format $cf_sumc =& $xls_wbk->addFormat(); $cf_sumc->setFgColor('green'); $cf_sumc->setBold(); $cf_sumc->setNumFormat(2); $cf_test =& $xls_wbk->addFormat(array('NumFormat' => 1, 'FgColor' => 'red')); $xls_wst->setColumn(0,0,40,$cf_test); $int_row = 0; //row counter $int_col = 0; //col counter $int_number = 71010080115000000; for ( $int_row=0; $int_row < 10; $int_row += 1) { $xls_wst->write($int_row,0,$int_number); } $xls_wst->write(0,1,"Hello, I'am text"); //$xls_wst->setColumn(0,0,40,$cf_test); $xls_wst->setColumn(0,0,40,$cf_sumc); $xls_wbk->close(); ?> I would be happy to get setColumn with $format parameter working. kind regards