将表内容导出到xlsx文件

时间:2014-07-04 11:44:43

标签: php excel

我允许用户允许上传xlsx文件,执行音译(阿拉伯语到英语)并在网页上显示为表格内容。 (与xlsx文件相同的视图)。

  1. 我可以将表格内容导出到xlsx吗? (细胞含量应保持其细胞位置)
  2. 或者是否可以将每个进程单元格结果写入xlsx?
  3. 以下是代码:

    if (isset($_FILES['file'])) {
        header('Content-Type: text/html; charset=UTF-8');
        require_once "simplexlsx.class.php";
        require '../../Arabic.php';
        $Arabic = new I18N_Arabic('Transliteration');
        $xlsx = new SimpleXLSX( $_FILES['file']['tmp_name'] );
        echo '<h1>Parsing Result</h1>';
        echo '<table border="1" cellpadding="3" style="border-collapse: collapse">';
        $eng = array();
        list($cols,) = $xlsx->dimension();  
        foreach( $xlsx->rows() as $k => $r) {
    //      if ($k == 0) continue; // skip first row
            echo '<tr>';
            for( $i = 0; $i < $cols; $i++)
            {   
                $temp =  $Arabic->ar2en($r[$i]);    
                echo '<td>'.( (isset($r[$i])) ? $temp : '&nbsp;' ).'</td>';
            }
            echo '</tr>';
        }
        echo '</table>';
    }
    ?>
    <h1>Upload</h1>
    <form method="post" enctype="multipart/form-data">
    *.XLSX <input type="file" name="file"  />&nbsp;&nbsp;<input type="submit" value="Parse" />
    </form>
    

1 个答案:

答案 0 :(得分:0)

查看PHPExcel库。这是一个非常复杂的库,用于处理Excel文档,您应该能够实现您的目标。我不知道直接导出html表,但是应该很容易在这个库中编写一个简单的方法来进行转换。