CSV是(逗號分隔值)的英文縮寫,通常都是純文本文件,建議使用WORDPAD或是記事本(NOTE)來開啟,再則先另存新檔后用EXCEL開啟,也可以直接使用excel打開,和excel文件一樣.
php生成excel文件(csv)參考代碼如下:
<?php header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename= www.phprm.com test_data.xls"); //輸出內(nèi)容如下: echo "姓名"."t"; echo "年齡"."t"; echo "學歷"."t"; echo "n"; echo "張三"."t"; echo "25"."t"; echo "本科"."t";
下面這種方法是從一個項目中摘取的(只支持1997-2003),t是Tab,代碼如下:
<?php /** * 導出 Excel 表格 * */ public function excel(){ // 表示輸出的是excel文件 header("Content-type:application/vnd.ms-excel;"); // 表示輸出的文件名為lamp_dtype.xls header("Content-Disposition:filename=lamp_dtype.xls"); $exc .= "類型名稱t宿舍類別t宿舍面積t容納人數(shù)t月租/人t備注tn"; $dtype = D('dtype'); // 查詢數(shù)據(jù)庫內(nèi)的信息 $datas = $dtype->select(); // 循環(huán)輸出每條信息 foreach($datas as $data){ $exc .="{$data['name']}t{$data['type']}t{$data['area']}t{$data['capacity']}t{$data['rent']}t{$data['remark']}tn"; } // UTF-8 轉換成 GB2312 $exc =iconv("UTF-8","GB2312",$exc); echo $exc; // 避免輸出下面的內(nèi)容 exit(); }
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Guide: Stellar Blade Save File Location/Save File Lost/Not Saving
4 weeks ago
By DDD
Oguri Cap Build Guide | A Pretty Derby Musume
2 weeks ago
By Jack chen
Agnes Tachyon Build Guide | A Pretty Derby Musume
2 weeks ago
By Jack chen
Dune: Awakening - Advanced Planetologist Quest Walkthrough
4 weeks ago
By Jack chen
Date Everything: Dirk And Harper Relationship Guide
4 weeks ago
By Jack chen

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)
