PHPEXcel和easyui采用MVC框架写一个超大Excel上传到数据库,先插入临时表,根据临时的字段查入实际的数据库,用临时的某个字段是字段判断以前的某个字段重复跳过下一行插入数据并且在上传完显示到上界面

时间: 2024-04-16 13:24:49 浏览: 24
您可以按照以下步骤来实现您的需求: 1. 首先,创建一个MVC架构的项目。您可以使用任何流行的PHP框架,如Laravel、CodeIgniter或Yii等。 2. 在您的视图层中,使用easyui创建一个上传文件的表单,并将表单数据发送到控制器。 3. 在控制器中,接收上传文件,并使用PHPEXcel库读取Excel文件数据。您可以使用PHPEXcel的方法,如`load()`函数来加载Excel文件。 4. 在控制器中,创建一个临时表来存储Excel数据。您可以使用数据库操作类或原生SQL语句来执行插入操作,并将Excel数据插入到临时表中。 5. 接下来,根据临时表中的字段进行查询操作。您可以使用SQL语句来查询具有重复字段的数据行。 6. 根据查询结果,在实际数据库中插入数据。您可以使用数据库操作类或原生SQL语句来执行插入操作,并将数据插入到实际的数据库表中。 7. 最后,将上传数据显示在前端界面上。您可以在控制器中查询实际数据库,并将结果传递给视图层,然后使用easyui来渲染和显示数据。 请注意,以上步骤是一个大致的指导,具体实现还需要根据您所选择的框架和库进行调整。此外,代码的安全性和数据验证也是非常重要的,您可能需要添加适当的验证和过滤来确保数据的准确性和安全性。
相关问题

PHPEXcel和easyui写一个超大Excel上传到数据库

要实现将超大的Excel文件上传到数据库,可以使用PHPExcel库来读取Excel文件的数据,然后使用EasyUI的文件上传组件来实现文件上传功能。下面是一个示例的代码: 1. 首先,确保已经安装了PHPExcel库和EasyUI库。 2. 创建一个上传页面(upload.php),包含一个EasyUI的文件上传组件和一个上传按钮: ```html <!DOCTYPE html> <html> <head> <title>Excel上传</title> <link rel="stylesheet" type="text/css" href="easyui/easyui.css"> <script type="text/javascript" src="easyui/jquery.min.js"></script> <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script> </head> <body> <h2>Excel上传</h2> <input id="excelFile" name="excelFile" class="easyui-filebox" accept=".xls,.xlsx"> <br><br> <a href="#" class="easyui-linkbutton" onclick="upload()">上传</a> <script type="text/javascript"> function upload() { $('#excelFile').filebox('textbox').attr('name', 'excelFile'); $('#excelForm').form('submit', { url: 'upload_handler.php', onSubmit: function() { $.messager.progress(); return true; }, success: function(data) { $.messager.progress('close'); $.messager.alert('提示', data, 'info'); } }); } </script> </body> </html> ``` 3. 创建一个处理上传的脚本(upload_handler.php),在这个脚本中使用PHPExcel库来读取Excel数据并将其插入到数据库中: ```php <?php require_once 'PHPExcel/IOFactory.php'; // 获取上传的Excel文件 $excelFile = $_FILES['excelFile']['tmp_name']; // 加载Excel文件 $objPHPExcel = PHPExcel_IOFactory::load($excelFile); // 获取第一个工作表 $sheet = $objPHPExcel->getActiveSheet(); // 获取行数和列数 $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); // 循环读取数据 for ($row = 1; $row <= $highestRow; $row++) { $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, null, true, false); // 将数据插入数据库,这里只是示例,需要根据实际情况进行数据库操作 // $rowData[0][0] 表示第一列的数据,$rowData[0][1] 表示第二列的数据,依此类推 // 例如:将数据插入名为data的表格中的两列name和value中 // $name = $rowData[0][0]; // $value = $rowData[0][1]; // insert into data (name, value) values ('$name', '$value'); } echo '上传成功!'; ?> ``` 以上代码仅为示例,实际使用中需要根据数据库类型和表结构进行相应的修改。另外,由于上传大型Excel文件可能会占用较多内存,可能需要对服务器进行相应的配置和优化。

写一个excel上传到数据库展示到前端,要求采用MVC,前端框架easyui

Sure! Here's an example of how you can upload an Excel file, store its data in a database, and display it on the front-end using the MVC pattern and the EasyUI framework: 1. Create the necessary database table to store the Excel data. Let's assume the table is named `excel_data` and has columns `id`, `name`, and `email`. 2. Create a file named `index.php` for the front-end view using EasyUI: ```html <!DOCTYPE html> <html> <head> <title>Excel Upload</title> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/easyui@1.9.25/themes/default/easyui.css"> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/easyui@1.9.25/jquery.easyui.min.js"></script> </head> <body> <h2>Excel Upload</h2> <form id="excelForm" method="post" enctype="multipart/form-data"> <input id="excelFile" name="excelFile" type="file"> <button id="uploadBtn" class="easyui-linkbutton" type="submit">Upload</button> </form> <table id="datagrid"></table> <script type="text/javascript"> $(function(){ $('#excelForm').form({ url: 'upload.php', onSubmit: function(){ return $(this).form('validate'); }, success: function(result){ $('#datagrid').datagrid('reload'); $.messager.show({ title: 'Success', msg: result, timeout: 5000 }); } }); $('#datagrid').datagrid({ url: 'data.php', fitColumns: true, columns: [[ {field: 'id', title: 'ID', width: 50}, {field: 'name', title: 'Name', width: 100}, {field: 'email', title: 'Email', width: 150} ]] }); }); </script> </body> </html> ``` 3. Create a file named `upload.php` to handle the file upload and data insertion into the database: ```php <?php require_once 'PHPExcel/PHPExcel.php'; // Database connection details $host = 'localhost'; $username = 'your_username'; $password = 'your_password'; $database = 'your_database'; // File upload directory $targetDir = 'uploads/'; if (!is_dir($targetDir)) { mkdir($targetDir, 0777, true); } $targetFile = $targetDir . basename($_FILES["excelFile"]["name"]); move_uploaded_file($_FILES["excelFile"]["tmp_name"], $targetFile); $objPHPExcel = PHPExcel_IOFactory::load($targetFile); $worksheet = $objPHPExcel->getActiveSheet(); $conn = new mysqli($host, $username, $password, $database); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } foreach ($worksheet->getRowIterator() as $row) { $rowData = []; $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); foreach ($cellIterator as $cell) { $rowData[] = $cell->getValue(); } $sql = "INSERT INTO excel_data (name, email) VALUES (?, ?)"; $stmt = $conn->prepare($sql); $stmt->bind_param("ss", $rowData[0], $rowData[1]); $stmt->execute(); } $conn->close(); unlink($targetFile); echo "Upload successful!"; ?> ``` 4. Create a file named `data.php` to fetch the data from the database and return it as JSON for the front-end grid: ```php <?php // Database connection details $host = 'localhost'; $username = 'your_username'; $password = 'your_password'; $database = 'your_database'; $conn = new mysqli($host, $username, $password, $database); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM excel_data"; $result = $conn->query($sql); $data = array(); while ($row = $result->fetch_assoc()) { $data[] = $row; } $conn->close(); echo json_encode($data); ?> ``` Make sure to replace `'your_username'`, `'your_password'`, and `'your_database'` with your actual database credentials. This example follows the MVC pattern by separating the front-end view (`index.php`), the controller (`upload.php`), and the model (`data.php`). Remember to include the PHPExcel library in the appropriate locations and adjust the file paths accordingly. I hope this example helps you with uploading an Excel file, storing the data in a database, and displaying it on the front-end using the MVC pattern and EasyUI framework. Let me know if you have any further questions!

相关推荐

最新推荐

recommend-type

使用phpexcel类实现excel导入mysql数据库功能(实例代码)

下面小编就为大家带来一篇使用phpexcel类实现excel导入mysql数据库功能(实例代码)。小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
recommend-type

php通过PHPExcel导入Excel表格到MySQL数据库的简单实例

下面小编就为大家带来一篇php通过PHPExcel导入Excel表格到MySQL数据库的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
recommend-type

phpexcel导入excel处理大数据(实例讲解)

直接写到PHPExcel 这个文件里面的。调用很简单。引入phpExcel 这个类传递对应的excel 文件的路径就好了 现在上传到指定的目录,然后加载上传的excel文件读取这里读取是的时候不转换数组了。注意:是Sheet可以多个...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

可见光定位LED及其供电硬件具体型号,广角镜头和探测器,实验设计具体流程步骤,

1. 可见光定位LED型号:一般可使用5mm或3mm的普通白色LED,也可以选择专门用于定位的LED,例如OSRAM公司的SFH 4715AS或Vishay公司的VLMU3500-385-120。 2. 供电硬件型号:可以使用常见的直流电源供电,也可以选择专门的LED驱动器,例如Meanwell公司的ELG-75-C或ELG-150-C系列。 3. 广角镜头和探测器型号:一般可采用广角透镜和CMOS摄像头或光电二极管探测器,例如Omron公司的B5W-LA或Murata公司的IRS-B210ST01。 4. 实验设计流程步骤: 1)确定实验目的和研究对象,例如车辆或机器人的定位和导航。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这