PHP code example of bean / excel

1. Go to this page and download the library: Download bean/excel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bean / excel example snippets


    use Excel/ExcelReader;
    // 实例化ExcelReader类
    $reader = new ExcelReader($realPath);
    // 粗暴的获取Excel数据
    $data = $reader->readExcel()->readSheet()->getData();
    // 也可以这样使用
    $excel = $reader->readExcel();
    $sheetNumber = $excel->sheetNumber;
    $sheetName = $excel->sheetName[0];
    $sheet = $excel->readSheet($sheetName);
    $columnCount = $sheet->column;
    $rowCount = $sheet->row;
    $data = $sheet->getData()

    $writer = new ExcelWriter();

    for ($i = 0; $i < 100; $i++){
        for ($j = 0; $j < 10; $j++){
            $data[$i][$j] = 'test ['.$i.']+['.$j.']';
        }
    }
    $writer->setWidth(range('A','J'))
        ->setValue($data)
        ->setFormat('xls')
        ->setAlignment(array('A1','C1'),'CENTER')
        ->setBackgroundColor(array('A1','C1'),'#ccccc')
        ->setAlignment(array('A2','C2'),'RIGHT')
        ->setActiveSheetName('Bean')
        ->outPut('test.xls');

    $help = new Helpers();
    if ($help->hasFile('file')){
        $file = $help->uploadFile('file');
        $fileExtension = $file->fileExtension();
        $fileName = $file->fileName();
        $fileSize = $file->fileSize();
        $fileMineType = $file->fileMineType();
    }else{
        echo '文件上传失败';
    }