doukoumi3389 2013-08-12 08:27
浏览 21
已采纳

如果声明从excel表中提取数据取决于星期几

I'm doing a data pull from excel to display the output in HTML via PHP dependent on the day of the week. My code is as follows:

$dw = date('N');

if($dw==1) {$objWorksheet = $objPHPExcel->getActiveSheet(10);}
elseif($dw ==2) {$objWorksheet = $objPHPExcel->getActiveSheet(11);}
elseif($dw==3) {$objWorksheet = $objPHPExcel->getActiveSheet(12);}
elseif($dw==4) {$objWorksheet = $objPHPExcel->getActiveSheet(13);}
elseif  ($dw == 5) {$objWorksheet = $objPHPExcel->getActiveSheet(14);}
$A = $objWorksheet->getCellByColumnAndRow(0, $row)->getValue();
$B = $objWorksheet->getCellByColumnAndRow(1, $row)->getValue();
$C = $objWorksheet->getCellByColumnAndRow(2, $row)->getValue();
$D = $objWorksheet->getCellByColumnAndRow(5, $row)->getValue();
$E = substr(($objWorksheet->getCellByColumnAndRow(6, $row)->getValue()), 0, 1);
$F = $objWorksheet->getCellByColumnAndRow(7, $row)->getValue();

The problem I'm having is that instead of getting the data from sheet 10, I'm getting the data from sheet 1. In fairness even if I change the active sheet number to correspond to a different sheet I still get the same output yet further down the sheet I use a piece of code to pull the date and time from sheet 0 and this works fine.

I'd appreciate any suggestions on how to fix this

  • 写回答

2条回答 默认 最新

  • dpnv33177 2013-08-12 08:36
    关注

    From the PHPExcel documentation:

    PHPExcel - Worksheets

    getSheet(10)
    

    instead of getActiveSheet (which doesn't have any arguments)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊