一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

用Simple Excel導出xls實現方法

因為前幾天寫了篇文章,用php-excel-reader類導入excel內容,順便說些excel導出問題,我用的是simple excel,一個很簡單的導出xls類,特好用!
simple excel源碼如下:
復制代碼 代碼如下:
<?php
/**
* Simple excel generating from php5
*
* @package Utilities
* @license http://www.opensource.org/licenses/mit-license.php
* @author Oliver Schwarz <oliver.schwarz@gmail.com>
* @version 1.0
*/
class Excel_Xml
{
private $header = "<?xml version=/"1.0/" encoding=/"%s/"?/>/n<Workbook xmlns=/"urn:schemas-microsoft-com:office:spreadsheet/" xmlns:x=/"urn:schemas-microsoft-com:office:excel/" xmlns:ss=/"urn:schemas-microsoft-com:office:spreadsheet/" xmlns:html=/"http://www.w3.org/TR/REC-html40/">";
private $footer = "</Workbook>";
private $lines = array();
private $sEncoding;
private $bConvertTypes;
private $sWorksheetTitle;
public function __construct($sEncoding = 'UTF-8', $bConvertTypes = false, $sWorksheetTitle = 'Table1')
{
$this->bConvertTypes = $bConvertTypes;
$this->setEncoding($sEncoding);
$this->setWorksheetTitle($sWorksheetTitle);
}
public function setEncoding($sEncoding)
{
$this->sEncoding = $sEncoding;
}
public function setWorksheetTitle ($title)
{
$title = preg_replace ("/[///|:|//|/?|/*|/[|/]]/", "", $title);
$title = substr ($title, 0, 31);
$this->sWorksheetTitle = $title;
}
private function addRow ($array)
{
$cells = "";
foreach ($array as $k => $v):
$type = 'String';
if ($this->bConvertTypes === true && is_numeric($v)):
$type = 'Number';
endif;
$v = htmlentities($v, ENT_COMPAT, $this->sEncoding);
$cells .= "<Cell><Data ss:Type=/"$type/">" . $v . "</Data></Cell>/n";
endforeach;
$this->lines[] = "<Row>/n" . $cells . "</Row>/n";
}
public function addArray ($array)
{
foreach ($array as $k => $v)
$this->addRow ($v);
}
public function generateXML ($filename = 'excel-export')
{
$filename = preg_replace('/[^aA-zZ0-9/_/-]/', '', $filename);
header("Content-Type: application/vnd.ms-excel; charset=" . $this->sEncoding);
header("Content-Disposition: inline; filename=/"" . $filename . ".xls/"");
echo stripslashes (sprintf($this->header, $this->sEncoding));
echo "/n<Worksheet ss:Name=/"" . $this->sWorksheetTitle . "/">/n<Table>/n";
foreach ($this->lines as $line)
echo $line;
echo "</Table>/n</Worksheet>/n";
echo $this->footer;
}
}
?>

使用php案例如下:
復制代碼 代碼如下:
<?php
/**
* @author mckee
* @blog www.phpddt.com
*/
require_once 'excel.class.php';
$xls = new Excel_Xml('UTF-8',false,'測試');
$data = array(
1 => array('名稱','地址'),
2 => array('php點點通','www.phpddt.com'),
3 => array('百度','www.baidu.com')
);
$xls->addArray($data);
$xls->generateXML('name4test');

?>

導出結果如下圖:
用Simple Excel導出xls

php技術用Simple Excel導出xls實現方法,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 伊人久久综合网亚洲 | 亚洲免费久久 | 日韩在线播放中文字幕 | 亚洲国产成人在线 | 精品精品久久宅男的天堂 | 亚洲成人tv | 国内精品美女久久久久 | 91九色视频无限观看免费 | 欧美亚洲图片小说 | 真实国产乱子伦久久 | 91免费视频网 | 久久久久亚洲国产 | 久久久窝窝午夜精品 | 欧美成年黄网站色高清视频 | 婷婷激情片 | 国产精品玖玖玖在线观看 | 久久久亚洲精品视频 | 国产成人禁片在线观看 | 欧美综合在线观看 | 国内精品一区二区2021在线 | 综合精品视频 | 91色久| 手机看片www xiao2b cm | 久久久久久久国产a∨ | 免费精品视频在线 | 午夜视频在线 | 中文在线第一页 | 亚洲免费久久 | 色女人综合 | 伊人久久中文大香线蕉综合 | 久久亚洲私人国产精品 | 亚洲一区二区三区高清 | 91在线成人 | 欧美日韩一区二区亚洲 | 亚州色吧 | 91精品福利老司机在线观看 | 国产午夜视频 | 天天色综合社区 | 国产精品网页 | 亚洲国产精品自产在线播放 | 欧美一级成人免费大片 |