PHP Excelreader Read Excel Class

Source: Internet
Author: User
The code is as follows Copy Code

$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 in 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 tutorial 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= ' web Effects ' >
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]]);
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= ' web Effects ' >
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 This class you can go to the official website to download OH.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.