php ExcelReader 读取Excel类
这是一款开源的php代码,ExcelReader是专业地excel表进行读写操作的,下面我们来看一款ExcelReader读取phprm.com.xls工作表实例吧,代码如下:
<?php $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.phprm.com/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='javascript'> var sheet_html = array(); "; for ($sheet = 0; $sheet < count($data->sheets); $sheet++) { $table_output[$sheet].= "<table class='table_body'> <tr> <td> </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> "; 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 class="brush:php;toolbar:false">$debug_output
Copy after login
", $data->boundsheets[$sheet]['name'], " | "; } echo "
www.phprm.com
";
//echo "";
/*
echo ""; print_r($data); echo "
Copy after login
excelreader这个类你可以到官网去下载 .
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

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
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks ago
By DDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks ago
By DDD
Where to find the Crane Control Keycard in Atomfall
3 weeks ago
By DDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months ago
By DDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks ago
By DDD

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)

Hot Topics
CakePHP Tutorial
1387
52

