这里我们是介绍利用php的fgetcsv函数直接来读取.csv文件了,并不是真正的excel文件,如果要读取真正的excel文件我们需要使用插件了,下面我会简单介绍一下.
excel文件(.csv),代码如下:
<?php function getCSVdata($filename) { $row = 1;//第一行开始 if(($handle = fopen($filename, "r")) !== false) { while(($dataSrc = fgetcsv($handle)) !== false) { $num = count($dataSrc); for ($c=0; $c < $num; $c++)//列 column { if($row === 1)//第一行作为字段 { $dataName[] = $dataSrc[$c];//字段名称 } else { foreach ($dataName as $k=>$v) { if($k == $c)//对应的字段 { $data[$v] = $dataSrc[$c]; } } } } if(!emptyempty($data)) { $dataRtn[] = $data; unset($data); } $row++; } fclose($handle); return $dataRtn; } } $aData = getCSVdata('all_.csv'); foreach ($aData as $k=>$v ){ echo "http://".$v['a']."<br>"; }
生成excel文件(csv),代码如下:
<?php header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=test_data.xls"); //输出内容如下: echo "姓名"."t"; echo "年龄"."t"; echo "学历"."t"; echo "n"; echo "张三"."t"; echo "25"."t"; echo "本科"."t";
上面只是简单的一些excel文件操作,如果说进行如编辑,修改,删除行表格操作我们可使用phpexcel插件来操作excel文件了.
教程地址:
欢迎转载!但请带上文章地址^^

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

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

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
