php导出excel

excel  php  

<?php
header ( "Content-type:application/vnd.ms-excel" );
header ( "Content-Disposition:filename=registration list.xls");
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>无标题文档</title>
<style>
td{
	text-align:center;
	font-size:12px;
	font-family:Arial, Helvetica, sans-serif;
	border:#1C7A80 1px solid;
	color:#152122;
	width:100px;
}
table,tr{
	border-style:none;
}
.title{
	background:#7DDCF0;
	color:#FFFFFF;
	font-weight:bold;
}
</style>
</head>

<body>
<table width='800' border='1'>
  <tr>
  	<td class='title'>报名ID</td>
    <td class='title'>姓名</td>
    <td class='title'>UID</td>
    <td class='title'>学号</td>
    <td class='title'>昵称</td>
    <?php if($type>=1){?>
    <td class='title'>职位</td>
    <?php }?>
    <td class='title'>单位</td>
    <td class='title'>手机</td>
    <td class='title'>QQ</td>
    <td class='title'>报名时间</td>
    <td class='title'>付款方式</td>
	 <?php if($type>=4){?>
    <td class='title'>报名级别</td>
	<?php }?>
	<?php if($type>=5){?>
    <td class='title'>最高学历</td>
	<td class='title'>意向类型</td>
	<td class='title'>意向专业</td>
	<?php }?>
  </tr>
  <?php foreach($list as $r): ?>
  <tr>
  	<td><?php echo $r['bmid']?></td>
    <td><?php echo $r['name']?></td>
    <td><?php echo $r['uid']?></td>
    <td><?php echo $r['studentid']?></td>
    <td><?php echo $r['nickname']?></td>
    <?php if($type>=1){?>
    <td><?php echo $r['position']?></td>
    <?php }?>
    <td><?php echo $r['company']?></td>
    <td><?php echo $r['mobile']?></td>
    <td><?php echo $r['qq']?></td>
    <td><?php echo date('Y-m-d H:i', $r['dateline'])?></td>
    <td><?php echo $r['pay']?></td>
	 <?php if($type>=4){?>
    <td><?php echo $r['level']?></td>
	<?php }?>
	 <?php if($type>=5){?>
    <td><?php echo $r['zuigaoxueli']?></td>
    <td><?php echo $r['yixiangleixing']?></td>
    <td><?php echo $r['yixiangzhuanye']?></td>        
	<?php }?>	
  </tr>
  <?php endforeach; ?>
</table>
</body>
</html>

php导出csv

csv  php  excel  

    //导出订单
    private function _export_collection($data_v)
    {
        $data = array();
        $up_status = $this->up_status();
        $progress_status = $this->progress_status();
        $mobile_status = $this->mobile_status();
        $cy_status=$this->cy_status();
        $data[] = array('手机号码', 'uid', '提交时间', '联系人', '公司名称', '机构类型', '当前职位', '所在地区', '工作年限', '擅长领域', '是否创业', '创业方向', '是否有课', '课程名称', '备注', '操作记录', '状态', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term', '来源', '电话有效性', '进展', '跟进备注', '分配对象');
        foreach ($data_v as $key => $mobile) {
            $i = 1;
			$data[] = array(
				"\t" . $v['mobile'],
				$v['uid'],
				date('Y-m-d H:i:s', $v['dateline']),
				$v['contact'],
				$v['company'],
				$v['organize'],
				$v['job'],
				$v['area'],
				$v['work_year'],
				$v['skill'],
				$v['cy'] >= 1 ? $cy_status[$v['cy']] : '',
				$v['cy_direction'],
				$v['video'] >= 1 ? $cy_status[$v['video']] : '',
				$v['video_name'],
				$v['remark'],
				$mobile['collection_log'][0]['dateline'] ? sprintf('%s %s %s',date('Y-m-d H:i:s', $mobile['collection_log'][0]['dateline']) , $mobile['collection_log'][0]['username'], str_replace(array(','),'|',$mobile['collection_log'][0]['remark'])) : '',
				$up_status[$v['status']],
				$v['utm_source'],
				$v['utm_medium'],
				$v['utm_campaign'],
				$v['utm_content'],
				$v['utm_term'],
				$v['source'],
				$v['mobile_status'] > 1 ? $mobile_status[$v['mobile_status']] : '',
				$v['progress'] == 0 ? '' : $progress_status[$v['progress']]['name'],
				$v['username_remark'],
				$v['ownership'],
			);
			$i = $i + 1;
        }
        fx_phpexcel_utl::export_csv($data);
    }


    // CVS导出速度快
    public static function export_csv($data)
    {
        $string = "";
        foreach ($data as $key => $value) {
            foreach ($value as $k => $val) {
                $value[$k]= str_replace(array(","), '|',  $value[$k]);
                $value[$k] = iconv('utf-8', 'gbk//IGNORE',  str_replace(array("\n", "\r"), '',  $value[$k]));
            }
            $string .= implode(",", str_replace(PHP_EOL, '',  $value)) . "\n"; //用英文逗号分开
        }
        $filename = date('Ymd') . '.csv'; //设置文件名
        header("Content-type:text/csv");
        header("Content-Disposition:attachment;filename=" . $filename);
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');
        echo $string;
    }

python excel转json

python  excel  

#!/usr/bin/python
#-*- coding: utf-8 -*-
import json, sys
import xlrd
from datetime import date, datetime
from collections import OrderedDict
import json
import codecs
reload(sys)
sys.setdefaultencoding('utf-8')
wb = xlrd.open_workbook(r'E:\dir\school\2.xlsx')
sheet_list = wb.sheet_names()
filename=1for sheet in sheet_list:
    print sheet
    convert_list = []
    sh = wb.sheet_by_name(sheet)
    title = sh.row_values(0)
    for rownum in range(1, sh.nrows):
        rowvalue = sh.row_values(rownum)
        single = OrderedDict()
        for colnum in range(0, len(rowvalue)):
            single[title[colnum]] = rowvalue[colnum]
        convert_list.append(single)

    j = json.dumps(convert_list,ensure_ascii=False,indent=2)
    f=file('E:\dir\school\json\{}.json'.format(filename), 'w')
    f.write(j)
    f.close()
    filename=filename+1