如何修复“标签”在Excel导出(PHP)? [英] How to fix "tabs" in Excel Export (PHP)?

查看:125
本文介绍了如何修复“标签”在Excel导出(PHP)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我申请了这个解决方案来解决一个编码问题,我将文件导出到.CSV和Excel,并且它成功工作,但现在出现了另一个问题:

I applied this solution to solve an encoding problem I got exporting files to .CSV and Excel and it worked successfully, but now another problem emerged:

标签(\t)我在PHP中使用停止工作的Excel文件的分隔符。在我解决以前的问题之前,这是工作。当我打开excel文件时,它显示如下:

The tabs ("\t") I use in PHP as the delimiter for Excel files stopped working. It was working before I solve the previous problem. When I open the excel file, it display likes:


ColumnAColumbBColumnC(all together)。

"ColumnAColumbBColumnC" (all together).

如果导出它像csv ('Content-type:text / csv; charset = UTF-8')我有成功,但不是Excel( Content-type:application / vnd.ms-excel; charset = UTF-8 )。

If a export it like csv ('Content-type: text/csv; charset=UTF-8') I have success, but not as Excel (Content-type: application/vnd.ms-excel; charset=UTF-8).

任何解决方案?

注意:使用,作为分隔符对我来说不是一个好的解决方案,因为我有值 在某些领域。

Note: using "," as a separator is not a good solution for me, because I have values with "," in some fields.

推荐答案

我在PHP中使用的选项卡(\t)作为Excel文件的分隔符停止

The tabs ("\t") I use in PHP as the delimiter for Excel files stopped working.

是的,这是正确的。

尽管这仍然是一种简单的导出到Excel的方法。

Despite this there is still a simple way to export to Excel.

使用< td> < tr> ,这样做不错。

一个例子:

<?php
    header("Content-Type: text/plain");
    echo "<table border='1'>";
    echo "<tr>";
    echo "<th>Name</th>";
    echo "<th>First Name</th>";
    echo "<th>Department</th>";
    echo "<th>Date</th>";
    echo "<th>Topic</th>";
    echo "<th>State</th>";
    echo "<th>E-mail</th>";
    echo "<th>Place</th>";
    echo "<th>Registration fee</th>";
    echo '</tr>';
    echo '</table>';
    header("Content-disposition: attachment; filename=example_export_to_excel.xls");
    }
?>

这非常适合导出到excel。
没有库需要,为什么看起来很简单的东西就可以了。

This works perfectly for export to excel. There are no libraries needed, why look complicated things simple as it can.

这篇关于如何修复“标签”在Excel导出(PHP)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆