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(';');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效