The underlying PHP library lets you set the widths on the exported columns. It would be nice to expose that through the Drupal module as well. Similar to how the Views Data Export module does it. The widths are set to auto so they expand to the widest content in a column.

Comments

minorOffense created an issue. See original summary.

MorinLuc0’s picture

Status: Active » Closed (works as designed)

This can be achieved by using the following hook and code.

/**
 * Implements hook_phpexcel_export().
 */
function HOOK_phpexcel_export($op, &$data, &$phpexcel, $options, $column = NULL, $row = NULL) {
  switch($op) {
    case 'headers':
      $column_dimensions = $phpexcel->getSheet()->getColumnDimensions();
      if (!empty($column_dimensions)) {
        foreach ($column_dimensions as $col => $col_dim) {
          // Set the autosize to true on the columns.
          $col_dim->setAutoSize(true);
        }
      }
      // Refresh the column dimensions.
      $phpexcel->getSheet()->refreshColumnDimensions();
      break;
  }
}