程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php ExcelReader 讀取Excel類

php ExcelReader 讀取Excel類

編輯:關於PHP編程

php ExcelReader 讀取Excel類 /* 這是一款開源的php代碼,ExcelReader是專業地excel表進行讀寫操作的哦,下面我們來看一款ExcelReader讀取bKjia.c0m.xls工作表實例吧。

php教程 excelreader  讀取excel類
 /*
 這是一款開源的php代碼,excelreader是專業地excel表進行讀寫操作的哦,下面我們來看一款excelreader讀取bKjia.c0m.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 = "bKjia.c0m.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.bKjia.c0m/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();n";
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("n","",$table_output[$sheet]);
 $table_output[$sheet] = str_replace("r","",$table_output[$sheet]);
 $table_output[$sheet] = str_replace("t"," ",$table_output[$sheet]);
 if($debug)
 {
  $debug_output = print_r($data->sheets[$sheet],true);
  $debug_output = str_replace("n","\n",$debug_output);
  $debug_output = str_replace("r","\r",$debug_output);
  $table_output[$sheet] .= "<pre>$debug_output</pre>";
 }
 echo "sheet_html[$sheet] = "$table_output[$sheet]";n";
}
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.bKjia.c0m</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這個類你可以到官網去下載哦。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved