天天躁日日躁狠狠躁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 使用小記,轉載需保留來源!

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

主站蜘蛛池模板: 国产精品嫩草影院一区二区三区 | 国产Av男人的天堂精品良久 | 中文字幕乱码在线人视频 | 成人免费在线观看视频 | 国产免费人成在线视频有码 | 国产偷啪自怕网 | 国产午夜高潮熟女精品AV | 九色终合九色综合88 | 99久久精品国产一区二区三区 | 欧美高清videos 360p| 羲义嫁密着中出交尾gvg794 | 国产精品无码AV天天爽人妻蜜桃 | 无人视频在线观看免费播放影院 | 在线播放成人无码日 | 亚洲三级视频在线观看 | 一色狗影院| 成人精品在线视频 | 20岁中国男同志china1069 20岁αsrian男同志免费 | 亚洲视频中文字幕在线观看 | 99成人在线 | 亚洲国产成人久久一区www妖精 | 69国产精品成人无码视频 | 精品无码三级在线观看视频 | 曰韩一本道高清无码av | 国产啪精品视频网免费 | X8X8拨牐拨牐X8免费视频8午夜 | 中文字幕福利视频在线一区 | brazzers欧美最新版视频 | 天天躁夜夜踩很很踩2022 | 动漫美女禁区 | 日韩亚洲国产欧美免费观看 | 国产亚洲精品久久久久久白晶晶 | 主播蜜汁丝袜精品自拍 | 十八禁久久成人一区二区 | 亚洲AV无码专区国产精品麻豆 | 精品熟女少妇AV免费观看 | cctv网站| 办公室里做好紧好爽H | 一个人的免费完整在线观看HD | 老女人与小伙子露脸对白 | 一本道亚洲区免费观看 |