codeigniter - 除当前单元格值外,导入 phpexcel codeigniter
问题描述
我想使用我的codeigniter中的php excel从excel导入,当前单元格包含当前文本
单元格1 | 单元格2 |
---|---|
一个 | 1 |
乙 | 2 |
C | 3 |
我只想在cell1中除了B之外的单元格插入数据库
我的控制器
public function import_excel(){
if (isset($_FILES["fileExcel"]["name"])) {
$path = $_FILES["fileExcel"]["tmp_name"];
$object = IOFactory::load($path);
foreach($object->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
$highestColumn = $worksheet->getHighestColumn();
for($row=2; $row<=$highestRow; $row++)
{
$cell1= $worksheet->getCellByColumnAndRow(0, $row)->getValue();
$cell2= $worksheet->getCellByColumnAndRow(1, $row)->getValue();
$temp_data[] = array(
'cell1' => $cell1,
'cell2' => $cell2,
);
}
}
if($cell1 == 'B'){
}else{
$this->load->model('M_Admin');
$insert = $this->M_Admin->insert($temp_data);
}
但这失败了,数据仍然插入。请帮助我,非常感谢你的帮助。
解决方案
我以前从未使用过 phpexcel,但如果它是数组并认为 $cell1 是字符串/文本,我想你可以尝试使用它:
for($row=2; $row<=$highestRow; $row++)
{
$cell1= $worksheet->getCellByColumnAndRow(0, $row)->getValue();
$cell2= $worksheet->getCellByColumnAndRow(1, $row)->getValue();
//cell value you want to hide
if ($cell1 == 'B') {
$cell1 = 'xxx'; //overwrite that value into something
}
$temp_data[] = array(
'cell1' => $cell1,
'cell2' => $cell2,
);
}
注意:我正在使用 codeigniter 3
推荐阅读
- postgresql - Postgresql Percentile_Cont 不起作用:函数 percentile_cont(numeric, character varying, numeric) 不存在
- matlab - 使用 fwrite 在 matlab 中将 24 位 bmp 转换为 8 位 bmp
- javascript - 从视图中的隐藏字段获取值并在同一视图中使用它
- javascript - 我如何访问公会 ID (Discord Bot)
- javascript - 将授权令牌添加到 JavaScript 中的标头以从 API 获取数据
- python - Create Table of all Sums from two Arrays in Pandas
- django - Django - 保存前替换模型字段值
- azure-cosmosdb - 在 LINQ 查询中将 POCO 中的属性名称映射到 Cosmos Db 中的字段名称的问题
- python - 将值添加到 DataFrame 到相应的值
- css - 在 youtube 全屏视图上放置一个浮动按钮