<?php

/**
 * luffy丶大叔 
 * <><><><><><><><><><><><><>有妹子加微信不哦！~<><><><><><><><><><><><><><><><>
 * @Author: luffy丶大叔 
 * @Z 2015-5-11 13:58:32
 * @email luffy00789@126.com
 * @encoding UTF-8
 */
class CreateTable {
    public static $cacheTemp;
    
    /**
     * 写八一行数据
     * @param type $rowArray
     * @throws Exception
     */
    public static function writeRow($rowArray = array()) {
        if(empty($rowArray)){
            throw new Exception("Data is empty！");
        }else{
            self::$cacheTemp    .= self::setLineStart();
            foreach ($rowArray as $column) {
                self::$cacheTemp    .= self::setCell($column);
            }    
            self::$cacheTemp    .= self::setLineEnd();
        }
    }
    
    
    public static function save($attr = '') {   
        $cacheTemp = self::setStart($attr) . self::$cacheTemp .self::setEnd();    
        self::$cacheTemp = '';
        return  $cacheTemp;
    }

    /**
     * 
     * @return string
     */
    public static function setEnd() {
        return "</table>";
    }
    /**
     * <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     * @return string
     */
    public static function setStart($attr = '') {
        return '<table '. $attr .'>';
    }
    /**
     * 
     * @param type $pValue
     * @param style 文本：vnd.ms-excel.numberformat:@ vnd.ms-excel.numberformat:yyyy/mm/dd vnd.ms-excel.numberformat:#,##0.00 vnd.ms-excel.numberformat:￥#,##0.00 vnd.ms-excel.numberformat: #0.00% 
     * @return type
     */
    public static function setCell($pValue, $style = ""){
        return "<td style='{$style}'>{$pValue}</td>";
    }
    /**
     * 
     * @return string
     */
    public static function setLineStart() {
        return "<tr>";
    }
    /**
     * 
     * @return string
     */
    public static function setLineEnd() {
        return "</tr>";
    }
}