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

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

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

主站蜘蛛池模板: 91网站免费在线观看 | 日韩亚洲国产综合久久久 | 亚洲欧洲色天使日韩精品 | 欧美日本一区二区三区 | 337q日本大胆欧美人术艺术 | 国产高清一级毛片在线人 | 真人视频一级毛片 | 国产成人91精品 | 九九视频这里只有精品 | 欧美亚洲国产精品 | 麻豆国产在线视频 | 在线观看视频www | 国产精品久久久久久亚洲小说 | 美女视频黄频大全免费视频 | 综合网在线观看 | 国产精品自产拍视频观看 | 香蕉免费看一区二区三区 | 成人在线免费 | 欧美日韩一道本 | 色综合天天综合给合国产 | 黑人美国一级一级爰片 | 精品色综合 | 亚洲国产成人久久笫一页 | 天天狠天天透天天伊人 | 成人午夜视频在线播放 | 国产亚洲精品国产福利在线观看 | 激情小视频在线观看 | 国产成人精品福利网站在线观看 | 男女91视频 | 国产情侣小视频 | 在线精品国产一区二区 | 五月婷婷六月合 | 激情五月宗合网 | 国产精品免费一区二区区 | 欧美一区二区三区精品国产 | se97se成人亚洲网站 | 在线国产福利 | 国产一区二区三区在线观看视频 | caoliu在线| 色综合久久夜色精品国产 | 亚洲综合精品成人 |