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

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

May 31, 2016 pm 06:15 PM
EX 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

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)

Use ddrescue to recover data on Linux Use ddrescue to recover data on Linux Mar 20, 2024 pm 01:37 PM

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

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

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.

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

Beelink EX graphics card expansion dock promises zero GPU performance loss Beelink EX graphics card expansion dock promises zero GPU performance loss Aug 11, 2024 pm 09:55 PM

One of the standout features of the recently launched Beelink GTi 14is that the mini PC has a hidden PCIe x8 slot underneath. At launch, the company said that this would make it easier to connect an external graphics card to the system. Beelink has n

How to get Douyin private message emoticons on WeChat? How to export the private message emoticon package? How to get Douyin private message emoticons on WeChat? How to export the private message emoticon package? Mar 21, 2024 pm 10:01 PM

With the continuous rise of social media, Douyin, as a popular short video platform, has attracted a large number of users. On Douyin, users can not only show their lives but also interact with other users. In this interaction, emoticons have gradually become an important way for users to express their emotions. 1. How to get Douyin private message emoticons on WeChat? First of all, to get private message emoticons on the Douyin platform, you need to log in to your Douyin account, then browse and select the emoticons you like. You can choose to send them to friends or collect them yourself. After receiving the emoticon package on Douyin, you can long press the emoticon package through the private message interface, and then select the "Add to Emoticon" function. In this way, you can add this emoticon package to Douyin’s emoticon library. 3. Next, we need to add the words in the Douyin emoticon library

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

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.

See all articles