使用php创建.xls文件 [英] create .xls file using php

查看:68
本文介绍了使用php创建.xls文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的:

   $sep = "\t";        //tabbed character
    $fp = fopen('registrars.xls', "w");

$schema_insert_rows = "";
//printing column names 

        $schema_insert_rows.="#" . $sep;
        $schema_insert_rows.="Registrar" . $sep;
        $schema_insert_rows.="Country" . $sep;
        $schema_insert_rows.="Website" . $sep;
        //$schema_insert_rows.="Postal Address" . $sep;
        //$schema_insert_rows.="Contact Number" . $sep;
        $schema_insert_rows.="Email Address" . $sep;

        $schema_insert_rows.="\n";
        fwrite($fp, $schema_insert_rows);

// printing data:
    $row = 0; $i = 0; $schema_insert_rows = "";

        $schema_insert_rows .= (++$row) . "" . $sep;
        $schema_insert_rows .= $registrarArr[$i] . "" . $sep;
        $schema_insert_rows .= $registrarArr[$i+1] . "" . $sep;
        $schema_insert_rows .= $linkArr[$i] . "" . $sep;
        $schema_insert_rows .= (string)(strip_tags($address)) . "" . $sep;
        $schema_insert_rows .= (string)(strip_tags($phone)). "" . $sep;
        $schema_insert_rows .= "email test";

        $schema_insert_rows .= "\n";



fwrite($fp, $schema_insert_rows);

fclose($fp);

另一列工作正常,但我注释掉的列不起作用[用于邮政地址和电子邮件地址].我删除了注释,尽管该数据应该在同一行,但数据将转到下一行与其他行一样..我通过var_dump检查是否存在<br>但什么都没有..这是怎么回事?

The other column works fine but the ones i commented out are not working [for postal address and email address].. I i get rid of the comments, the data will go to the next row though it should be on the same row as the others.. I checked via var_dump to see if there's < br> but there's none.. What's wrong here?

推荐答案

我使用了 PHPExcel 在一个客户项目上取得了良好的效果.它可以生成Microsoft Excel,Open Excel和PDF文档.

I've used PHPExcel on a client project with good results. It can generate Microsoft Excel, Open Excel and PDF documents.

您可能会发现CSV限制文件格式.

You might find the file format CSV limiting.

更新但尚未稳定的项目是 PhpSpreadsheet .它还支持更多格式.

The newer, but not yet stable project is PhpSpreadsheet. It also supports more formats.

这篇关于使用php创建.xls文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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