zoukankan      html  css  js  c++  java
  • excel大批量导出数据&生成随机字符串

    $headArr=['姓名','身高','','位置'];//列名
    $data = [['aa',12,'b'],['bb',13,'c'],['dd',34,'e]]; //数据
    
    function exportToExcel($fileName = '', $headArr = [], $data = []){
        ini_set('memory_limit','1024M');
        ini_set('max_execution_time',0);
        ob_end_clean();
        ob_start();
        header("Content-Type: text/csv");
        header("Content-Disposition:filename=".$fileName.'.csv');
        $fp=fopen('php://output','w');
        fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));
        fputcsv($fp,$headArr);
        $index = 0;
        foreach ($data as $item) {
            if($index==1000){
                $index=0;
                ob_flush();
                flush();
            }
            $index++;
            fputcsv($fp,$item);
        }
        ob_flush();
        flush();
        ob_end_clean();
        exit();
    }
    

      2.生成随机字符串

    function bing_rand($length = 32, $char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
        if(!is_int($length) || $length < 0) {
            return false;
        }
        $string = '';
        for($i = $length; $i > 0; $i--) {
            $string .= $char[mt_rand(0, strlen($char) - 1)];
        }
        return $string;
    }
  • 相关阅读:
    PAT 1059. Prime Factors
    PAT 1058. A+B in Hogwarts
    关于树状数组
    PAT 1057. Stack
    PAT 1056. Mice and Rice
    PAT 1055. The World's Richest
    PAT 1054. The Dominant Color
    fft_filter  designed to filter gridded data in an a
    matlab 1 yr oscillations
    RMVANNUAL
  • 原文地址:https://www.cnblogs.com/bing2017/p/14293839.html
Copyright © 2011-2022 走看看