php ExcelReader 读取Excel类

 更新时间:2016年11月25日 16:39  点击:1678
这是一款开源的php代码,ExcelReader是专业地excel表进行读写操作的哦,下面我们来看一款ExcelReader读取111cn.net.xls工作表实例吧。
 代码如下 复制代码

$allow_url_override = 1; // set to 0 to not allow changed via post or get
if(!$allow_url_override || !isset($file_to_include))
{
 $file_to_include = "111cn.net.xls";
}
if(!$allow_url_override || !isset($max_rows))
{
 $max_rows = 0; //use 0 for no max
}
if(!$allow_url_override || !isset($max_cols))
{
 $max_cols = 5; //use 0 for no max
}
if(!$allow_url_override || !isset($debug))
{
 $debug = 0;  //1 for on 0 for off
}
if(!$allow_url_override || !isset($force_nobr))
{
 $force_nobr = 1;  //force the info in cells not to wrap unless stated explicitly (newline)
}

require_once 'www.111cn.net/reader.php';
$data = new spreadsheet_excel_reader();
$data->setoutputencoding('cpa25a');
$data->read($file_to_include);
error_reporting(e_all ^ e_notice);
echo "
<style>
.table_data
{
 border-style:ridge;
 border-width:1;
}
.tab_base
{
 background:#c5d0dd;
 font-weight:bold;
 border-style:ridge;
 border-width:1;
 cursor:pointer;
}
.table_sub_heading
{
 background:#cccccc;
 font-weight:bold;
 border-style:ridge;
 border-width:1;
}
.table_body
{
 background:#f0f0f0;
 font-wieght:normal;
 font-size:12;
 font-family:sans-serif;
 border-style:ridge;
 border-width:1;
 border-spacing: 0px;
 border-collaps教程e: collapse;
}
.tab_loaded
{
 background:#222222;
 color:white;
 font-weight:bold;
 border-style:groove;
 border-width:1;
 cursor:pointer;
}
</style>
";
function make_alpha_from_numbers($number)
{
 $numeric = "abcdefghijklmnopqrstuvwxyz";
 if($number<strlen($numeric))
 {
  return $numeric[$number];
 }
 else
 {
  $dev_by = floor($number/strlen($numeric));
  return "" . make_alpha_from_numbers($dev_by-1) . make_alpha_from_numbers($number-($dev_by*strlen($numeric)));
 }
}
echo "<script language='网页特效'>
var sheet_html = array(); ";
for($sheet=0;$sheet<count($data->sheets);$sheet++)
{
 $table_output[$sheet] .= "<table class='table_body'>
 <tr>
  <td>&nbsp;</td>";
 for($i=0;$i<$data->sheets[$sheet]['numcols']&&($i<=$max_cols||$max_cols==0);$i++)
 {
  $table_output[$sheet] .= "<td class='table_sub_heading' align=center>" . make_alpha_from_numbers($i) . "</td>";
 }
 for($row=1;$row<=$data->sheets[$sheet]['numrows']&&($row<=$max_rows||$max_rows==0);$row++)
 {
  $table_output[$sheet] .= "<tr><td class='table_sub_heading'>" . $row . "</td>";
  for($col=1;$col<=$data->sheets[$sheet]['numcols']&&($col<=$max_cols||$max_cols==0);$col++)
  {
   if($data->sheets[$sheet]['cellsinfo'][$row][$col]['colspan'] >=1 && $data->sheets[$sheet]['cellsinfo'][$row][$col]['rowspan'] >=1)
   {
    $this_cell_colspan = " colspan=" . $data->sheets[$sheet]['cellsinfo'][$row][$col]['colspan'];
    $this_cell_rowspan = " rowspan=" . $data->sheets[$sheet]['cellsinfo'][$row][$col]['rowspan'];
    for($i=1;$i<$data->sheets[$sheet]['cellsinfo'][$row][$col]['colspan'];$i++)
    {
     $data->sheets[$sheet]['cellsinfo'][$row][$col+$i]['dontprint']=1;
    }
    for($i=1;$i<$data->sheets[$sheet]['cellsinfo'][$row][$col]['rowspan'];$i++)
    {
     for($j=0;$j<$data->sheets[$sheet]['cellsinfo'][$row][$col]['colspan'];$j++)
     {
      $data->sheets[$sheet]['cellsinfo'][$row+$i][$col+$j]['dontprint']=1;
     }
    }
   }
   else if($data->sheets[$sheet]['cellsinfo'][$row][$col]['colspan'] >=1)
   {
    $this_cell_colspan = " colspan=" . $data->sheets[$sheet]['cellsinfo'][$row][$col]['colspan'];
    $this_cell_rowspan = "";
    for($i=1;$i<$data->sheets[$sheet]['cellsinfo'][$row][$col]['colspan'];$i++)
    {
     $data->sheets[$sheet]['cellsinfo'][$row][$col+$i]['dontprint']=1;
    }
   }
   else if($data->sheets[$sheet]['cellsinfo'][$row][$col]['rowspan'] >=1)
   {
    $this_cell_colspan = "";
    $this_cell_rowspan = " rowspan=" . $data->sheets[$sheet]['cellsinfo'][$row][$col]['rowspan'];
    for($i=1;$i<$data->sheets[$sheet]['cellsinfo'][$row][$col]['rowspan'];$i++)
    {
     $data->sheets[$sheet]['cellsinfo'][$row+$i][$col]['dontprint']=1;
    }
   }
   else
   {
    $this_cell_colspan = "";
    $this_cell_rowspan = "";
   }
   if(!($data->sheets[$sheet]['cellsinfo'][$row][$col]['dontprint']))
   {
    $table_output[$sheet] .= "<td class='table_data' $this_cell_colspan $this_cell_rowspan>&nbsp;";
    if($force_nobr)
    {
     $table_output[$sheet] .= "<nobr>";
    }
    $table_output[$sheet] .= nl2br(htmlentities($data->sheets[$sheet]['cells'][$row][$col]));
    if($force_nobr)
    {
     $table_output[$sheet] .= "</nobr>";
    }
    $table_output[$sheet] .= "</td>";
   }
  }
  $table_output[$sheet] .= "</tr>";
 }
 $table_output[$sheet] .= "</table>";
 $table_output[$sheet] = str_replace(" ","",$table_output[$sheet]);
 $table_output[$sheet] = str_replace(" ","",$table_output[$sheet]);
 $table_output[$sheet] = str_replace(" "," ",$table_output[$sheet]);
 if($debug)
 {
  $debug_output = print_r($data->sheets[$sheet],true);
  $debug_output = str_replace(" ","\n",$debug_output);
  $debug_output = str_replace(" ","\r",$debug_output);
  $table_output[$sheet] .= "<pre>$debug_output</pre>";
 }
 echo "sheet_html[$sheet] = "$table_output[$sheet]"; ";
}
echo "
function change_tabs(sheet)
{
 //alert('sheet_tab_' + sheet);
 for(i=0;i<" , count($data->sheets) , ";i++)
 {
  document.getelementbyid('sheet_tab_' + i).classname = 'tab_base';
 }
 document.getelementbyid('table_loader_div').innerhtml=sheet_html[sheet];
 document.getelementbyid('sheet_tab_' + sheet).classname = 'tab_loaded';

}
</script>";
echo "
<table class='table_body' name='tab_table'>
<tr>";
for($sheet=0;$sheet<count($data->sheets);$sheet++)
{
 echo "<td class='tab_base' id='sheet_tab_$sheet' align=center
  onmousedown="change_tabs($sheet);">", $data->boundsheets[$sheet]['name'] , "</td>";
}

echo
"<tr>";
echo "</table>
<div id=table_loader_div>www.111cn.net</div>
<script language='网页特效'>
change_tabs(0);
</script>";
//echo "<iframe name=table_loader_iframe src='about:blank' width=100 height=100></iframe>";
/*
echo "<pre>";
print_r($data);
echo "</pre>";
*/

// excelreader这个类你可以到官网去下载哦。

这是一款php mysql数据库备份与还原备份的代码,你可以随便的对你网站的数据库进行备份,同时也可以还原哦,这程序生成的是.sql的数据库文件,你也可以用其它工具导入,方便,生成的都是sql数据库备份语句,所以兼容性好。

inport.php

 代码如下 复制代码

<?php

 /**
  * 数据库备份程序
  *
  * @author:黄乐
  * @version:1.0
  * @lastupdate:2010-7-19
  *
  */

 include("config/config.php");
 include("includes/dbbackup.class.php");
 include("includes/msg.class.php");
 $dbbackup = new dbbackup($dbhost, $dbuser, $dbpwd, $dbname);
 $msg = new msg();
 $bakfile = $dbbackup->get_backup();       //获取备份文件
 if($_get['fn']){
  if($dbbackup->import($_get['fn'])){      //导入数据
   $str = "恭喜您<br>备份数据已经成功导入!";   //提示信息
   $msg->show_msg($str,'import.php','export.php'); //提示导入成功
  }
 }
 //删除备份文件
 if($_post['sub']){
  echo $dbbackup->del($_post['choice'])? $msg->show_msg("恭喜您<br>备份文件已删除成功!",'import.php','export.php') : $msg->show_msg("删除失败!",'import.php','import.php');
 }
?>

 

实现原理很简单就是根据用户提交的数据到mysql数据表中查询是否有相同的,有就输出没有就不操作了。这是一款简单的记录搜索代码。

首先我们来创建搜索数据表
create table if not exists `search` (
  `id` int(4) not null auto_increment,
  `keyword` varchar(500) not null,
  primary key  (`id`)
) engine=myisam default charset=utf8 auto_increment=1 ;

保存数据

 代码如下 复制代码
insert into `acc`.`search` (
`id` ,
`keyword`
)
values (
null , '内容搜索'
), (
null , 'php站内搜索'
);

*/

//数据连接

 代码如下 复制代码

$conn = mysql教程_connect('localhost','ac','1');//这里的ac用户名,1是密码,修改成你自己的mysql便可

$res = mysql_db_query('abc',"select * from search where keyword='内容搜索' ") or die(mysql_error());

if(mysql_num_rows($res) == 1) {
   while($row = mysql_fetch_assoc($res)) {
      foreach($row as $key => $val) {
         echo $row['keyword'],'<br >';
      }
   }
}

/*

本站原创转载注明来源www.111cn.net
*/

php搜索csv中的数据原理是打开csv文件,然后一行行搜索指定的内容是否包含在我们读取这代码中,如果是返回true。

//搜索csv中指定内容

 代码如下 复制代码

$fh = @fopen("csv_file_name", "r");
if($fh) {
   if(flock($fh, lock_ex)) {
      while(!feof($fh)) {
         $line = fgets($fh);
         if(strstr($line, $target_email_address) !== false) {
            $data = split(",", $line); // $data *is* an array
         }
      }
      flock($fh, lock_un);
   }

   fclose($fh);
}

 代码如下 复制代码
$cn = mysql_connect('localhost','root','root');
if( $cn )
{
 die('数据库连接成功');
}
else
{
 die('连接失败');
}
[!--infotagslink--]

相关文章

  • php svn操作类

    以前我们开发大型项目时都会用到svn来同步,因为开发产品的人过多,所以我们会利用软件来管理,今天发有一居然可以利用php来管理svn哦,好了看看吧。 代码如下 ...2016-11-25
  • PHP 数据库缓存Memcache操作类

    操作类就是把一些常用的一系列的数据库或相关操作写在一个类中,这样调用时我们只要调用类文件,如果要执行相关操作就直接调用类文件中的方法函数就可以实现了,下面整理了...2016-11-25
  • C#从数据库读取图片并保存的两种方法

    这篇文章主要介绍了C#从数据库读取图片并保存的方法,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2021-01-16
  • SpringBoot实现excel文件生成和下载

    这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
  • php把读取xml 文档并转换成json数据代码

    在php中解析xml文档用专门的函数domdocument来处理,把json在php中也有相关的处理函数,我们要把数据xml 数据存到一个数据再用json_encode直接换成json数据就OK了。...2016-11-25
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • Php文件上传类class.upload.php用法示例

    本文章来人大家介绍一个php文件上传类的使用方法,期望此实例对各位php入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
  • c#读取excel方法实例分析

    这篇文章主要介绍了c#读取excel方法,实例分析了C#读取excel文件的原理与相关技巧,需要的朋友可以参考下...2020-06-25
  • Python导入数值型Excel数据并生成矩阵操作

    这篇文章主要介绍了Python导入数值型Excel数据并生成矩阵操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-06-09
  • PHP实现无限级分类(不使用递归)

    无限级分类在开发中经常使用,例如:部门结构、文章分类。无限级分类的难点在于“输出”和“查询”,例如 将文章分类输出为<ul>列表形式; 查找分类A下面所有分类包含的文章。1.实现原理 几种常见的实现方法,各有利弊。其中...2015-10-23
  • PHP实现递归无限级分类

    在一些复杂的系统中,要求对信息栏目进行无限级的分类,以增强系统的灵活性。那么PHP是如何实现无限级分类的呢?我们在本文中使用递归算法并结合mysql数据表实现无限级分类。 递归,简单的说就是一段程序代码的重复调用,当把...2015-10-23
  • C#类中static变量用法分析

    这篇文章主要介绍了C#类中static变量用法,实例分析了static变量使用技巧与相关注意事项,需要的朋友可以参考下...2020-06-25
  • mybatis-plus实体类主键策略有3种(小结)

    这篇文章主要介绍了mybatis-plus实体类主键策略有3种(小结),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-08-27
  • C# winform打开Excel文档的方法总结(必看篇)

    下面小编就为大家带来一篇C# winform打开Excel文档的方法总结(必看篇)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • ecshop商品无限级分类代码

    ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25
  • c# 对CSV文件操作(写入、读取、修改)

    这篇文章主要介绍了c# 如何对CSV文件操作,帮助大家更好的理解和学习C#,感兴趣的朋友可以了解下...2020-11-03
  • PHP 一个完整的分页类(附源码)

    在php中要实现分页比起asp中要简单很多了,我们核心就是直接获取当前页面然后判断每页多少再到数据库中利用limit就可以实现分页查询了,下面我来详细介绍分页类实现程序...2016-11-25
  • python读取和保存mat文件的方法

    本文主要介绍了python读取和保存mat文件的方法,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-08-25
  • C# 导出Excel的6种简单方法实现

    C# 导出 Excel 的6种简单方法:数据表导出到 Excel,对象集合导出到 Excel,数据库导出到 Excel,微软网格控件导出到 Excel,数组导出到 Excel,CSV 导出到 Excel,你都会了吗?需要的朋友们下面随着小编来一起学习学习吧...2020-06-25
  • 详解ES6实现类的私有变量的几种写法

    这篇文章主要介绍了详解ES6实现类的私有变量的几种写法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-10