Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

朱继来 / 后台订单管理

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • Order
  • ..
  • Reader
  • HTML.php
HTML.php 20.8 KB
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
1 2
<?php

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
3 4 5 6 7 8 9 10
if (!defined('PHPEXCEL_ROOT')) {
    /**
     * @ignore
     */
    define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
    require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}

叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
11
/**
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
12
 * PHPExcel_Reader_HTML
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
13
 *
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
14
 * Copyright (c) 2006 - 2015 PHPExcel
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPExcel
 * @package    PHPExcel_Reader
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
32 33
 * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
34 35 36 37 38 39 40 41 42 43 44
 * @version    ##VERSION##, ##DATE##
 */
/** PHPExcel root directory */
class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
{

    /**
     * Input encoding
     *
     * @var string
     */
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
45
    protected $inputEncoding = 'ANSI';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
46 47 48 49 50 51

    /**
     * Sheet index to read
     *
     * @var int
     */
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
52
    protected $sheetIndex = 0;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
53 54 55 56 57 58

    /**
     * Formats
     *
     * @var array
     */
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
59 60 61 62
    protected $formats = array(
        'h1' => array(
            'font' => array(
                'bold' => true,
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
63 64
                'size' => 24,
            ),
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
65 66 67 68
        ), //    Bold, 24pt
        'h2' => array(
            'font' => array(
                'bold' => true,
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
69 70
                'size' => 18,
            ),
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
71 72 73 74
        ), //    Bold, 18pt
        'h3' => array(
            'font' => array(
                'bold' => true,
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
75 76
                'size' => 13.5,
            ),
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
77 78 79 80
        ), //    Bold, 13.5pt
        'h4' => array(
            'font' => array(
                'bold' => true,
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
81 82
                'size' => 12,
            ),
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
83 84 85 86
        ), //    Bold, 12pt
        'h5' => array(
            'font' => array(
                'bold' => true,
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
87 88
                'size' => 10,
            ),
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
89 90 91 92
        ), //    Bold, 10pt
        'h6' => array(
            'font' => array(
                'bold' => true,
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
93 94
                'size' => 7.5,
            ),
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
95 96 97 98 99 100
        ), //    Bold, 7.5pt
        'a' => array(
            'font' => array(
                'underline' => true,
                'color' => array(
                    'argb' => PHPExcel_Style_Color::COLOR_BLUE,
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
101 102
                ),
            ),
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
103 104 105 106 107 108 109
        ), //    Blue underlined
        'hr' => array(
            'borders' => array(
                'bottom' => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN,
                    'color' => array(
                        PHPExcel_Style_Color::COLOR_BLACK,
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
110 111 112
                    ),
                ),
            ),
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
113
        ), //    Bottom border
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
114 115 116 117 118 119 120 121 122
    );

    protected $rowspan = array();

    /**
     * Create a new PHPExcel_Reader_HTML
     */
    public function __construct()
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
123
        $this->readFilter = new PHPExcel_Reader_DefaultReadFilter();
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
124 125 126 127 128 129 130
    }

    /**
     * Validate that the current file is an HTML file
     *
     * @return boolean
     */
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
131
    protected function isValidFormat()
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
132
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
133 134 135
        //    Reading 2048 bytes should be enough to validate that the format is HTML
        $data = fread($this->fileHandle, 2048);
        if ((strpos($data, '<') !== false) &&
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
136
                (strlen($data) !== strlen(strip_tags($data)))) {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
137
            return true;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
138 139
        }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
140
        return false;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    }

    /**
     * Loads PHPExcel from file
     *
     * @param  string                    $pFilename
     * @return PHPExcel
     * @throws PHPExcel_Reader_Exception
     */
    public function load($pFilename)
    {
        // Create new PHPExcel
        $objPHPExcel = new PHPExcel();

        // Load into this instance
        return $this->loadIntoExisting($pFilename, $objPHPExcel);
    }

    /**
     * Set input encoding
     *
     * @param string $pValue Input encoding
     */
    public function setInputEncoding($pValue = 'ANSI')
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
166
        $this->inputEncoding = $pValue;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
167 168 169 170 171 172 173 174 175 176 177

        return $this;
    }

    /**
     * Get input encoding
     *
     * @return string
     */
    public function getInputEncoding()
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
178
        return $this->inputEncoding;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
179 180
    }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
181 182 183 184
    //    Data Array used for testing only, should write to PHPExcel object on completion of tests
    protected $dataArray = array();
    protected $tableLevel = 0;
    protected $nestedColumn = array('A');
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
185

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
186
    protected function setTableStartColumn($column)
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
187
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
188
        if ($this->tableLevel == 0) {
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
189
            $column = 'A';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
190 191 192
        }
        ++$this->tableLevel;
        $this->nestedColumn[$this->tableLevel] = $column;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
193

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
194
        return $this->nestedColumn[$this->tableLevel];
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
195 196
    }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
197
    protected function getTableStartColumn()
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
198
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
199
        return $this->nestedColumn[$this->tableLevel];
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
200 201
    }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
202
    protected function releaseTableStartColumn()
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
203
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
204
        --$this->tableLevel;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
205

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
206
        return array_pop($this->nestedColumn);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
207 208
    }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
209
    protected function flushCell($sheet, $column, $row, &$cellContent)
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
210 211
    {
        if (is_string($cellContent)) {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
212
            //    Simple String content
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
213
            if (trim($cellContent) > '') {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
214 215 216 217
                //    Only actually write it if there's content in the string
//                echo 'FLUSH CELL: ' , $column , $row , ' => ' , $cellContent , '<br />';
                //    Write to worksheet to be done here...
                //    ... we return the cell so we can mess about with styles more easily
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
218
                $sheet->setCellValue($column . $row, $cellContent, true);
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
219
                $this->dataArray[$row][$column] = $cellContent;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
220 221
            }
        } else {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
222 223 224
            //    We have a Rich Text run
            //    TODO
            $this->dataArray[$row][$column] = 'RICH TEXT: ' . $cellContent;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
225 226 227 228
        }
        $cellContent = (string) '';
    }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
229
    protected function processDomElement(DOMNode $element, $sheet, &$row, &$column, &$cellContent, $format = null)
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
230 231 232 233 234
    {
        foreach ($element->childNodes as $child) {
            if ($child instanceof DOMText) {
                $domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue));
                if (is_string($cellContent)) {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
235
                    //    simply append the text if the cell content is a plain text string
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
236 237
                    $cellContent .= $domText;
                } else {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
238 239
                    //    but if we have a rich text run instead, we need to append it correctly
                    //    TODO
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
240 241
                }
            } elseif ($child instanceof DOMElement) {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
242
//                echo '<b>DOM ELEMENT: </b>' , strtoupper($child->nodeName) , '<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
243 244 245

                $attributeArray = array();
                foreach ($child->attributes as $attribute) {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
246
//                    echo '<b>ATTRIBUTE: </b>' , $attribute->name , ' => ' , $attribute->value , '<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
247 248 249 250
                    $attributeArray[$attribute->name] = $attribute->value;
                }

                switch ($child->nodeName) {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
251
                    case 'meta':
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
252 253 254
                        foreach ($attributeArray as $attributeName => $attributeValue) {
                            switch ($attributeName) {
                                case 'content':
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
255 256
                                    //    TODO
                                    //    Extract character set, so we can convert to UTF-8 if required
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
257 258 259
                                    break;
                            }
                        }
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
260
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
261
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
262 263
                    case 'title':
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
264 265 266
                        $sheet->setTitle($cellContent);
                        $cellContent = '';
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
267 268 269 270 271
                    case 'span':
                    case 'div':
                    case 'font':
                    case 'i':
                    case 'em':
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
272
                    case 'strong':
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
273 274 275
                    case 'b':
//                        echo 'STYLING, SPAN OR DIV<br />';
                        if ($cellContent > '') {
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
276
                            $cellContent .= ' ';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
277 278 279
                        }
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
                        if ($cellContent > '') {
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
280
                            $cellContent .= ' ';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
281 282
                        }
//                        echo 'END OF STYLING, SPAN OR DIV<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
283
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
284 285
                    case 'hr':
                        $this->flushCell($sheet, $column, $row, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
286
                        ++$row;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
287 288
                        if (isset($this->formats[$child->nodeName])) {
                            $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
289 290
                        } else {
                            $cellContent = '----------';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
291
                            $this->flushCell($sheet, $column, $row, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
292 293
                        }
                        ++$row;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
294 295 296 297
                        // Add a break after a horizontal rule, simply by allowing the code to dropthru
                    case 'br':
                        if ($this->tableLevel > 0) {
                            //    If we're inside a table, replace with a \n
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
298 299
                            $cellContent .= "\n";
                        } else {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
300 301
                            //    Otherwise flush our existing content and move the row cursor on
                            $this->flushCell($sheet, $column, $row, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
302 303
                            ++$row;
                        }
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
304
//                        echo 'HARD LINE BREAK: ' , '<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
305
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
306 307
                    case 'a':
//                        echo 'START OF HYPERLINK: ' , '<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
308 309 310
                        foreach ($attributeArray as $attributeName => $attributeValue) {
                            switch ($attributeName) {
                                case 'href':
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
311
//                                    echo 'Link to ' , $attributeValue , '<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
312
                                    $sheet->getCell($column . $row)->getHyperlink()->setUrl($attributeValue);
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
313 314
                                    if (isset($this->formats[$child->nodeName])) {
                                        $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
315 316 317 318 319
                                    }
                                    break;
                            }
                        }
                        $cellContent .= ' ';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
320 321
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
//                        echo 'END OF HYPERLINK:' , '<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
322
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
323 324 325 326 327 328 329 330 331 332 333
                    case 'h1':
                    case 'h2':
                    case 'h3':
                    case 'h4':
                    case 'h5':
                    case 'h6':
                    case 'ol':
                    case 'ul':
                    case 'p':
                        if ($this->tableLevel > 0) {
                            //    If we're inside a table, replace with a \n
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
334
                            $cellContent .= "\n";
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
335 336 337
//                            echo 'LIST ENTRY: ' , '<br />';
                            $this->processDomElement($child, $sheet, $row, $column, $cellContent);
//                            echo 'END OF LIST ENTRY:' , '<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
338 339
                        } else {
                            if ($cellContent > '') {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
340
                                $this->flushCell($sheet, $column, $row, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
341 342
                                $row++;
                            }
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
343 344 345 346
//                            echo 'START OF PARAGRAPH: ' , '<br />';
                            $this->processDomElement($child, $sheet, $row, $column, $cellContent);
//                            echo 'END OF PARAGRAPH:' , '<br />';
                            $this->flushCell($sheet, $column, $row, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
347

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
348 349
                            if (isset($this->formats[$child->nodeName])) {
                                $sheet->getStyle($column . $row)->applyFromArray($this->formats[$child->nodeName]);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
350 351 352 353 354 355
                            }

                            $row++;
                            $column = 'A';
                        }
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
356 357 358
                    case 'li':
                        if ($this->tableLevel > 0) {
                            //    If we're inside a table, replace with a \n
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
359
                            $cellContent .= "\n";
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
360 361 362
//                            echo 'LIST ENTRY: ' , '<br />';
                            $this->processDomElement($child, $sheet, $row, $column, $cellContent);
//                            echo 'END OF LIST ENTRY:' , '<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
363 364
                        } else {
                            if ($cellContent > '') {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
365
                                $this->flushCell($sheet, $column, $row, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
366 367
                            }
                            ++$row;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
368 369 370 371
//                            echo 'LIST ENTRY: ' , '<br />';
                            $this->processDomElement($child, $sheet, $row, $column, $cellContent);
//                            echo 'END OF LIST ENTRY:' , '<br />';
                            $this->flushCell($sheet, $column, $row, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
372 373 374
                            $column = 'A';
                        }
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
375 376 377 378 379
                    case 'table':
                        $this->flushCell($sheet, $column, $row, $cellContent);
                        $column = $this->setTableStartColumn($column);
//                        echo 'START OF TABLE LEVEL ' , $this->tableLevel , '<br />';
                        if ($this->tableLevel > 1) {
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
380
                            --$row;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
381 382 383 384 385
                        }
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
//                        echo 'END OF TABLE LEVEL ' , $this->tableLevel , '<br />';
                        $column = $this->releaseTableStartColumn();
                        if ($this->tableLevel > 1) {
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
386 387 388 389 390
                            ++$column;
                        } else {
                            ++$row;
                        }
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
391 392 393
                    case 'thead':
                    case 'tbody':
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
394
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
395 396
                    case 'tr':
                        $column = $this->getTableStartColumn();
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
397
                        $cellContent = '';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
398 399
//                        echo 'START OF TABLE ' , $this->tableLevel , ' ROW<br />';
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
400
                        ++$row;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
401
//                        echo 'END OF TABLE ' , $this->tableLevel , ' ROW<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
402
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
403 404 405 406 407
                    case 'th':
                    case 'td':
//                        echo 'START OF TABLE ' , $this->tableLevel , ' CELL<br />';
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
//                        echo 'END OF TABLE ' , $this->tableLevel , ' CELL<br />';
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
408 409 410 411 412

                        while (isset($this->rowspan[$column . $row])) {
                            ++$column;
                        }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
413
                        $this->flushCell($sheet, $column, $row, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452

//                        if (isset($attributeArray['style']) && !empty($attributeArray['style'])) {
//                            $styleAry = $this->getPhpExcelStyleArray($attributeArray['style']);
//
//                            if (!empty($styleAry)) {
//                                $sheet->getStyle($column . $row)->applyFromArray($styleAry);
//                            }
//                        }

                        if (isset($attributeArray['rowspan']) && isset($attributeArray['colspan'])) {
                            //create merging rowspan and colspan
                            $columnTo = $column;
                            for ($i = 0; $i < $attributeArray['colspan'] - 1; $i++) {
                                ++$columnTo;
                            }
                            $range = $column . $row . ':' . $columnTo . ($row + $attributeArray['rowspan'] - 1);
                            foreach (\PHPExcel_Cell::extractAllCellReferencesInRange($range) as $value) {
                                $this->rowspan[$value] = true;
                            }
                            $sheet->mergeCells($range);
                            $column = $columnTo;
                        } elseif (isset($attributeArray['rowspan'])) {
                            //create merging rowspan
                            $range = $column . $row . ':' . $column . ($row + $attributeArray['rowspan'] - 1);
                            foreach (\PHPExcel_Cell::extractAllCellReferencesInRange($range) as $value) {
                                $this->rowspan[$value] = true;
                            }
                            $sheet->mergeCells($range);
                        } elseif (isset($attributeArray['colspan'])) {
                            //create merging colspan
                            $columnTo = $column;
                            for ($i = 0; $i < $attributeArray['colspan'] - 1; $i++) {
                                ++$columnTo;
                            }
                            $sheet->mergeCells($column . $row . ':' . $columnTo . $row);
                            $column = $columnTo;
                        }
                        ++$column;
                        break;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
453
                    case 'body':
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
454 455 456
                        $row = 1;
                        $column = 'A';
                        $content = '';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
457 458
                        $this->tableLevel = 0;
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
459 460
                        break;
                    default:
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
461
                        $this->processDomElement($child, $sheet, $row, $column, $cellContent);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
                }
            }
        }
    }

    /**
     * Loads PHPExcel from file into PHPExcel instance
     *
     * @param  string                    $pFilename
     * @param  PHPExcel                  $objPHPExcel
     * @return PHPExcel
     * @throws PHPExcel_Reader_Exception
     */
    public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
    {
        // Open file to validate
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
478 479 480
        $this->openFile($pFilename);
        if (!$this->isValidFormat()) {
            fclose($this->fileHandle);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
481 482
            throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file.");
        }
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
483 484
        //    Close after validating
        fclose($this->fileHandle);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
485 486

        // Create new PHPExcel
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
487
        while ($objPHPExcel->getSheetCount() <= $this->sheetIndex) {
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
488 489
            $objPHPExcel->createSheet();
        }
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
490
        $objPHPExcel->setActiveSheetIndex($this->sheetIndex);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
491

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
492
        //    Create a new DOM object
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
493
        $dom = new domDocument;
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
494 495 496 497
        //    Reload the HTML file into the DOM object
        $loaded = $dom->loadHTML(mb_convert_encoding($this->securityScanFile($pFilename), 'HTML-ENTITIES', 'UTF-8'));
        if ($loaded === false) {
            throw new PHPExcel_Reader_Exception('Failed to load ' . $pFilename . ' as a DOM Document');
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
498 499
        }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
500
        //    Discard white space
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
501 502 503 504 505
        $dom->preserveWhiteSpace = false;

        $row = 0;
        $column = 'A';
        $content = '';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
506
        $this->processDomElement($dom, $objPHPExcel->getActiveSheet(), $row, $column, $content);
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
507

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
508
        // Return
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
509 510 511 512 513 514 515 516 517 518
        return $objPHPExcel;
    }

    /**
     * Get sheet index
     *
     * @return int
     */
    public function getSheetIndex()
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
519
        return $this->sheetIndex;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
520 521 522 523 524 525 526 527 528 529
    }

    /**
     * Set sheet index
     *
     * @param  int                  $pValue Sheet index
     * @return PHPExcel_Reader_HTML
     */
    public function setSheetIndex($pValue = 0)
    {
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
530
        $this->sheetIndex = $pValue;
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
531 532 533 534

        return $this;
    }

朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
535 536 537 538 539 540 541 542
    /**
     * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks
     *
     * @param     string         $xml
     * @throws PHPExcel_Reader_Exception
     */
    public function securityScan($xml)
    {
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
543
        $pattern = '/\\0?' . implode('\\0?', str_split('<!ENTITY')) . '\\0?/';
朱继来's avatar
1. 调整明细编辑;
0b4e495b
 
朱继来 committed 5 years ago
544
        if (preg_match($pattern, $xml)) {
叶明星's avatar
账期管理
d99f4f05
 
叶明星 committed 6 years ago
545 546 547 548 549
            throw new PHPExcel_Reader_Exception('Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks');
        }
        return $xml;
    }
}