•  0
    PHP

    Read excel file and display in html using PHP and PHPExcel library

      Admin     7999        0        Report content

    $inputFileName = 'upload/'.$_POST['filename'];
        //  Read your Excel workbook
        try {
            $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
            $objReader = PHPExcel_IOFactory::createReader($inputFileType);
            $objPHPExcel = $objReader->load($inputFileName);
        } catch (Exception $e) {
            die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) 
            . '": ' . $e->getMessage());
        }
        //  Get worksheet dimensions
        $sheet = $objPHPExcel->getSheet(0);
        $highestRow = $sheet->getHighestRow();
        $highestColumn = $sheet->getHighestColumn();
        $str = '';
        //  Loop through each row of the worksheet in turn
        for ($row = 1; $row <= $highestRow; $row++) {
            //  Read a row of data into an array
            $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, 
            NULL, TRUE, FALSE);
            $even = $row%2==0? "class='even'":"";
            $str .= '';
            foreach($rowData[0] as $k=>$v){
                //echo "Row: ".$row."- Col: ".($k+1)." = ".$v."
    "; //$data[$row][$k+1][] = $v; if($row == 1){ $str .= ''; } else { $str .= ''; } } $str .= ''; } $str .= '
    '.$v.''.$v.'
    '; echo $str; }

     

     


  •  


Leave a Comment

Please Login to insert comment.

 

Facebook Conversations