zoukankan      html  css  js  c++  java
  • php导出excel

    php 5.6

    git clone https://github.com/PHPOffice/PHPExcel.git

    //导入文件
    require_once("/PHPExcel/Classes/PHPExcel.php");
    $_phpExcel = new PHPExcel();
    $_phpExcel->getProperties()->setTitle("low php excel test");
    $arr = [
    ['t1',10],
    ['t2',19],
    ];
    $sub_title = [
    ['title','age'],
    ];
    $_phpExcel->getActiveSheet()->fromArray($sub_title,null);
    $_phpExcel->getActiveSheet()->fromArray($arr,null,'A2');

    $_write = new PHPExcel_Writer_Excel2007($_phpExcel);
    $_write->save('low_php_excel.xlsx');

    **************************
    php 7.2
    git clone https://github.com/PHPOffice/PhpSpreadsheet.git
    use PhpOfficePhpSpreadsheetSpreadsheet;
    use PhpOfficePhpSpreadsheetWriterXlsx;
    $title = 'test';
    $spreadsheet = new Spreadsheet();
    $sheet = $spreadsheet->getActiveSheet();
    $sheet->setTitle($title);
    $columns=['名称','年龄'];
    $list=[["liujin",'18'],["lili",19]];
    foreach ($columns as $k=>$column) {
    $sheet->setCellValueByColumnAndRow($k+1,1,$column);
    }
    foreach ($list as $k => $item){
    foreach ($item as $j=>$v) {
    $sheet->setCellValueByColumnAndRow($j+1,$k+2,$item[$j]);
    }
    }
    $writer = new Xlsx($spreadsheet);
    $file_path = 'tmp.xlsx';
    $writer->save($file_path);


  • 相关阅读:
    Chromium(Chrome) frame structure detail
    Chromium(Chrome) Sandbox Details
    ECMA6 New Features
    Asynchronous programming in javascript
    Restful OData Protocol
    java 历年版本特征(简化)
    λ 演算学习
    远程访问其他主机的Mysql(Ubuntu)
    NoSQL基础学习
    Apache solr 6.6.0安装
  • 原文地址:https://www.cnblogs.com/shaoyang0123/p/13140826.html
Copyright © 2011-2022 走看看