Home Backend Development PHP Tutorial Dwz与thinkphp整合下的数据导出到Excel实例_php实例

Dwz与thinkphp整合下的数据导出到Excel实例_php实例

Jun 07, 2016 pm 05:14 PM
excel thinkphp Export data Integrate

本文实例讲述了Dwz与thinkphp整合下的数据导出到Excel的方法。分享给大家供大家参考。具体方法如下:

这个问题困扰了我很久,终于还是自己写JQUERY把它搞掂了,希望能对遇到同样问题的人有所帮助,好吧,下面就是源代码:

jquery代码如下:

复制代码 代码如下:
$(function(){ 
 
        //_getIds方法就是获取已选的要导出的数据的ID,设了两个参数selectedIds--已选id的input名称,targetType-->碎片模式,默认是navTab,如果是dialog的自行修改 
function _getIds(selectedIds,targetType){ 
        var ids=""; 
        var $box=targetType=="dialog"?$.pdialog.getCurrent():navTab.getCurrentPanel(); 
        $box.find("input:checked").filter("[name='"+selectedIds+"']").each(function(i){ 
 
            var val=$(this).val(); 
            ids+=i==0?val:","+val;}); 
            return ids; 
        } 
        //导出excel的按钮 class=iconn,click时触发 
$(".iconn").click( 
function(){ 
//因为这个方法直运用到导出到excel 所以这里所需的参数变量我直接写死了 
var targetType="navTab"; 
var selectedIds="ids"; 
var postType="string";//批量选择的话,以文本的形式获取 
var ids=_getIds(selectedIds,targetType); 
if(!ids){ 
alertMsg.error($(".iconn").attr("warn")); 
return false; 
//alert("请选择要导出的数据!"); 
}else{ 
//将获取到的ids 传给后台处理 
window.open("__URL__/memberExport/ids/"+ids); 

 
}); 
});

PHP代码如下:
复制代码 代码如下:
//member成员信息导出到excel 
public function memberExport(){ 
    $id=$_REQUEST['ids'];//获取已选数据的ID 
    //echo $id; 
 
//在这里导出到excel我没有用到phpexcel,是自己写的,很简单,相信大家都明白是什么意思,根据自己需要自行修改就行了 
    $filename=date('Y-m-d'); 
    header("Pragma:public"); 
header("Expires:0"); 
header("Cache-Control:must-revalidate,post-check=0,pre-check=0"); 
header("Content-Type:application/force-download"); 
header("Content-Type:application/vnd.ms-execl;charset=gb2312"); 
header("Content-Type:application/octet-stream"); 
header("Content-Type:application/download"); 
header('Content-Disposition:attachment;filename="'.$filename.'.xls"'); 
header("Content-Transfer-Encoding:binary"); 
if(!$id){ 
$this->error('非法操作!'); 
}else{ 
 
$map['id']=array('in',$id); 
$title="用户名\t 姓名\t 部门\t 职务\t 身份证\t 职称\t 学历\t 毕业时间\t 录用时间"; 
$title=iconv('utf-8','gbk',$title); 
echo $title; 
set_time_limit(0); 
   $offset= 0; 
   $length=100; 
$Member = M('Member'); 
$list=$Member->where($map)->order('id desc')->select(); 
if(!$list){ 
$this->error('操作错误!'); 
}else{ 
foreach($list as $key=>$row){ 
echo "\n"; 
echo iconv('utf-8','gbk',$row['username'])."\t"; 
echo iconv('utf-8','gbk',$row['name'])."\t"; 
echo iconv('utf-8','gbk',$row['department'])."\t"; 
echo iconv('utf-8','gbk',$row['zhiwu'])."\t"; 
echo iconv('utf-8','gbk',$row['sfz'])."\t"; 
echo iconv('utf-8','gbk',$row['zhicheng'])."\t"; 
echo iconv('utf-8','gbk',$row['xueli'])."\t"; 
echo iconv('utf-8','gbk',$row['bytime'])."\t"; 
echo iconv('utf-8','gbk',$row['lytime'])."\t"; 
 

$offset+=$length; 


}

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Apr 01, 2024 pm 07:46 PM

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

How to insert excel icons into PPT slides How to insert excel icons into PPT slides Mar 26, 2024 pm 05:40 PM

1. Open the PPT and turn the page to the page where you need to insert the excel icon. Click the Insert tab. 2. Click [Object]. 3. The following dialog box will pop up. 4. Click [Create from file] and click [Browse]. 5. Select the excel table to be inserted. 6. Click OK and the following page will pop up. 7. Check [Show as icon]. 8. Click OK.

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

See all articles