setWidth in html?

Topics: Developer Forum, User Forum
Oct 1, 2010 at 12:45 PM
Edited Oct 1, 2010 at 12:46 PM

PHP version: 5.3
phpExcel version: 1.7.4

I currently have the following code:

foreach($headers as $key => $value)
{
$sheet = $objPHPExcel->getActiveSheet();
$cell = $objPHPExcel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($key, 1, $value, true);
$sheet->getStyle($cell->getCoordinate())->applyFromArray(array('borders'=>$borders));
$sheet->getStyle($cell->getCoordinate())->getFont()->getColor()->applyFromArray( array('rgb' => 'FFFFFF') );
$sheet->getStyle($cell->getCoordinate())->getFill()->applyFromArray(array('color' => array('rgb' => '000000'), 'type' => PHPExcel_Style_Fill::FILL_SOLID) );
$sheet->getColumnDimension($cell->getColumn())->setAutoSize(false);
$sheet->getColumnDimension($cell->getColumn())->setWidth(100);
}

The problem is, that when i change the width of the coloumn it changes in the right way in Excel, but when I try to change the size of the column and output it to html, the columnwidth is always the same (as small as possible). I've tried to setAutoSize both true and false with the same result (tested in several browsers).

Later on in my code i create a html-writer and writes the CSS to the page.

Am I doing it wrong or is setting the width in html simply not supported? - I know I could just make my own css to get around it, but I think it ruins some of the smartness of phpExcel.

regards, 

   Esben

Coordinator
Oct 1, 2010 at 3:05 PM

I've just tried the following:

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(50);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(40);

with the resulting css

table.sheet0 col.col0 { width:142.3333317pt }
table.sheet0 col.col1 { width:237.2222195pt }
table.sheet0 col.col2 { width:27.78888857pt }
table.sheet0 col.col3 { width:189.7777756pt }

and html

  <col class="col0">
  <col class="col1">
  <col class="col2">
  <col class="col3">
  <tbody>
      <tr class="row0">
          <td class="column0 style0 s">Thank</td>
          <td class="column1 style0 s">God</td>
          <td class="column2 style0 s">it's</td>
          <td class="column3 style0 s">Friday</td>
      </tr>
  </tbody>

which is what I'd expect to see.

Can you check the html source for your output, and see if it contains similar css and html table entries?

Oct 1, 2010 at 3:19 PM

Yes, i have both the CSS and the html.

We've been looking into it and by the looks of it, it seems to relate to the way, the table behaves in css/html. We expected the table to show in the full width (the css says est. 475pt wide per column), but the table does not want to expand beyond the width of the screen (without specifying the exact size the table should be).

Our solution to this, is to calculate the total width of the columns and then make a div around the table with the width set to the total width of all the columns  (which will expand the table beyond the width of the screen). This is (most likely) not the prettiest solution, but it works. 

Is it somehow possible to mark this as solved to close the thread?

Coordinator
Oct 1, 2010 at 4:00 PM
esbenboye wrote:

Our solution to this, is to calculate the total width of the columns and then make a div around the table with the width set to the total width of all the columns  (which will expand the table beyond the width of the screen). This is (most likely) not the prettiest solution, but it works. 

Not really practical I'm afraid, because of the way different browser handle hidden columns: IE5.5-IE7 only hide columns, but still leave the space that they would occupy; Safari, Chrome and Opera (prior to 10.5) don't hide the hidden columns at all, while most other browsers correctly support collapsing columns... all of which result in differing sizes for the table width.

esbenboye wrote:

Is it somehow possible to mark this as solved to close the thread?

Discussion threads can't be closed, only Work Items