天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

PHPEXCEL 使用小記

首先是使用php Reader 讀取Excle內容:
復制代碼 代碼如下:
require("http://www.jb51.NET/phpExcel/Classes/phpExcel.php");
$file = "D://datas.xlsx";
if(!file_exists($file)){
die("no file found in {$file}");
}
$datasReader = phpExcel_IOFactory::load($file);
$sheets = $datasReader->getAllSheets();
//如果有多個工作簿
$countSheets = count($sheets);
$sheetsinfo = array();
$sheetData = array();
if($countSheets==1){
$sheet = $sheets[0];
$sheetsinfo["rows"] = $sheet->getHighestRow();
$sheetsinfo["column"] = phpExcel_Cell::columnIndexFromString($sheet->getHighestColumn());
for($row=1;$row<=$sheetsinfo["rows"];$row++){
for($column=0;$column<$sheetsinfo["column"];$column++){
$sheetData[$column][$row] = $sheet->getCellByColumnAndRow($column, $row)->getValue();
}
}
}else{
foreach ($sheets as $key => $sheet)
{
$sheetsinfo[$key]["rows"] = $sheet->getHighestRow();
$sheetsinfo[$key]["column"] = phpExcel_Cell::columnIndexFromString($sheet->getHighestColumn());
for($row=1;$row<=$sheetsinfo[$key]["rows"];$row++){
for($column=0;$column<$sheetsinfo[$key]["column"];$column++){
$sheetData[$key][$column][$row] = $sheet->getCellByColumnAndRow($column, $row)->getValue();
}
}
}
}
echo "<pre>";
print_r($sheetData);
echo "</pre>";

注:使用php 讀取excel文件內容,一般都是處理整理好格式的csv或者excel,也可以讀取xml文件

phpExcel生成Exceel
復制代碼 代碼如下:
$sql = sprintf("select * from table where op_id=%d", intval($this->params['id']));
$query = $this->_db->query($sql);
require_once './phpExcel_1.7.4/Classes/phpExcel.php';
$objphpExcel = new phpExcel();
$objphpExcel->setActiveSheetIndex(0);
$objphpExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
$objphpExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$objphpExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
$objphpExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
$objphpExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
$objphpExcel->getActiveSheet()->setCellValue('A1', "{$this->_packInfos['o_id']}");
$objphpExcel->getActiveSheet()->setCellValue('B1', "Volume weight (kg)");
$objphpExcel->getActiveSheet()->setCellValue('D1', "Actual weight (kg)");


$objphpExcel->getActiveSheet()->setCellValue('A2', "Box No.");
$objphpExcel->getActiveSheet()->setCellValue('B2', "Products");
$objphpExcel->getActiveSheet()->setCellValue('C2', "Shipping Box");
$objphpExcel->getActiveSheet()->setCellValue('D2', "System");
$objphpExcel->getActiveSheet()->setCellValue('E2', "Input");
$objActSheet = $objphpExcel->getActiveSheet();
$objActSheet->mergeCells("B1:C1");
$objActSheet->mergeCells("D1:E1");

$objphpExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_LEFT);
$objphpExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_CENTER);
$objphpExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_CENTER);

$objphpExcel->getActiveSheet()->getStyle('A2'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_LEFT);
$objphpExcel->getActiveSheet()->getStyle('B2'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_CENTER);
$objphpExcel->getActiveSheet()->getStyle('C2'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_CENTER);
$objphpExcel->getActiveSheet()->getStyle('D2'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_CENTER);
$objphpExcel->getActiveSheet()->getStyle('E2'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_CENTER);

if($this->_db->num_rows($query)>0)
{
$i=3;
while ($row = $this->_db->fetch_assoc($query))
{
$objphpExcel->getActiveSheet()->setCellValue('A'.($i),"BOX ".$row['box_num']);
$objphpExcel->getActiveSheet()->setCellValue('B'.($i),sprintf("%.2f",$row['volume_weight']));
$objphpExcel->getActiveSheet()->setCellValue('C'.($i),sprintf("%.2f",$row['box_weight']));
$objphpExcel->getActiveSheet()->setCellValue('D'.($i),sprintf("%.2f",$row['system_weight']));
$objphpExcel->getActiveSheet()->setCellValue('E'.($i),sprintf("%.2f",$row['real_weight']));

$objphpExcel->getActiveSheet()->getStyle('A'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_LEFT);
$objphpExcel->getActiveSheet()->getStyle('B'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objphpExcel->getActiveSheet()->getStyle('C'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objphpExcel->getActiveSheet()->getStyle('D'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objphpExcel->getActiveSheet()->getStyle('E'.($i))->getAlignment()->setHorizontal(phpExcel_Style_Alignment::HORIZONTAL_RIGHT);
$i++;
}
}

$fileName="exportBox.xls";
$filePath = dirname(dirname("__FILE__"))."/template/".$fileName;
$path = "./template/".$fileName;
$objWriter = new phpExcel_Writer_Excel2007($objphpExcel);
if(file_exists($path)){
chmod($path, 0777);
unlink($path);
$objWriter->save($path);
header('application/vnd.ms-excel');
header('Content-Disposition: attachment;filename=weight-'.$this->_packInfos["o_id"].".xlsx");
readfile($filePath);
die();
}
else
{
$objWriter->save($path);
header('application/vnd.ms-excel');
header('Content-Disposition: attachment;filename=weight-'.$this->_packInfos["o_id"].".xlsx");
readfile($filePath);
die();
}

注:上面的php生成excel的方式是直接使用A標簽形式的,如果使用ajax,可以不使用header,直接echo $path,前臺window.location.href=返回來的path就可以了。

php技術PHPEXCEL 使用小記,轉載需保留來源!

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

主站蜘蛛池模板: 精品手机在线1卡二卡3卡四卡 | 国产野外无码理论片在线观看 | a级男女性高爱潮高清试看 A级毛片无码久久精品免费 | 18禁在线无遮挡羞羞漫画 | 亚洲欧美一区二区三区四区 | 嫩草AV久久伊人妇女 | 久久精麻豆亚洲AV国产品 | 亚洲日本天堂在线 | 麻豆传煤网站网址入口在线下载 | 国产三级多多影院 | 各种场合肉H校园1V1 | 伊人久在线| 国产成人高清亚洲一区app | 94色94色永久网站 | 亚洲人成在线播放无码 | 日韩午夜欧美精品一二三四区 | 男人边吃奶边摸边做刺激情话 | 亚洲综合中文字幕无线码 | 野花日本免费完整版高清版动漫 | 午夜性爽视频男人的天堂在线 | 国产午夜亚洲精品区 | 免费视频国产 | 琉璃美人煞在线观看 | 国产精品久久久久久AV免费不卡 | 伸进同桌奶罩里摸她胸作文 | 亚洲精品久久区二区三区蜜桃臀 | 精品视频在线观看视频免费视频 | 亚洲、国产综合视频 | 国产人妻精品久久久久久很牛 | 国产手机在线亚洲精品观看 | 午夜影视不充值观看 | 国产毛A片久久久久久无码 国产毛A片啊久久久久久A | 毛片基地看看成人免费 | 精品久久综合1区2区3区激情 | 性888xxxx入欧美 | 久久婷婷五月综合色情 | 成人手机在线 | 亚洲精品国偷拍自产在线 | 最近中文字幕无吗免费高清 | 成人免费视频一区 | 无人在线观看免费高清视频播放 |