日期:2014-05-17 浏览次数:20750 次
var hostname = location.hostname; //主机名 /** ******** 导出功能函数 ****** */ /** * 浏览器判断 */ var Sys = {}; var ua = navigator.userAgent.toLowerCase(); if (window.ActiveXObject) Sys.ie = ua.match(/msie ([\d.]+)/)[1]; else if (document.getBoxObjectFor) Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1]; function containsArray(array, obj) { for (var i = 0; i < array.length; i++) { if (array[i] == obj) { return i; break; } } return -1; } Array.prototype.contains = function(obj) { return containsArray(this, obj); } function PrintTableToExcel(tableId) { var offsetLeftArray = new Array(); var cell;// 单元格Dom var col;// 单元格实际所在列 var cellStr;// 每个cell以row,col,rowSpan,colSpan,value,background形式 var cellStrArray = []; var objTab = document.getElementById(tableId); // 遍历第一次取出offsetLeft集合 for (var i = 0; i < objTab.rows.length; i++) { for (var j = 0; j < objTab.rows[i].cells.length; j++) { cell = objTab.rows[i].cells[j]; if (offsetLeftArray.contains(cell.offsetLeft) == -1) offsetLeftArray.push(cell.offsetLeft); } } offsetLeftArray.sort(function(x, y) { return parseInt(x) - parseInt(y); }); //alert("offsetLeft集合:" + offsetLeftArray.join(',')); // 遍历第二次生成cellStrArray for (var i = 0; i < objTab.rows.length; i++) { for (var j = 0; j < objTab.rows[i].cells.length; j++) { cell = objTab.rows[i].cells[j]; var project ;//该对象为获得批注信息,可根据需要取舍 if(cell.id){ project = getProjectById(cell.id.split("-")[2]); //alert(project.projectCode +"|"+project.projectName +"|"+project.projectManager+"|"+project.projectType+"|"+project.meetingAddress); } col = offsetLeftArray.contains(cell.offsetLeft); if(cell.id){ cellStr = i + '^' + col + '^' + cell.rowSpan + '^' + cell.colSpan + "^" + (Sys.firefox?cell.textContent:cell.innerText)+"^"+($(cell).css("background")==undefined? '-1':$(cell).css("background"))+"^"+project.projectCode +"^"+project.projectName +"^"+project.managerNames+"^"+(project.projectKind==null? '':project.projectKind) +"^"+project.meetingAddress; }else{ cellStr = i + '^' + col + '^' + cell.rowSpan + '^' + cell.colSpan + "^" + (Sys.firefox?cell.textContent:cell.innerText)+"^"+($(cell).css("background")==undefined? '-1':$(cell).css("background")); } //alert(cellStr); cellStrArray.push(cellStr); } } var str = cellStrArray.join('@'); var url = 'url' //你要要提交表单的地址 $("#exportStr").attr("value",str); $("#exportfullStr").attr("value",getfullMonthProjectsString); document.exportform.action = url; document.exportform.method = "post"; document.exportform.submit(); } /** * @return */ function getfullMonthProjectsString(){ var projects = allProjects.delRepeat(); var len = projects.length; var fullString = [] for (var i=0 ; i <len ; i++){ if (projects[i].fullMoon == '1'){ fullString.push(projects[i].projectName +":" + projects[i].managerNames); } } return fullString.join("@"); }
public class ExportExcel { private List<ExcelContent> parseStrToData(String contentstr) { List<ExcelContent> contents = new ArrayList<ExcelContent>(); String[] contentStrs = contentstr.split("@"); for (String str : contentStrs) { ExcelContent ec = new ExcelContent(); ExcelComments ecm = new ExcelComments(); String[] c = str.split("\\^"); if (StringUtils.isNotBlank(c[0])) { ec.setRowNo(Integer.valueOf(c[0])); } if (StringUtils.isNotBlank(c[1])) { ec.setColNo(Integer.valueOf(c[1])); } if (StringUtils.isNotBlank(c[2])) { ec.setRowSpan(Integer.valueOf(c[2])); } if (StringUtils.isNotBlank(c[3])) { ec.setColSpan(Integer.valueOf(c[3])); } if (StringUt