一区二区久久-一区二区三区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精品国产免费入口 | 理论片中文字幕在线观看 | 久久亚洲综合伊人 | 国产精品午夜国产小视频 | 免费国产h视频在线观看 | 国产免费一区二区三区在线观看 | 国产福利99 | 高清一区二区三区 | 一级做a爰片性色毛片男 | 亚洲欧美视频在线播放 | 国产真实伦在线视频免费观看 | 香蕉成人在线视频 | 在线播放一区二区三区 | 免费国产在线观看不卡 | 日本在线观看永久免费网站 | 韩国一级毛片在线观看 | 一区二区三区亚洲 | 七七七久久久久人综合 | 日韩片在线观看 | 婷婷中文 | 美女网站视频黄色 | 国产第二区 | 欧美色综合高清视频在线 | 国产成人精品亚洲日本在线 | 久久香蕉综合精品国产 | 91麻精品国产91久久久久 | 特黄毛片 | 热伊人99re久久精品最新地 | 日产精品一区二区 | 亚洲人的天堂男人爽爽爽 | 国内成人免费视频 | 加勒比精品 | 国产视频第一页 | 成人免费大片a毛片 | 97在线观看成人免费视频 | 国产三级全黄 |