PHP导入和导出Excel文件
一、PHP导出Excel文件
1:第一推荐无比风骚的PHPExcel,官方网站: http://www.codeplex.com/PHPExcel
导入导出都成,可以导出office2007格式,同时兼容2003
2、使用pear的Spreadsheet_Excel_Writer类
下载地址: http://pear.php.net/package/Spreadsheet_Excel_Writer
此类依赖于OLE,下载地址:http://pear.php.net/package/OLE
需要注意的是导出的Excel文件格式比较老,修改后保存会提示是否转换成更新的格式。不过可以设定格式,很强大。
3:利用smarty,生成符合Excel规范的XML或HTML文件
支持格式,非常完美的导出方案。不过导出来的的本质上还是XML文件,如果用来导入就需要另外处理了。
详细内容请见rardge大侠的帖子:http://bbs.chinaunix.net/viewthread.php?tid=745757
需要注意的是如果导出的表格行数不确定时,最好在模板中把”ss:ExpandedColumnCount=”5″ ss:ExpandedRowCount=”21″”之类的东西删掉。
4、利用pack函数打印出模拟Excel格式的断句符号,这种更接近于Excel标准格式,用office2003修改后保存,还不会弹出提示,推荐用这种方法。缺点是无格式。
5、使用制表符、换行符的方法
制表符”\t”用户分割同一行中的列,换行符”\t\n”可以开启下一行。
6、使用com
如果你的PHP可以开启com模块,就可以用它来导出Excel文件
二、php导入excel文件
1. 以.csv格式读取
将.xls转换成.csv的文本格式,然后再用PHP分析这个文件,和PHP分析文本没有什么区别。
优点:跨平台,效率比较高、可以读写。
缺点:只能直接使用.csv的文件,如果经常接受.xls二进制文件的话需要手工转换,不能自动化。一个文件只有一个SHEET。
PHP有自带的分析.csv函数:fgetcsv
2. ODBC链接数据源
优点:支持多种格式,cvs, xls等。支持读写,使用标准SQL语言,和SQLSERVER、MYSQL数据库几乎完全一样。
缺点:值支持windows服务器
3. PHP自定义类
优点:跨平台。某些类支持写操作。支持.xls二进制文件
常用的类有phpExcelReader、PHPExcel。其中后者支持读写,但是需要php5.2以上版本。
phpExcelReader是专门用来读取文件的。返回一个数组,包含表格的所有内容。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
