- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将每个员工的出勤详细信息作为批量出勤上传从 excel 文件保存到数据库中,下面的代码显示 Excel 数据导入成功,但没有将值存储到数据库中,行 $last_id= $this->mod_common->add_attendence_data($data_user);没有执行,这就是为什么它不起作用,如何让这一行执行?由于这段代码是由其他一些开发人员编写的,我发现它很难理解。
Controller :admin_list.php
function upload_bulk_attendance(){
$data['htmltext'] = $this->mod_common->get_allleaves();
$this->data['maincontent'] = $this->load->view('maincontents/upload_attendance_sheet', $data,true);
$this->load->view('layout', $this->data);
}
function importExcel() {
//$this->mod_common->delete_attendance();
$this->load->library('excel');
//microsoft excel 2007
if(!$objReader = PHPExcel_IOFactory::createReader('Excel5')){
die('Unable to create reader object');
}
//$objReader = PHPExcel_IOFactory::createReader('Excel2007');
//set to read only
$objReader->setReadDataOnly(false);
//load excel file
global $SITE;
if(!$upload_val=$this->admin_init_elements->do_upload_docs('user_attendance',$SITE->client_logo_image_src,false)){
$data['error'] = $this->upload->display_errors();
$this->load->view('maincontents/upload_attendance_sheet', $data,true);
} else {
$file_path = $upload_val['upload_data']['full_path'];
}
$objPHPExcel = $objReader->load($file_path);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(1);
/*---------------------------------------------------------------------------*/
$excelrow = 1;
$from_Date = $objWorksheet->getCellByColumnAndRow(4,1)->getValue();
$to_Date = $objWorksheet->getCellByColumnAndRow(6,1)->getValue();
$total_rows_in_sheet = $objPHPExcel->getActiveSheet()->getHighestRow();
if (PHPExcel_Shared_Date::isDateTime($objPHPExcel->getActiveSheet()->getCell('E1'))) {
$dateValue = PHPExcel_Shared_Date::ExcelToPHP($from_Date);
$from_date = date('Y-m-d',$dateValue);
}
if (PHPExcel_Shared_Date::isDateTime($objPHPExcel->getActiveSheet()->getCell('G1'))) {
$dateValue = PHPExcel_Shared_Date::ExcelToPHP($to_Date);
$to_date = date('Y-m-d',$dateValue);
}
$start = strtotime($from_date);
$end = strtotime($to_date);
$days_between = ceil(abs($end - $start) / 86400);
$excelrow = $excelrow + 2;
$emp_code_id_array = $this->mod_common->get_Details2('pr_users_details',array('userid','emp_code'));
foreach($emp_code_id_array as $e){ $emp_code_id[$e['emp_code']] = $e['userid']; }
do {
$shift_excelrow = ++$excelrow;
/*--------------- Moving row wise for each employees data --------------*/
$emp_code = $objWorksheet->getCellByColumnAndRow(0,$excelrow)->getValue();
$emp_code =($emp_code==null)?0:$emp_code;
if($emp_code<=0) continue;
$emp_code = str_pad($emp_code, 3, '0', STR_PAD_LEFT);
$emp_id =($emp_code_id[$emp_code]==null)?0:$emp_code_id[$emp_code];
$emp_name = $objWorksheet->getCellByColumnAndRow(1,$excelrow)->getValue();
/*--------------- Moving column wise for each days data --------------*/
$col_no=3;
for($i=0;$i<=$days_between;$i++) {
$dt = date('Y-m-d',strtotime($from_date));
$day = date('d', strtotime($dt .' +'.$i.' day'));
$entry[] = $day."|".$objWorksheet->getCellByColumnAndRow($col_no,$shift_excelrow)->getValue();
$col_no++;
}
$present=$objWorksheet->getCellByColumnAndRow(34,$shift_excelrow)->getValue();
$absent=$objWorksheet->getCellByColumnAndRow(35,$shift_excelrow)->getValue();
$total=$objWorksheet->getCellByColumnAndRow(36,$shift_excelrow)->getValue();
if($emp_id!=0){
$emp_id_arr[] = $emp_id;
}
/* CREATING ARRAY FOR DB INSERT */
$data_user['emp_code'] = $emp_code;
$data_user['emp_id'] = $emp_id;
$data_user['name'] = $emp_name;
$data_user['entry'] = implode(",",$entry);
$data_user['from_date'] = $from_date;
$data_user['to_date'] = $to_date;
$data_user['present'] = $present;
$data_user['absent'] = $absent;
$data_user['total'] = $total;
$data_user['current_date'] = date('Y-m-d');
$last_id=$this->mod_common->add_attendence_data($data_user);
//Reset array
$entry=array();
}while($excelrow <=$total_rows_in_sheet);
/*----------------------------------------------------*/
if(count($emp_id_arr)==0){
$emp_id_arr[] = 0;
}
$this->mod_common->save_attendance_notification($last_id,implode(",",$emp_id_arr),$data_user['from_date']);
$this->session->set_flashdata('success', 'Excel Data Imported Succesfully');
redirect(base_url().'admin_list/upload_bulk_attendance');
}//importExcel() END
模型:mod_common.php
function add_attendence_data($datauser) {
$emp_code = str_pad($datauser['emp_code'], 3, '0', STR_PAD_LEFT);
$this->db_replace->select('*');
$this->db_replace->from($this->myTables['attendance']);
$this->db_replace->where('emp_code',$emp_code);
$this->db_replace->where('from_date',$datauser['from_date']);
$query=$this->db_replace->get();
if($query->num_rows() <= 0)
{
$datauser['emp_code'] = $emp_code;
$this->db_replace->insert($this->myTables['attendance'],$datauser);
$instanceid = $this->db_replace->insert_id();
return $instanceid;
} else return false;
}
查看:upload_attendance_sheet.php
<section class="content-header">
<h1>
Upload Attendance
</h1>
<ol class="breadcrumb">
<li><a href="<?php echo base_url(); ?>"><i class="fa fa-home"></i> Home</a></li>
<li><a href="<?php echo base_url(); ?>admin_list"> Admin</a></li>
<li><a href="<?php echo base_url(); ?>admin_list#peopleconnect">Attendance</a></li>
<li class="active">Upload Attendance</li>
</ol>
</section>
<section class="content">
<div class="container-fluid">
<div class="row">
<!-- Thought Day-->
<div class="panel wrapper clearfix m-b-none">
<div class="box-header with-border">
<?php if($bulkUploadMsg!=''){?>
<?php echo $bulkUploadMsg;?>
<?php } ?>
<?php
if($this->session->flashdata('success') == TRUE){
echo $this->session->flashdata('success');
}
?>
<br>
<?php
echo form_open_multipart('admin_list/importExcel', array('method'=>'post','name'=>'uploadUserForm','id'=>'upload_file','class'=>"custom-form"));
?>
Please download attendance upload format by clicking <a href="<?php echo base_url(); ?>uploads/attendance_format.xls" class="text-info" style="color:#23b7e5">here</a><br><br>
<table cellpadding="10px" style="background:none;width:100%;" RULES="ROWS">
<thead>
<tr>
<td width="50px;">Upload</td>
<td>:</td>
<td>
<?php echo form_upload(array("required"=>"required","name"=>"user_attendance","id"=>"user_attendance")); ?>
</td>
</tr>
</table>
<h3>Instructions to Upload : </h3>
<ul>
<li>Complete the sheet below and upload to update attendance records of all employees
</li><li>
You may add as many rows as needed - one for each employee
</li><li>Enter the start and end dates in the dd/mm/yyyy format only
</li><li>Only use the legend given to enter primary attendance details - Present at assigned office location-X, Absent without notification-A, On Official Travel-O, Present but not in office location-P, Week Off-W, Holiday-H, Half day working-D
</li><li>Use the following legends for entering Leave Details-<?php echo $htmltext; ?>
</li><li>As good practice, ensure that this sheet is uploaded at approximately the same interval each month
</li></ul><br>
</p>
<br>
<?php
echo form_submit(array('name'=>'submit','value'=>'Upload','class'=>'btn btn-info btn-submit pull-right add'));
echo form_close();
?>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/plugins/data-tables/DT_bootstrap.js"></script>
表:pr_attendance
最佳答案
请尝试这种方式:-
<?php
public function importContacts($id)
{
if(isset($_POST["Import"]))
{
$filename=$_FILES["file"]["name"];
$f_extension = explode('.',$filename);
$f_extension = strtolower(end($f_extension));
if($f_extension == 'csv') // for import CSV file
{
$file_tmp_name=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($file_tmp_name, "r");
$row = array();
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
array_push($row, $emapData);
}
fclose($file);
unset($row[0]);
foreach(array_values($row) as $r){
$data = array(
'gc_group_id' => $id,
'gc_user_id' => $this->session->userdata('userId'),
'gc_name' => @$r[1],
'gc_number' => @$r[0],
'gc_email' => @$r[2],
'gc_added_date' => date('Y-m-d'),
);
$this->user_model->add('groups_contact',$data);
array_push($valid_no, $r[0]);
}
fclose($file);
}
}
if($f_extension == 'xlsx' || $f_extension == 'xls')
{
/* PHPExcel library */
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
require_once APPPATH.'third_party/PHPExcel/IOFactory.php';
$file_tmp_name=$_FILES["file"]["tmp_name"];
try {
$objPHPExcel = PHPExcel_IOFactory::load($file_tmp_name);
} catch(Exception $e) {
die('Error loading file :' . $e->getMessage());
}
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
unset($sheetData[1]);
foreach(array_values($sheetData) as $s){
$data = array(
'gc_group_id' => $id,
'gc_user_id' => $this->session->userdata('userId'),
'gc_name' => @$s[B],
'gc_number' => @$s[A],
'gc_email' => @$s[C],
'gc_added_date' => date('Y-m-d'),
);
$this->user_model->add('groups_contact',$data);
array_push($valid_no, $s[A]);
}
}
$msg = 'Contacts Added Successfully ';
}
}
?>
如果您发现任何问题,请告诉我。
关于php - 从上传的 excel 文件中检索值并将其存储到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45972690/
我正在运行一个辅助角色,并检查 Azure 上托管的存储中是否存在数据。当我将连接字符串用于经典类型的存储时,我的代码可以正常工作,但是当我连接到 V2 Azure 存储时,它会抛出此异常。 “远程服
在我的应用程序的主页上,我正在进行 AJAX 调用以获取应用程序各个部分所需的大量数据。该调用如下所示: var url = "/Taxonomy/GetTaxonomyList/" $.getJSO
大家好,我正在尝试将我的商店导入我的 Vuex Route-Gard。 路由器/auth-guard.js import {store} from '../store' export default
我正在使用 C# 控制台应用程序 (.NET Core 3.1) 从 Azure Blob 存储读取大量图像文件并生成这些图像的缩略图。新图像将保存回 Azure,并将 Blob ID 存储在我们的数
我想将 Mlflow 设置为具有以下组件: 后端存储(本地):在本地使用 SQLite 数据库存储 Mlflow 实体(run_id、params、metrics...) 工件存储(远程):使用 Az
我正在使用 C# 控制台应用程序 (.NET Core 3.1) 从 Azure Blob 存储读取大量图像文件并生成这些图像的缩略图。新图像将保存回 Azure,并将 Blob ID 存储在我们的数
我想将 Mlflow 设置为具有以下组件: 后端存储(本地):在本地使用 SQLite 数据库存储 Mlflow 实体(run_id、params、metrics...) 工件存储(远程):使用 Az
我的 Windows 计算机上的本地文件夹中有一些图像。我想将所有图像上传到同一容器中的同一 blob。 我知道如何使用 Azure Storage SDKs 上传单个文件BlockBlobServi
我尝试发出 GET 请求来获取我的 Azure Blob 存储帐户的帐户详细信息,但每次都显示身份验证失败。谁能判断形成的 header 或签名字符串是否正确或是否存在其他问题? 代码如下: cons
这是用于编写 JSON 的 NeutralinoJS 存储 API。是否可以更新 JSON 文件(推送数据),而不仅仅是用新的 JS 对象覆盖数据。怎么做到的??? // Javascript
我有一个并行阶段设置,想知道是否可以在嵌套阶段之前运行脚本,所以像这样: stage('E2E-PR-CYPRESS') { when { allOf {
我想从命令行而不是从GUI列出VirtualBox VM的详细信息。我对存储细节特别感兴趣。 当我在GUI中单击VM时,可以看到包括存储部分在内的详细信息: 但是到目前为止,我还没有找到通过命令行执行
我有大约 3500 个防洪设施,我想将它们表示为一个网络来确定流动路径(本质上是一个有向图)。我目前正在使用 SqlServer 和 CTE 来递归检查所有节点及其上游组件,只要上游路径没有 fork
谁能告诉我 jquery data() 在哪里存储数据以及何时删除以及如何删除? 如果我用它来存储ajax调用结果,会有性能问题吗? 例如: $("body").data("test", { myDa
有人可以建议如何为 Firebase 存储中的文件设置备份。我能够备份数据库,但不确定如何为 firebase 存储中的文件(我有图像)设置定期备份。 最佳答案 如何进行 Firebase 存储的本地
我最近开始使用 firebase 存储和 firebase 功能。现在我一直在开发从功能到存储的文件上传。 我已经让它工作了(上传完成并且文件出现在存储部分),但是,图像永远保持这样(永远在右侧加载)
我想只允许用户将文件上传到他们自己的存储桶中,最大文件大小为 1MB,仍然允许他们删除文件。我添加了以下内容: match /myusers/{userId}/{allPaths=**} { al
使用生命周期管理策略将容器的内容从冷访问层移动到存档。我正在尝试以下策略,希望它能在一天后将该容器中的所有文件移动到存档层,但事实并非如此在职的。我设置了选择标准“一天未使用后”。 这是 json 代
对于连接到 Azure 存储端点,有 http 和 https 两个选项。 第一。 https 会带来开销,可能是 5%-10%,但我不支付同一个数据中心的费用。 第二。 http 更快,但 Auth
有人可以帮我理解这一点吗?我创建了Virtual Machine in Azure running Windows Server 2012 。我注意到 Azure 自动创建了一个存储帐户。当我进入该存
我是一名优秀的程序员,十分优秀!