excel csv 导出

本文介绍了一种使用PHPExcel库将数据导出为Excel和CSV文件的方法。通过具体代码示例展示了如何设置文件标题、字段名及数据内容,并实现文件下载。
    public function result_export($title,$list,$field){
//调用PHP_Excel
Vendor("PhpExcel.PHPExcel");
$objExcel = new PHPExcel(); 
$objWriter = new PHPExcel_Writer_Excel2007($objExcel);
$objExcel->setActiveSheetIndex(0);
$objActSheet = $objExcel->getActiveSheet(); 
$objActSheet->setTitle($title);
$letter = 'A';
foreach($field as $values){
$objActSheet->setCellValue($letter.'1',$values);
++$letter;
}
if(is_array($list)){
foreach($list as $k=>$v){
$letter = 'A';
$k = $k+2;
reset($field);
foreach($field as $key=>$value){
$objActSheet->setCellValueExplicit($letter.$k,$v[$key],PHPExcel_Cell_DataType::TYPE_STRING);//setCellValue($letter.$k,$v[$key])
++$letter;
}
}
}
$objExcel->setActiveSheetIndex(0);
spl_autoload_register(array('Think','autoload'));//必须的,不然ThinkPHP和PHPExcel会冲突
header("Content-Type:application/force-download"); 
header("Content-Type:application/octet-stream"); 
header("Content-Type:application/download");
header('Content-Disposition:inline;filename="'.mb_convert_encoding($title,'gb2312','UTF-8').'.xlsx"');
header("Content-Transfer-Encoding: binary");
header("Last-Modified:".gmdate("D, d M Y H:i:s")."GMT");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Pragma: no-cache"); 
$objWriter->save('php://output');
}
   
    public function result_export_csv($title,$list,$field){
$filename = $title.".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');
        $data = implode(',',$field).PHP_EOL;
        if(is_array($list)){
foreach($list as $k=>$v){
reset($field);
                $row = '';
foreach($field as $key=>$value){
$row .= $v[$key].',';
}
                $data .= rtrim($row,',').PHP_EOL;
}
}
        echo $data;
}
<table align="center" border="0" cellpadding="0" cellspacing="0" class="tableForm" style="table-layout: fixed;"> <colgroup> <col width="80" /> <col /><!--hide4phone.start--> <col width="80" /> <col width="380" /><!--hide4phone.end--> </colgroup> <tbody> <tr> <td style="text-align: right;">&nbsp;<span style="color: rgb(255, 0, 0);">*</span>Subject:</td> <td dbf.type="required" id="dbf.subject">&nbsp;</td> <!--show4phone.start></tr><tr><show4phone.end--> <td style="text-align: right;">&nbsp;Status:</td> <td><span id="mapping.dbf.procXSource">&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Responsor: <span id="mapping.dbf.responsorSource">&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Participants: <span id="mapping.dbf.participantsSource">&nbsp;</span></td> </tr> </tbody> </table> <div>&nbsp;</div> <div style="text-align: center;"> <h1><img src="../common/logo.png" /> [Form Name]</h1> </div> <div>[Design form here, based on the template below, or customized by yourself after the template removed]</div> <table align="center" border="0" cellpadding="0" cellspacing="0" class="tableListBorder" style="table-layout: fixed;"> <colgroup> <col width="130" /> <col /><!--hide4phone.start--> <col width="130" /> <col width="330" /><!--hide4phone.end--> </colgroup> <tbody> <tr> <td colspan="4" colspan4phone="2" dbf.source="" dbf.type="" style="background-color: lightyellow;">&nbsp;<strong>[Brief Information]</strong></td> </tr> <tr> <td class="fieldLabel" style="text-align: center; width: 147px;"><span style="color: red;">*</span>&nbsp;username</td> <td id="username" style="width: 210px;">&nbsp;</td> <!--show4phone.start--> </tr> <tr><!--show4phone.end--> <td class="fieldLabel" style="text-align: center; width: 63px;"><span style="color: red;">*</span>&nbsp;id</td> <td id="ID" style="width: 254px;">&nbsp;</td> </tr> <tr> <td class="fieldLabel" style="text-align: center;">项目名称</td> <td id="项目名称" style="width: 210px;">&nbsp;</td> <td class="fieldLabel" style="text-align: center;">装置名称</td> <td id="装置名称" style="width: 254px;">&nbsp;</td> </tr> <tr> <td class="fieldLabel" style="text-align: center;">Customer Name</td> <td id="CustomerName" style="width: 210px;">&nbsp;</td> <td class="fieldLabel" style="text-align: center;">E-NO/序列号</td> <td id="ENO号" style="width: 254px;">&nbsp;</td> </tr> <tr> <td class="fieldLabel" style="text-align: center;">产品描述</td> <td id="产品描述" style="width: 210px;">&nbsp;</td> <td class="fieldLabel" style="text-align: center;">Remark</td> <td id="Remark" style="width: 254px;">&nbsp;</td> </tr> <tr> <td class="fieldLabel" style="text-align: center;">Subject</td> <td id="subjectid" style="width: 210px;">&nbsp;</td> <td class="fieldLabel" dbf.source="" dbf.type="" id="" style="text-align: center;">&nbsp;</td> <td dbf.source="" dbf.type="" id="" style="width: 254px;">&nbsp;</td> </tr> <tr> <td colspan="4" colspan4phone="2" dbf.source="" dbf.type="" style="background-color: lightyellow;"><strong>&nbsp;</strong><strong>[Detailed Information]</strong></td> </tr> </tbody> </table> <div style="text-align: center; margin: 20px 0;">&nbsp; &nbsp; &nbsp; &nbsp; <input id="idslist" name="idslist" type="hidden" /> &nbsp;<input id="sql内容" name="sql内容" type="hidden" /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <strong> <input id="check" name="check" onclick="clickData()" type="button" value="check记录" /> </strong> <strong> <input id="check2" name="check2" onclick="downloadCSV()" type="button" value="下载结果" /> </strong></div> <!-- ==================== 移动端表格占位(暂不使用)==================== --><!-- ==================== 查询结果表格容器 ==================== --> <div id="resultTableContainer" style="margin-top: 20px; padding: 0 10px; min-height: 20px;"><!-- 动态表格将插入到这里 --></div> <div class="slide4phone2" id="reptable" style="display:none;"> <table align="center" border="0" cellpadding="0" cellspacing="0" class="tableListBorder2" style="width: 1300px;"> </table> </div> <!-- ==================== 核心脚本:查询与渲染 ==================== --><script language="javascript"> function clickData() { if (window.__isQuerying) { console.warn("请勿频繁点击!"); return; } window.__isQuerying = true; try { // 获取所有输入框的值 var projectName = $("项目名称")?.value ? $("项目名称").value().trim() : ""; var deviceName = $("装置名称")?.value ? $("装置名称").value().trim() : ""; var customerName = $("CustomerName")?.value ? $("CustomerName").value().trim() : ""; var enonumber = $("ENO号")?.value ? $("ENO号").value().trim() : ""; // 关键字段 var remark = $("Remark")?.value ? $("Remark").value().trim() : ""; var productDesc = $("产品描述")?.value ? $("产品描述").value().trim() : ""; var formsubject = $("subjectid")?.value ? $("subjectid").value().trim() : ""; /** * 安全转义 SQL 单引号 */ function escapeSql(str) { if (typeof str !== 'string' && typeof str !== 'number') return ''; return String(str).replace(/'/g, "''"); } // 构建模糊匹配模式:必须加 %% var pName = '%' + escapeSql(projectName) + '%'; var dName = '%' + escapeSql(deviceName) + '%'; var cName = '%' + escapeSql(customerName) + '%'; var enoNum = '%' + escapeSql(enonumber) + '%'; // ✅ 必须加 %% var rmk = '%' + escapeSql(remark) + '%'; var prodDesc = '%' + escapeSql(productDesc) + '%'; var subj = '%' + escapeSql(formsubject) + '%'; var subj2 = '%-' + escapeSql(formsubject) + '%'; // ✅ 核心修复点:清理 ENO序列号 中的换行、空格、制表符 const cleanedEnoField = ` REPLACE( REPLACE( REPLACE( ISNULL([ENO序列号], ''), CHAR(10), ''), CHAR(13), ''), ' ', '') `; // 主 SQL 查询语句 var sql = `SELECT TOP 100 Subject, Status, 申请人, 申请日期, 产品类别, 其他, type, 内勤, 系统, customer, ProjectName, DeviceName, 新产品, [ENO序列号], 目标价, 数量, 产地, 含税报价, HandlerRemark, Remark, 描述 FROM X_BPM_DWH_819_InquiryLines WHERE ISNULL(ProjectName, '') LIKE '${pName}' AND ISNULL(DeviceName, '') LIKE '${dName}' AND ISNULL(customer, '') LIKE '${cName}' AND ${cleanedEnoField} LIKE '${enoNum}' AND ISNULL(Remark, '') LIKE '${rmk}' AND ISNULL(描述, '') LIKE '${prodDesc}' AND ( ISNULL(Subject, '') LIKE '${subj}' OR ISNULL(Subject, '') LIKE '${subj2}' ) ORDER BY 申请日期 DESC `; alert( sql); // ⚠️ 打开浏览器控制台查看是否真包含 %888888% // 执行查询 var rawResult = service("common.js", "getDbsRecords", sql, "array"); let arr = parseServiceResult(rawResult); renderTable(arr); } catch (e) { console.error("【查询失败】", e); alert("查询出错:" + (e.message || e)); document.getElementById("resultTableContainer").innerHTML = ` <div style="color:red;text-align:center;padding:10px;"> ❌ ${e.message || e} </div> `; } finally { window.__isQuerying = false; } } /** * 安全解析 service 返回的结果 * 支持:合法JSON / 非法JSON / JS数组字面量 / 字符串化数组 / null等 */ function parseServiceResult(rawResult) { console.log("【原始返回类型】", typeof rawResult); console.log("【原始内容】", rawResult); // 情况1:已经是数组 if (Array.isArray(rawResult)) { console.log("✅ 已识别为原生数组"); return rawResult; } // 情况2:null/undefined/false if (rawResult == null || rawResult === 'null' || rawResult === 'undefined') { console.warn("⚠️ 返回为空值"); return []; } // 转为字符串处理 let str = String(rawResult).trim(); if (!str) { console.warn("⚠️ 返回空字符串"); return []; } // 情况3:可能是HTML错误页(常见于服务异常) if (str.startsWith('<') || str.includes('<html') || str.toLowerCase().includes('error') || str.includes('Exception')) { console.error("🔴 返回了HTML错误页!", str.substring(0, 200)); throw new Error('服务端错误,请检查SQL语法或联系管理员'); } /** * 数据清洗函数:修复各种非法字符 */ function clean(str) { return str .replace(/\\\\/g, '\\') // 修复多个反斜杠 .replace(/"/g, '\\"') // 先转义双引号 .replace(/'/g, '"') // 单引号 → 双引号 .replace(/\\"/g, '"') // 还原正常引号 .replace(/\\n/g, '\\n') // 显式换行 .replace(/\\r/g, '\\r') .replace(/\\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') .replace(/\t/g, '\\t') .replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, '') // 移除控制字符 .replace(/^"(\[.*\])"$/, '$1') // 去掉 "[...]" 外层引号 .replace(/^"(\{.*\})"$/, '$1') .replace(/,\s*}/g, '}') // 去除对象尾部逗号 .replace(/,\s*]/g, ']'); // 去除数组尾部逗号 } // 尝试多种解析方式 const parsers = [ // 方式1:直接JSON.parse () => JSON.parse(str), // 方式2:清洗后再解析 () => JSON.parse(clean(str)), // 方式3:作为JS表达式执行(仅限可信环境) () => new Function(`return (${str});`)(), // 方式4:进一步清理后尝试 () => JSON.parse(clean(str).replace(/""/g, '"').replace(/"\s+:/g, '":').replace(/:\s+"/g, ':"')) ]; for (let i = 0; i < parsers.length; i++) { try { const result = parsers[i](); if (Array.isArray(result)) { console.log(`✅ 第 ${i+1} 种方式解析成功`); return result; } // 兼容 { data: [...] } 结构 if (result && Array.isArray(result.data)) return result.data; if (result && Array.isArray(result.rows)) return result.rows; } catch (e) { console.warn(`📌 方式 ${i+1} 解析失败`, e.message); } } // 情况5:手动解析简单二维数组字符串 [[...],[...]] if (/^\[\s*$$[^$$]*$\s*(,\s*$$[^$$]*$)*\s*\]$/.test(str)) { try { console.log("🔍 检测到疑似二维数组字符串,尝试手动解析"); const rows = str.match(/$[^$$]*$/g) || []; return rows.map(row => { return row.replace(/^\[/, '').replace(/\]$/, '') .split(',') .map(field => field.trim().replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1')); }).filter(r => r.length > 0); } catch (e) { console.error("手动解析失败", e); } } // 所有方式都失败 console.error("🔴 所有解析方式均失败", { raw: rawResult, cleaned: clean(str) }); throw new Error('返回数据格式异常,无法解析。请检查SQL是否正确或联系开发人员。'); } /** * 渲染查询结果为表格 */ function renderTable(arr) { var container = document.getElementById("resultTableContainer"); if (!container) return; // 清空容器 container.innerHTML = ''; if (!arr || arr.length === 0) { container.innerHTML = ` <p style="text-align:center;color:#999;font-style:italic;padding:20px;"> 📭 未找到匹配的数据。 </p> `; return; } // 创建表格 var table = document.createElement('table'); table.className = 'tableListBorder'; table.style.width = '100%'; table.style.tableLayout = 'fixed'; table.setAttribute('border', '1'); table.setAttribute('cellpadding', '6'); table.setAttribute('cellspacing', '0'); table.style.fontFamily = 'Arial, sans-serif'; table.style.fontSize = '13px'; // 表头 var thead = document.createElement('thead'); var headerRow = document.createElement('tr'); var headers = [ "Subject", "Status", "申请人", "申请日期", "产品类别", "其他", "类型", "内勤", "系统", "客户", "项目名称", "装置名称", "新产品", "E-NO/序列号", "目标价", "数量", "产地", "含税报价", "处理备注", "备注", "描述" ]; headers.forEach(function(text) { var th = document.createElement('th'); th.style.backgroundColor = '#f5f5f5'; th.style.textAlign = 'center'; th.style.padding = '10px'; th.style.whiteSpace = 'nowrap'; th.style.fontWeight = 'bold'; th.textContent = text; headerRow.appendChild(th); }); thead.appendChild(headerRow); table.appendChild(thead); // 表体 var tbody = document.createElement('tbody'); arr.forEach(function(row, index) { if (!row || !Array.isArray(row) && typeof row !== 'object') { console.warn(`第 ${index} 行数据异常`, row); return; } var tr = document.createElement('tr'); Object.values(row).forEach(function(cell) { var td = document.createElement('td'); td.style.padding = '8px'; td.style.borderTop = '1px solid #eee'; td.style.wordBreak = 'break-word'; td.style.maxWidth = '200px'; td.textContent = cell == null ? '' : String(cell).trim(); tr.appendChild(td); }); tbody.appendChild(tr); }); table.appendChild(tbody); container.appendChild(table); console.log(`✅ 成功渲染 ${arr.length} 行数据`); } /** * 将当前查询结果导出CSV 文件 */ function downloadCSV() { if (!currentQueryResult || currentQueryResult.length === 0) { alert("没有可下载的数据,请先执行查询。"); return; } // 定义表头(中文标题) const headers = [ "Subject", "Status", "申请人", "申请日期", "产品类别", "其他", "类型", "内勤", "系统", "客户", "项目名称", "装置名称", "新产品", "E-NO/序列号", "目标价", "数量", "产地", "含税报价", "处理备注", "备注", "描述" ]; // 映射原始字段名(必须与 SQL 查询顺序一致) const fieldKeys = [ "Subject", "Status", "申请人", "申请日期", "产品类别", "其他", "type", "内勤", "系统", "customer", "ProjectName", "DeviceName", "新产品", "ENO序列号", "目标价", "数量", "产地", "含税报价", "HandlerRemark", "Remark", "描述" ]; // 构建 CSV 内容 const BOM = '\uFEFF'; // 支持中文 Excel 打开不乱码 let csv = []; // 添加表头 csv.push(headers.join(',')); // 添加每一行数据 currentQueryResult.forEach(row => { const values = fieldKeys.map(key => { let val = ''; if (Array.isArray(row)) { // 如果是数组格式,按索引取值 val = row[fieldKeys.indexOf(key)] || ''; } else { // 如果是对象格式,按 key 取值 val = row[key] || ''; } // 转字符串 + 处理双引号和逗号 val = String(val || '').trim(); // CSV 中双引号要转义成两个双引号,并整体用双引号包裹 if (val.includes(',') || val.includes('"') || val.includes('\n')) { val = `"${val.replace(/"/g, '""')}"`; } return val; }); csv.push(values.join(',')); }); // 生成文件内容 const csvContent = BOM + csv.join('\n'); // 创建 Blob 对象 const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); // 创建下载链接 const link = document.createElement('a'); const url = URL.createObjectURL(blob); const now = new Date().toISOString().slice(0, 19).replace(/:/g, '-'); // 当前时间作为文件名 link.setAttribute('href', url); link.setAttribute('download', `查询结果_${now}.csv`); link.style.visibility = 'hidden'; // 添加到 DOM 并触发点击 document.body.appendChild(link); link.click(); // 清理内存 document.body.removeChild(link); URL.revokeObjectURL(url); console.log(`✅ 已下载 ${currentQueryResult.length} 行数据为 CSV`); } </script> <div id="resultTableContainer" style="margin-top: 20px; overflow-x: auto;">&nbsp;</div>
10-22
function initTable_work() { // 獲取當前顯示的stage var wipSource = []; $.ajax({ url: 'docmanage.aspx?type=task/stageJson', async: false, type: "get", data: {}, success: function (data, status) { for (var item of data){ wipSource.push({value:item,text:item}) } } }); // 获取PDE人員 var pdeSource = []; $.ajax({ url: 'docmanage.aspx?type=task/pdeJson', async: false, type: "get", data: {}, success: function (data, status) { for (var item of data){ pdeSource.push({value:item.value,text:item.text}) } } }); //獲取發文難度 var docDifficult=[]; $.ajax({ url: 'docmanage.aspx?type=task/docDifficult', async: false, type: "get", data: {}, success: function (data, status) { for (var item of data){ docDifficult.push({value:item,text:item}) } } }); // 預設模式:<i class="bi bi-gear m-l-5"> // 手動模式:<i class="bi bi-wrench m-l-5"></i> // 預估模式:<i class="bi bi-bell m-l-5"></i> // 獲取係統中的wip_mode的值 默認是預設模式 var wip_mode = '<i class="bi bi-gear m-l-5" value="1" title="預設" onclick=updateWipMode(1)>' var process_mode='<i class="bi bi-arrow-clockwise" onclick=freshProcess()>' $.ajax({ url: 'docmanage.aspx?type=task/getWipMode', async: false, type: "get", data: {}, success: function (data, status) { // 手動模式: if (data[0]['mode'] === '2'){ wip_mode = '<i class="bi bi-wrench m-l-5" value="2" title="手動" onclick=updateWipMode(2)>' } // 預估模式: if (data[0]['mode'] === '3'){ wip_mode = '<i class="bi bi-bell m-l-5" value="3" title="預估" onclick=updateWipMode(3)>' } // 存儲wip_mode的值 localStorage.setItem('wip_mode',data[0]['mode']) } }); // 查詢參數 var savedQueryParams = JSON.parse(localStorage.getItem('queryParams')) || {}; var columnArr = [ { field: 'state', checkbox: true, align: 'center', valign: 'middle' }, { title: '操作', field: 'operate', align: 'center', switchable:false, align: 'center', events: window.operateEvents_work, formatter: operateFormatter_work }, { title: '任務No.', field: 'doc_no', align: 'center', switchable:false, sortable: true }, { title: '&nbsp;&nbsp;&nbsp;&nbsp;日期&nbsp;&nbsp;&nbsp;&nbsp;', field: 'create_time', align: 'center', switchable:false, sortable: true }, { title: '廠內料號', field: 'fact_partnum', switchable:false, sortable: true, escape: true, align: 'center' }, { title: '疊構', field: 'doc_products', switchable:false, sortable: true, escape: true, align: 'center' }, { title: '特殊設計', field: 'special_design', switchable:false, sortable: true, escape: true, align: 'center' }, { title: '產品', field: 'doc_product', switchable:false, sortable: true, escape: true, align: 'center' }, { title: '發文難度', field: 'difficulty', switchable:false, sortable: true, escape: true, editable: { noEditFormatter: function (value, row, index, field){ return false; }, source: docDifficult, type: 'select', escape:true, title: '發文難度', validate: function (v) { if (!v) return '發文難度不能为空!'; } }, align: 'center' },{ title: 'PDE', field: 'pde_finish_user', switchable:false, escape:true, sortable: true, editable: { noEditFormatter: function (value, row, index, field){ return false; }, source: pdeSource, type: 'select', escape:true, title: 'PDE人員', validate: function (v) { if (!v) return 'PDE人員不能为空!'; } }, align: 'center' }, { title: '&nbsp;&nbsp;&nbsp;&nbsp;備註 &nbsp;&nbsp;&nbsp;&nbsp;', field: 'explain', switchable: false, escape:true, sortable: true, editable: { noEditFormatter: function (value, row, index, field){ return false; }, type: 'textarea', escape:true, title: '備註', validate: function (v) { if (!v) return '備註不能为空!'; } }, formatter: function (value) { return '<span data-toggle="tooltip" title="' + value +'">' + value.substring(0, 10) +'</span>' }, align: 'center' },{ title: '流程'+process_mode, field: 'doc_process', switchable:false, sortable: true, align: 'center' }, { title: 'WIP'+wip_mode, field: 'wip', switchable:false, sortable: true, editable: { noEditFormatter: function (value, row, index, field){ return false; }, type: 'select', escape:false, title: 'WIP', source: wipSource, validate: function (v) { if (!v) return 'WIP不能为空!'; } }, align: 'center' }, { title: '上傳情形', field: 'uploadScenarios', switchable:false, sortable: true, align: 'center', formatter: formatter_uploadScenarios }, { title: '工單檔案', field: 'uploadArchive', switchable:false, sortable: true, align: 'center', visible: false }, { title: '工單完成狀態', field: 'uploadfinishStatus', switchable:false, sortable: true, align: 'center', visible: false },{ title: '工單備註', field: 'uploadRemark', switchable:false, sortable: true, align: 'center', visible: false }, { title: '狀態', field: 'stages_status', switchable:false, sortable: true, align: 'center', formatter: formatter_status_vb }, { title: '發文', field: 'stage_type', switchable:false, align: 'center', formatter: function(value){return '<span>'+value+'&nbsp;<i class="bi bi-info-circle"></i></span>'}, events:window.operateEvents_work }] //從數據庫中獲取列 根據fact_no 獲取不同的stage $.ajax({ url: 'docmanage.aspx?type=task/stageJson', async: false, type: "get", data: {}, success: function (data, status) { $.each(data, function (key, value) { columnArr.push({ title: value, field: value, align: 'center', valign: 'middle', events:checkboxEvents_work, formatter: checkboxFormatter_work }); }); } }); $table_work.bootstrapTable('destroy').bootstrapTable({ url:'docmanage.aspx?type=task/dataJson', method:'get', cache: false, showColumnDynamic:false,//篩選設定 該項為自定義的 showColumns:true,//顯示列 showRefresh:true,//顯示刷新按鈕 striped: false,//是否顯示行間隔色 toolbar:"#queryForm_docwork", pageNumber: 1,//初始化第一頁 pagination: true,//是否分頁 sidePagination : 'server',//server:服务器端分页|client:前端分页 pageSize : 20,//单页记录数 pageList:[10,20,50],//分页步进值 sortable:true, sortOrder:'asc', height: document.documentElement.clientHeight-200, showExport: true, Icons : 'glyphicon-export', exportDataType: 'all', //选择导出数据的范围,默认basic:只导出当前页的表格数据;all:导出所有数据;selected:导出选中的数据 //导出文件类型,因为导出png文件时会出现忽略的列也显示;导出PDF文件出现中文乱码的问题,所以根据需要只支持Excel文件类型即可 exportTypes: ['csv'], //['json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'pdf'] //导出设置 exportOptions: { ignoreColumn: [0], //忽略某一列的索引 //重新format數據 onCellData: function(cell, rowIndex, colIndex, rowData, cellData){ //如果rowData 以...結尾 說明內容被截斷 從show-info中取出信息 if(rowIndex >= 1 && rowData.endsWith('...')){ return $(cell[0]).children().children().attr('show-info') } // return rowData; if(!isNaN(rowData)){ return "\u200B"+rowData ; } else{ return rowData; } },如何在导出时显示uploadArchive、uploadfinishStatus、uploadRemark栏位
11-21
<!--#Include file="../include/db.inc"--> <html> <head> <title>各区必修课数据查询</title> <style> .t_i{width:1520px; height:auto; float:center; border-right:0px solid #000; border-top:1px solid #000} .t_i_h{width:100%; overflow-x:hidden; background:buttonface;} .t_i_h table{width:1500px;} .t_i_h table td{border-right:1px solid #000; border-bottom:1px solid #000; height:20px; text-align:center} .cc{width:100%; height:625px; border-bottom:1px solid #000; border-right:1px solid #000; background:#fff; overflow:auto;} .cc table{width:1500px; } .cc table td{height:25px; border-bottom:1px solid #000; border-right:1px solid #000; text-align:center} </style> <script> function aa(){ var a=document.getElementById("cc").scrollTop; var b=document.getElementById("cc").scrollLeft; document.getElementById("hh").scrollLeft=b; } </script> <link href="../images/cssexamin.css" rel="stylesheet" type="text/css"> <script src="laydate/laydate.js"></script> </head> <body class="banquan" background="../images/11-08.gif"> <table border="0" align="center" width="100%" cellpadding='0' valign="top"> <tr> <td align="center" width="100%"> <img src="../images/pic.jpg"> </td> </tr> </table> <br><br> <form action="" name="form1" method="post"> <table width="750" border="0" align="center" cellpadding="2" cellspacing="1" class="banquan"> <tr> <td width="8%"><font face="Arial">Emp.NO:</font></td> <td width="6%" align="center"> <input name="EmpNo" type="text" id="EmpNo" size="15"> </td> <td>&nbsp;</td> <td width="11%"><font face="Arial">Section:</font></td> <td width="10%" align="center"> <font size="2" face="Arial"> <select name="Section"> <option value=""></option> <option value="TF1">TF1</option> <option value="TF2">TF2</option> <option value="CMP1">CMP1</option> <option value="CVD1">CVD1</option> <option value="PVD1">PVD1</option> <option value="CMP2">CMP2</option> <option value="CVD2">CVD2</option> <option value="PVD2">PVD2</option> <option value="4F">4F</option> <option value="CMP3">CMP3</option> <option value="TF3">TF3</option> <option value="DIFF1">DIFF1</option> <option value="IMP1">IMP1</option> <option value="DIFF2">DIFF2</option> <option value="IMP2">IMP2</option> <option value="MIDDLE">MIDDLE</option> <option value="ETCH3">ETCH3</option> <option value="LITHO3">LITHO3</option> <option value="ETCH1">ETCH1</option> <option value="ETCH2">ETCH2</option> <option value="LITHO1">LITHO1</option> <option value="SCAN">SCAN</option> <option value="LITHO2">LITHO2</option> <option value="WFS(AL)">WFS(AL)</option> <option value="WFS(CU)">WFS(CU)</option> <option value="WAT">WAT</option> <option value="OQI">OQI</option> <option value="Transfer Team">Transfer Team</option> <option value="ALL">ALL</option> </select> </font> </td> <td>&nbsp;</td> <td width="10%" align="center"><font face="Arial">Shift:</font></td> <td width="10%" align="center"> <font size="2" face="Arial"> <select name="Shift"> <option value=""></option> <option value="DA">DA</option> <option value="DB">DB</option> <option value="NA">NA</option> <option value="NB">NB</option> <option value="Nor">Nor</option> </select> </font> </td> <td>&nbsp;</td> <td width="10%" align="center"><font face="Arial">报道日期:</font></td> <td width="6%" align="center"> <input name="Onboard" type="text" id="Onboard" size="15"> </td> <td>&nbsp;</td> <td width="8%" align="center"> <input type="submit" name="btnEnter" value="Query"> </td> </tr> </table> </form> <% EmpNo=trim(request("EmpNo")) Section=trim(request("Section")) Shift=trim(request("Shift")) Onboard=trim(request("Onboard")) ' response.write "Onboard=" & Onboard & "<br>" %> <!--table--> <div class="t_i" style="position:absolute;left:200px"> <div class="t_i_h" id="hh"> <div class="ee"> <table cellpadding="0" cellspacing="0" border="0"> <tr bgcolor="#336666"> <td width="7%" align="center" rowspan="2"><font color="#FFFFFF" size="2" face="Arial">Emp.NO</font></td> <td width="6.5%" align="center" rowspan="2"><font color="#FFFFFF" size="2" face="Arial">Name</font></td> <td width="6.5%" align="center" rowspan="2"><font color="#FFFFFF" size="2" face="Arial">Section</font></td> <td width="8%" align="center" rowspan="2"><font color="#FFFFFF" size="2" face="Arial">Report day</font></td> <!-- <td width="18%" align="center" colspan="3"><font color="#FFFFFF" size="2" face="Arial">新人训</font></td> --> <td width="18%" align="center" colspan="3"><font color="#FFFFFF" size="2" face="Arial">必修</font></td> <!-- <td width="18%" align="center" colspan="3"><font color="#FFFFFF" size="2" face="Arial">当前工作岗位</font></td> <td width="18%" align="center" colspan="3"><font color="#FFFFFF" size="2" face="Arial">跨岗位</font></td> --> </tr> <tr bgcolor="#336666"> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">应完成</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">实际完成</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">完成Ratio</font></td> <!-- <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">应完成</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">实际完成</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">完成Ratio</font></td> --> <!-- <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">应完成</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">实际完成</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">完成Ratio</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">应完成</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">实际完成</font></td> <td width="6%" align="center"><font color="#FFFFFF" size="2" face="Arial">完成Ratio</font></td> --> </tr> </table> </div> </div> <div class="cc" id="cc" onscroll="aa()"> <table cellpadding="0" cellspacing="0" border="0"> <% if Section = "" then Condition1 = "" elseif Section = "CMP1" then Condition1 = " AND sect='CMP1' " elseif Section = "CVD1" then Condition1 = " AND sect='CVD1' " elseif Section = "PVD1" then Condition1 = " AND sect='PVD1' " elseif Section = "CMP2" then Condition1 = " AND sect='CMP2' " elseif Section = "CVD2" then Condition1 = " AND sect='CVD2' " elseif Section = "PVD2" then Condition1 = " AND sect='PVD2' " elseif Section = "4F" then Condition1 = " AND sect='4F' " elseif Section = "CMP3" then Condition1 = " AND sect='CMP3' " elseif Section = "TF3" then Condition1 = " AND sect='TF3' " elseif Section = "DIFF1" then Condition1 = " AND sect='DIFF1' " elseif Section = "IMP1" then Condition1 = " AND sect='IMP1' " elseif Section = "DIFF2" then Condition1 = " AND sect='DIFF2' " elseif Section = "IMP2" then Condition1 = " AND sect='IMP2' " elseif Section = "MIDDLE" then Condition1 = " AND sect='MIDDLE' " elseif Section = "ETCH3" then Condition1 = " AND sect='ETCH3' " elseif Section = "LITHO3" then Condition1 = " AND sect='LITHO3' " elseif Section = "ETCH1" then Condition1 = " AND sect='ETCH1' " elseif Section = "ETCH2" then Condition1 = " AND sect='ETCH2' " elseif Section = "LITHO1" then Condition1 = " AND sect='LITHO1' " elseif Section = "SCAN" then Condition1 = " AND sect='SCAN' " elseif Section = "LITHO2" then Condition1 = " AND sect='LITHO2' " elseif Section = "WFS(AL)" then Condition1 = " AND sect='WFS(AL)' " elseif Section = "WFS(CU)" then Condition1 = " AND sect='WFS(CU)' " elseif Section = "WAT" then Condition1 = " AND sect='WAT' " elseif Section = "OQI" then Condition1 = " AND sect='OQI' " elseif Section = "Transfer Team" then Condition1 = " AND sect='Transfer Team' " elseif Section = "TF1" then Condition1 = " AND sect='TF1' " elseif Section = "TF2" then Condition1 = " AND sect='TF2' " end if if EmpNo="" then Condition2="" else Condition2=" AND employee_no='"&EmpNo&"' " end if if Shift="" then Condition3="" else Condition3=" AND Shift='"&Shift&"' " end if if Onboard="" then Condition4="" else Condition4=" AND edittime LIKE '"&Onboard&"%' " end if ' response.write"Condition1="&Condition1&"<br>" n=0 sql=" SELECT employee_no, name, sect, substr(edittime,1,4)||'-'||substr(edittime,5,2)||'-'||substr(edittime,7,2) edittime, basicttl, basic, Decode(basicttl,0,0,Round(basic/basicttl*100,0)) basicratio, "_ &" compulsoryttl, compulsory, Decode(compulsoryttl,0,0,Round(compulsory/compulsoryttl*100,0)) compulsoryratio, "_ &" mainttl, main, Decode(mainttl,0,0,Round(main/mainttl*100,0)) mainratio, crossttl, cross, Decode(crossttl,0,0,Round(cross/crossttl*100,0)) crossratio "_ &" FROM ( "_ &" SELECT employee_no, name, sect, edittime, "_ &" Count(CASE WHEN group_name='Basic' THEN course_id END) BasicTTL, "_ &" Count(CASE WHEN group_name='Basic' AND wr_certify=1 THEN course_id END) Basic, "_ &" Count(CASE WHEN group_name='Compulsory' THEN course_id END) CompulsoryTTL, "_ &" Count(CASE WHEN group_name='Compulsory' AND wr_certify=1 THEN course_id END) Compulsory, "_ &" Count(CASE WHEN certifygroup_type='Main Group' THEN course_id END) MainTTL, "_ &" Count(CASE WHEN certifygroup_type='Main Group' AND wr_certify=1 THEN course_id END) Main, "_ &" Count(CASE WHEN certifygroup_type='Cross Group' THEN course_id END) CrossTTL, "_ &" Count(CASE WHEN certifygroup_type='Cross Group' AND wr_certify||op_certify IN ('1NoNeed','1Pass') THEN course_id END) Cross "_ &" FROM MFG_TB_TRAINING_USER A, mfg_tb_newtraining_final_result B "_ &" WHERE A.employee_no=B.empno "_ &" AND status='A' "&Condition1&" "&Condition2&" "&Condition3&" "&Condition4&" "_ &" AND employee_no LIKE 'V%' "_ &" GROUP BY employee_no, name, sect, edittime "_ &" ) "_ &" ORDER BY employee_no " sql = " SELECT employee_no, name, sect, substr(edittime, 1, 4) || '-' || substr(edittime, 5, 2) || '-' || substr(edittime, 7, 2) AS edittime, safe_ttl, safe_completed, DECODE(safe_ttl, 0, 0, ROUND(safe_completed / safe_ttl * 100, 0)) AS saferatio FROM( SELECT employee_no, name, sect, edittime, COUNT(CASE WHEN group_name = 'Safe' THEN course_id END) AS safe_ttl, COUNT(CASE WHEN group_name = 'Safe' AND wr_certify = 1 THEN course_id END) AS safe_completed FROM MFG_TB_TRAINING_USER A JOIN mfg_tb_newtraining_final_result B ON A.employee_no = B.empno WHERE status = 'A' AND employee_no LIKE 'E068772' GROUP BY employee_no, name, sect, edittime) ORDER BY employee_no " 'response.write"Condition1="&sql&"<br>" set rs=conn.execute(sql) while not rs.eof if not rs.eof then EMPLOYEE_NO=rs("employee_no") NAME=rs("name") SECT=rs("sect") EDITTIME=rs("edittime") BASICTTL=rs("SAFE_TTL") BASIC=rs("SAFE_COMPLETED") BASICRATIO=rs("SAFERATIO") n=n+1 %> <tr bgcolor="#FFFFFF"> <td width="7%" align="center"><font color="#4091c4" size="2" face="Arial"><%=EMPLOYEE_NO%></font></td> <td width="6.5%" align="center"><font color="#4091c4" size="2" face="Arial"><%=NAME%></font></td> <td width="6.5%" align="center"><font color="#4091c4" size="2" face="Arial"><%=SECT%></font></td> <td width="8%" align="center"><font color="#4091c4" size="2" face="Arial"><%=EDITTIME%></font></td> <td width="6%" align="center"><a href="reportdata.asp?EMPLOYEE_NO=<%=EMPLOYEE_NO%>&GROUP_NAME=Basic&CERTIFYGROUP_TYPE=NULL"><font color="#4091c4" size="2" face="Arial"><%=BASICTTL%></font></td> <td width="6%" align="center"><font color="#4091c4" size="2" face="Arial"><%=BASIC%></font></td> <td width="6%" align="center"><font color="#4091c4" size="2" face="Arial"><%=BASICRATIO%>%</font></td> <!-- <td width="6%" align="center"><a href="reportdata.asp?EMPLOYEE_NO=<%=EMPLOYEE_NO%>&GROUP_NAME=Compulsory&CERTIFYGROUP_TYPE=NULL"><font color="#4091c4" size="2" face="Arial"><%=COMPULSORYTTL%></font></td> <td width="6%" align="center"><font color="#4091c4" size="2" face="Arial"><%=COMPULSORY%></font></td> <td width="6%" align="center"><font color="#4091c4" size="2" face="Arial"><%=COMPULSORYRATIO%>%</font></td> --> <!-- <td width="6%" align="center"><a href="reportdata.asp?EMPLOYEE_NO=<%=EMPLOYEE_NO%>&GROUP_NAME=NULL&CERTIFYGROUP_TYPE=MainGroup"><font color="#4091c4" size="2" face="Arial"><%=MAINTTL%></font></td> <td width="6%" align="center"><font color="#4091c4" size="2" face="Arial"><%=MAIN%></font></td> <td width="6%" align="center"><font color="#4091c4" size="2" face="Arial"><%=MAINRATIO%>%</font></td> <td width="6%" align="center"><a href="reportdata.asp?EMPLOYEE_NO=<%=EMPLOYEE_NO%>&GROUP_NAME=NULL&CERTIFYGROUP_TYPE=CrossGroup"><font color="#4091c4" size="2" face="Arial"><%=CROSSTTL%></font></td> <td width="6%" align="center"><font color="#4091c4" size="2" face="Arial"><%=CROSS%></font></td> <td width="6%" align="center"><font color="#4091c4" size="2" face="Arial"><%=CROSSRATIO%>%</font></td> --> </tr> <% end if rs.MoveNext wend if n<>"0" then if CDbl(round(ratioList/n,2))>0 and CDbl(round(ratioList/n,2))<1 then i="0" & round(ratioList/n,2) & "%" else i=round(ratioList/n,2) & "%" end if if CDbl(round(ratioList1/n,2))>0 and CDbl(round(ratioList1/n,2))<1 then j="0" & round(ratioList1/n,2) & "%" else j=round(ratioList1/n,2) & "%" end if else i=0 j=0 end if %> </table> </div> <table cellpadding="0" cellspacing="0" border="0"> <tr bgcolor="#FFFFFF"> <td colspan="16" align="left" width="1520" > &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </td> </tr> <tr bgcolor="#FFFFFF"> <td colspan="16" align="left"> <font size="3" face="Arial" color="#0000FF"><b> 当前显示记录:</b></font> <font face="Arial" size="3" color="red"> <b><%=n%></b> </font> <font size="3" face="Arial" color="#0000FF"><b>;&nbsp;&nbsp;当前工作岗位Ratio:</b></font> <font face="Arial" size="3" color="red"> <b><%=i%></b> </font> <font size="3" face="Arial" color="#0000FF"><b>;&nbsp;&nbsp;跨岗位Ratio:</b></font> <font face="Arial" size="3" color="red"> <b><%=j%></b> </font> </td> </tr> </table> <table border="0" width="100%"> <td>&nbsp;</td> <tr> <td width="100%" align="center"> <a href="setup.asp">--返 回--</a> </td> </tr> <tr> <td width="100%" align="center" class='banquan'> <font color="#666666">©Copyright&nbsp; Semiconductor Manufacturing International (Shanghai) Corp. <font color="#018ec6">2025 版权所有 ™</font> v1.0</font> </td> </tr> </table> </div> </table> <script> !function(){ laydate.skin('dahong');//切换皮肤,请查看skins下面皮肤库 laydate({elem: '#demo'});//绑定元素 }(); //日期范围限制 var start = { elem: '#start', format: 'YYYY-MM-DD', festival: true, //显示节日 max: '2099-06-16', //最大日期 istime: true, istoday: true, choose: function(datas){ end.min = datas; //开始日选好后,重置结束日的最小日期 end.start = datas //将结束日的初始值设定为开始日 } }; var end = { elem: '#end', format: 'YYYY-MM-DD', festival: true, //显示节日 max: '2099-06-16', istime: true, istoday: true, choose: function(datas){ start.max = datas; //结束日选好后,充值开始日的最大日期 } }; laydate(start); laydate(end); </script> </body> </html> 看看这个代码 ,我需要添加一个 导出按钮
09-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值