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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵