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);


  • 相关阅读:
    [Luogu P4779] 单源最短路径(标准版)
    [Luogu P1659] 拉拉队排练
    [Luogu P3435] OKR-Periods of Words
    [Poj #2127] Greatest Common Increasing Subsequence
    [Poj #2019] Cornfields
    [Poj #1949] Chores
    关于我
    划水记录
    [AGC006C] Rabbit Exercise
    [AGC007C] Pushing Balls
  • 原文地址:https://www.cnblogs.com/shaoyang0123/p/13140826.html
Copyright © 2011-2022 走看看