展开导出的Excel的列宽

I am doing an excel export from Magento. I wish to auto resize the column. Here is my code that I tried,

public function exportOrders($orders)
{
$fileName = 'order_export_'.date("Ymd_His").'.csv';
$fp = fopen(Mage::getBaseDir('export').'/'.$fileName, 'w');

$this->writeHeadRow($fp);
foreach ($orders as $order) {
    $order = Mage::getModel('sales/order')->load($order);
    $this->writeOrder($order, $fp);
}

for($i = $fromCol; $i !== $toCol; $i++) {
    $calculatedWidth = $sheet->getColumnDimension($i)->getWidth();
    $sheet->getColumnDimension($i)->setWidth((int) $calculatedWidth * 2);
}

fclose($fp);

return $fileName;
}

It does not seem to work.

if you are using PhpExcel Library

// this extenstion using PhpExcel Lib Perfect Excel Export - Management Report then

$objPHPExcel = new PHPExcel(); $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);

hope this help you