douxun7992
2014-06-24 07:53
浏览 46
已采纳

PHPExcel csv文件的computeWorksheetDimension

I use PHPExcel to import data from a .csv file which has the same rows and columns with a excel file. Basically I open them with LibreOffice and they look the same. However there are two result when calculating theirs worksheet dimensions.

  1. csv: A1:A10
  2. xlsx: A1: AMK10

I just want to ask that it is always like that due to the different formats or I do something wrong?

$pi = pathinfo($filePath);
  switch ($pi['extension']) {
    case 'xls':
      $reader = PHPExcel_IOFactory::createReader('Excel5');
      break;
    case 'xlsx':
      $reader = PHPExcel_IOFactory::createReader('Excel2007');
      break;
    case 'csv':
      $reader = PHPExcel_IOFactory::createReader('CSV');
      break;
    default:
      return array();
  }
  $phpexcel = $reader->load($filePath);
  $sheet = $phpexcel->getActiveSheet();
  $sheet->calculateWorksheetDimension();
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongqiang8058 2014-06-24 11:31
    已采纳

    When loading a CSV file, if the delimiter isn't a default comma (,) then you need to explicitly set the delimiter for the reader. e.g.

    PHPExcel_IOFactory::createReader('CSV'); 
    $reader->setDelimiter(';');
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题