国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

excle報盤之導入報盤

2019-11-08 01:49:24
字體:
來源:轉載
供稿:網友

前端jsp:

	<div class="blockhead">					<span>導入報盤</span>										<form id="importForm" action="" method="post" enctype="multipart/form-data" style="float: right;margin-right: 20px;padding-top: 3px;">							<input type="file" name="textfield" class="file" style="width:170px;" id="textfield" height="22px"  onchange="checkFile(this)"  /> 							<a href="javascript:void(0)" style="background-color: #ff6600;margin-left: 0px;" onclick="importData()">導入</a>														</form>									</div>

function checkFile(file){		var filepath = file.value;		if(filepath ==""){			alert("請選擇文件");			return ;		}		filepath=filepath.substring(filepath.lastIndexOf('.')+1,filepath.length);		if(filepath != 'xls'){			mbox({				title : "系統提示",				message : "只能上傳指定的模板文件"			});			$("#importForm")[0].reset();		}	}	//報盤導入數據	function importData() {				if($("#azj011").val() >= 300){			mbox({				title : "系統提示",				message : "上傳數據達到最大限制!"			});			return ;		}				var filepath =$("#textfield").val();		if(filepath ==""){			mbox({				title : "系統提示",				message : "請選擇文件!"			});			return ;		}								//顯示蒙版			var cover = $("<div class='covermask'/>").CSS({				width : $(window).width(),				height : $(window).height(),				opacity : 0.7,				"z-index" : 999			}).appendTo($("body"));			$("body").append($("<img style='z-index: 999;' class='loading' src='/icon/loading.gif'/><span style='z-index: 999;' class='loadingspan'>數據處理中,請稍等...</span>"));			//				$("#importForm").attr("action","${base!}/get_importdata.do?id=+'id + '&aab301=${b304!}&funid=" + $("#funid").val());			$.AjaxFileUpload({				url: "${base!}/get_importdata.do?Id="_id,            				secureuri:false,				fileElementId: 'textfield',				dataType: 'json',				success: function (data, status){					if(data.hasError == "true"){						var errors = [];						for(var key in data){							if(key != "hasError"){								errors.push("第" + key + data[key]);							}						}						mbox({							title : "系統提示",							message : errors.join("<br>"),							onClose : function(){								$(".loading,.covermask,.loadingspan").remove();								refreshPage();							}						});					}else if(data.status == "2"){						mbox({							title : "系統提示",							message : data.message,							onClose : function(){								$(".loading,.covermask,.loadingspan").remove();								refreshPage();							}						});					}else if(data.status == "4"){						mbox({							title : "系統提示",							message : data.message,							onClose : function(){								//刷新列表信息,以及數統計// 								goSelectPage();								///refreshLocation("1", "");								$(".loading,.covermask,.loadingspan").remove();								refreshPage();							}						});					}				},				error: function (data, status, e){					mbox({						title : "系統提示",						message : "上傳失敗",						onClose : function(){							$(".loading,.covermask,.loadingspan").remove();							refreshPage();						}					});				}			});			}注:此處mbox 及 
refreshPage();是提示框和刷新函數,此處忽略.

servlet:

@ResponseBody	@RequestMapping("get_importdata.html")	public void importData(MultipartHttpServletRequest request, String Id, ModelMap model, HttpServletResponse response){						BpWebDto dto = new BpWebDto();		dto.setId(Id);		Iterator<String> fileIter = request.getFileNames();		String message="";		if (!fileIter.hasNext()) {			message="模板文件錯誤,請查看!";			JSONUtil.writejson(response, "{'status' : '2', 'message' : '" + message + "'}");			return;		}		CommonsMultipartFile file = (CommonsMultipartFile) request.getFile("textfield");		String fileName = file.getOriginalFilename();		if (!fileName.endsWith(".xls")) {			message="模板文件錯誤,請查看!";			JSONUtil.writejson(response, "{'status' : '2', 'message' : '" + message + "'}");			return;		} else if(StringUtils.isBlank(Id)){			message="請先填寫并保存基本信息!";			JSONUtil.writejson(response, "{'status' : '2', 'message' : '" + message + "'}");			return;		} else {			//保存到臨時表中//			bpMng.importData(file, dto);//			//調用過程//			message = bpMng.importDataCheck(file, dto);			//在Java中做出校驗			try {				ExcelBean<BpWebDto> excelBean = importExcelMng.tempSaveInJavaBean(file.getInputStream(), dto);				if(excelBean == null){//達到最大數量限制					message = "數量已達到最大值。";				}else if(excelBean.hasErrors()){//報盤文件存在錯誤信息					excelBean.getErrors().put("hasError", "true");					JSONUtil.write(response, excelBean.getErrors());					return;				}else{//通過校驗,數據保存至臨時表					importExcelMng.saveData(excelBean.getDatas(), dto);					message = bpMng.importDataCheck(file, dto);//調用過程校驗報盤表數據				}			} catch (Exception e) {				e.PRintStackTrace();				message = "獲取模板文件信息出錯";			}		}		JSONUtil.writejson(response, "{'status' : '4', 'message' : '" + message + "'}");	}

注:此處的ModelMap及 BpWebDto 為自定義的map和bean類;

注:importExcelMng.saveData(excelBean.getDatas(), dto);  //為對Bpweb的存儲     message = importExcelMng.importCheckData(dto);//為調用過程校驗報盤表數據,返回的message 通過JSONUtil返回至前端,由ajax接收數據,提示。

importExcelMng.tempSaceInjavaBean() 類:

public ExcelBean<BpWebDto> tempSaveInJavaBean(InputStream is, BpWebDto dto) {		int maxNum = 99;		int currentNum = BpWebDao.countNum(dto.getId());		if(currentNum >= maxNum){			return null;		}		//excel表格里面的數據對應長度,屬性名,正則校驗,是否可為空。注意長度這幾個數組應當一致	/*	int[] proLength = new int[]{};		String[] properties = new String[]{};		String[] regexp = new String[]{};		boolean[] notnull = new boolean[]{};*/		int[] proLength = new int[]{18, 10, 3, 3, 3,20, 50, 100, 100, 10, 10,				  100, 100, 100, 50};		String[] properties = new String[]{"a002", "a003", "a012", "a029","a081","a083", "a005",  "a139",  "a046", "a183", "a007",                 "a008", "a027", "a028", "a029", "a013"};		String[] regexp = new String[]{"cardid", null, "code", "code","code", "number", "^[0-9//-]{0,50}$","^1[0-9]{10}$",				 "date,yyyyMMdd,yyyy-MM-dd", "number", "number", "number", null, null, null, null};		boolean[] notnull = new boolean[]{true, true, true, false, true,  true, false, false, true, true, false, false, false, false, false, false};		ExcelBean<BpWebDto> excelBean = new ExcelBean<BpWebDto>(properties, proLength, regexp, 1, 3, 0, 1, BpWebDto.class);		excelBean.setMaxRownum(maxNum - currentNum);		excelBean.setNotnull(notnull);		excelBean.impExcel(is);		return excelBean;	}

excelBean.impExcel()方法:

/**	 * @description 處理報盤模板Excel中的數據,并作校驗	 * @param source	 * @return	 * @List<T>	 * @author 	 * @throws IOException 	 * @date 	 */	public List<T> impExcel(InputStream source){		List<T> objs = new ArrayList<T>();		boolean iterateFlag = true;		int currRow = rowno;		try {			HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(					new BufferedInputStream(source)));			String[] header = getExcelHeader(wb, sheetno, headerrowno, properties.length, i);			if(!hasErrors()){				HSSFSheet sheet = wb.getSheetAt(sheetno);				if(sheet == null){					errors.put("00", "導入文件sheet頁錯誤");					iterateFlag = false;				}				while (iterateFlag) {					if(maxRownum != 0 && currRow >= maxRownum + rowno){						//超過最大行數限制,多余數據忽略						break;					}					HSSFRow row = sheet.getRow(currRow);										if(row == null){//已到最后一行						break;					}					if(checkLastRow(row, this.properties.length)){//有空行即退出循環。如果是最后一行返回true						break;					}else{						T t = clazz.newInstance();						HSSFCell cell;						for (int i = 0; i < header.length; i++) {							cell = row.getCell(i + this.i);														if(cell == null){								if(this.notnull != null){									if(this.notnull[i]){//不可為空										errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息不能為空,請按要求填寫。");									}								}								continue;							}							String value = getStringValueFromCell(cell);							if(StringUtils.isBlank(value)){//值為空,不作處理。								continue;							}							//特殊處理屬性的類存在							if(this.specialProperties != null){								//特殊屬性不為空并且當前屬性屬于特殊屬性								if(this.specialProperties.getSpecialPropertiesList() != null && this.specialProperties.getSpecialPropertiesList().contains(this.properties[i])){									try {										value = this.specialProperties.dealSpecialMethod(properties[i], value);										BeanUtils.copyProperty(t, properties[i], value);									} catch (Exception e) {										e.printStackTrace();										errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列", header[i] + "信息錯誤,請按要求填寫。");									}									//不做其他校驗									continue;								}							}							if("code".equals(regepx[i])){								if(value.indexOf(" ") == -1){//代碼項不含空格,提示錯誤									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列", header[i] + "信息錯誤,應為選擇項,請按要求選擇。");									continue;								}else{									value = value.substring(0, value.indexOf(" "));								}																if(!Pattern.matches("^[a-zA-Z0-9_//-]*$", value)){//代碼項中只允許有字符和數字、下劃線、橫線									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息錯誤,請按要求選擇。");									continue;								}							}else if("int".equals(regepx[i])){								if(!Pattern.matches("^[1-9][0-9]*$", value)){//整數校驗									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息錯誤,請輸入整數。");									continue;								}							}else if("number".equals(regepx[i])){//校驗數字								try {									Double.valueOf(value);								} catch (Exception e) {									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息應為數字,請按要求填寫。");									continue;								}							}else if("cardid".equals(regepx[i])){//校驗身份證號								if(!Pattern.matches("^(([0-9]{17}[Xx]{1})|([1-9]{1}[0-9]{17}))$", value)){									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息為身份證號,現填的內容為" + value +",長度為" + value.length() + "。請按要求填寫。");									continue;								}							}else if(regepx[i] != null && regepx[i].startsWith("date,")){//date已英文逗號隔開date,format日期格式化								try {									String[] datesReg = regepx[i].split(",");									SimpleDateFormat format = new SimpleDateFormat(datesReg[1]);									Date date = format.parse(value.trim());									if(datesReg.length == 3){//保存成字符串格式										SimpleDateFormat dateFormat = new SimpleDateFormat(datesReg[2]);										BeanUtils.copyProperty(t, properties[i], dateFormat.format(date));									}else{										BeanUtils.copyProperty(t, properties[i], date);									}								} catch (Exception e) {									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息錯誤,請按要求填寫。");								}								continue;//時間賦值之后跳到下一個CELL							}else if(regepx[i] != null){//自定義校驗								if(!Pattern.matches(regepx[i], value)){									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息格式不正確,請按要求填寫。");									continue;								}							}else{								//按普通字符串填寫							}							//校驗長度是否超范圍							if(value.length() > proLength[i]){								errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息超過要求長度,請按要求填寫。");								continue;							}else{								BeanUtils.copyProperty(t, properties[i], value);							}						}						objs.add(t);					}					currRow++;				}			}			//關閉文件流			source.close();		} catch (Exception e) {			e.printStackTrace();		}		if(this.hasErrors()){//校驗出現錯誤,返回空。不進行導入。			return null;		}		this.setDatas(objs);//導入的數據存放于datas中,便于保存		return objs;	}

完整的ExclBean.java:

package com.manager.impl.excelbean;import java.io.BufferedInputStream;import java.io.IOException;import java.io.InputStream;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Comparator;import java.util.Date;import java.util.List;import java.util.Map;import java.util.TreeMap;import java.util.regex.Pattern;import org.apache.commons.beanutils.BeanUtils;import org.apache.commons.lang.StringUtils;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFDateUtil;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.poifs.filesystem.POIFSFileSystem;/** * @description <h3>regex</h3> * <p>int 校驗整型數據</p> * <p>number 校驗數字</p> * <p>date,dateformat,date/date,dateformat,string 校驗日期</p> * <p>code 校驗選擇項</p> * <p>cardid 校驗身份證號</p> * <p>自定義校驗規則或為空不做校驗</p> * <h3>properties</h3> * <p>bean屬性property數組</p> * <h3>proLength</h3> * <p>bean屬性值最大長度數組</p> * @author *///EXCEL中數據都轉為String類型處理public final class ExcelBean<T> {	private String[] properties;//字段名稱	private int[] proLength;//字段長度	private int sheetno; //sheetno 當前處理的sheet頁	private int rowno; //rowno 起始行	private int headerrowno; //標題行	private int i; //i 起始列	private Class<T> clazz;//bean的Class		private String[] regepx;//正則校驗	private boolean[] notnull;	private AbstractSpecialProperties specialProperties;		/**	 * @description 需要特殊處理的屬性	 * <p>需要自定義類并繼承AbstractSpecialProperties抽象類,并實現特殊處理屬性的方法dealSpecialMethod</p>	 * @param specialProperties	 * @void	 * @author 	 * @date	 */	public void setSpecialProperties(AbstractSpecialProperties specialProperties) {		this.specialProperties = specialProperties;	}		public boolean[] getNotnull() {		return notnull;	}	/**	 * @description 設置是否校驗可為空數組	 * @param notnull	 * @void	 * @author 	 * @date 	 */	public void setNotnull(boolean[] notnull) {		this.notnull = notnull;	}	private int maxRownum = 0;//導入的最大條數限制	//保存導入的數據	private List<T> datas;	public List<T> getDatas() {		return datas;	}	public void setDatas(List<T> datas) {		this.datas = datas;	}	/**	 * @description 如果有錯誤,errors不為空,	 * <p>key為ij,第幾行第幾列</p>	 * <p>value為第i行第j列,+ header[j-1] + '數據錯誤' </p>	 */	private Map<String, String> errors;	public int getHeaderrowno() {		return headerrowno;	}	public void setHeaderrowno(int headerrowno) {		this.headerrowno = headerrowno;	}	public String[] getProperties() {		return properties;	}	public void setProperties(String[] properties) {		this.properties = properties;	}	public int[] getProLength() {		return proLength;	}	public void setProLength(int[] proLength) {		this.proLength = proLength;	}	public int getSheetno() {		return sheetno;	}	public void setSheetno(int sheetno) {		this.sheetno = sheetno;	}	public int getRowno() {		return rowno;	}	public void setRowno(int rowno) {		this.rowno = rowno;	}	public int getI() {		return i;	}	public void setI(int i) {		this.i = i;	}	public Class<T> getClazz() {		return clazz;	}	public void setClazz(Class<T> clazz) {		this.clazz = clazz;	}	public String[] getRegepx() {		return regepx;	}	public void setRegepx(String[] regepx) {		this.regepx = regepx;	}	public Map<String, String> getErrors() {		return errors;	}	public void setErrors(Map<String, String> errors) {		this.errors = errors;	}	public int getMaxRownum() {		return maxRownum;	}	/**	 * @description 設置可導入的最大條數	 * @param maxRownum	 * @void	 * @author 	 * @date	 */	public void setMaxRownum(int maxRownum) {		this.maxRownum = maxRownum;	}	/**	 * @description 有錯誤返回true,沒有錯誤返回false	 * @return	 * @boolean	 * @author 	 * @date 	 */	public boolean hasErrors(){		return !errors.isEmpty();	}	/**	 * @description properties,proLength,regepx必須存在,長度必須相等	 * @param properties 屬性數組不可為空	 * @param proLength 屬性長度不可為空	 * @param sheetno 數據頁	 * @param rowno 數據起始行	 * @param headerrowno 標題行	 * @param i 起始列	 * @param clazz	 * @param regepx 正則匹配不可為空	 */	public ExcelBean(String[] properties, int[] proLength, String[] regexp, int sheetno,			int rowno, int i, int headerrowno, Class<T> clazz){		this.properties = properties;		this.proLength = proLength;		this.sheetno = sheetno;		this.rowno = rowno;		this.i = i;		this.clazz = clazz;		this.regepx = regexp;		this.headerrowno = headerrowno;		//按行列排序		this.errors = new TreeMap<String, String>(new Comparator<String>() {			@Override			public int compare(String o1, String o2) {				if(o1 != null && o2 != null){					if(o1.contains("行") && o1.contains("列") && o2.contains("行") && o2.contains("列")){						int temp1 = Integer.valueOf(o1.substring(0, o1.indexOf("行")));						int temp2 = Integer.valueOf(o2.substring(0, o2.indexOf("行")));						if(temp1 == temp2){							temp1 = Integer.valueOf(o1.substring(o1.indexOf("行") + 1, o1.indexOf("列")));							temp2 = Integer.valueOf(o2.substring(o2.indexOf("行") + 1, o2.indexOf("列")));							return temp1 - temp2;						}						return temp1 - temp2;					}				}				return o1.compareTo(o2);			}		});	}	/**	 * @description 處理報盤模板Excel中的數據,并作校驗	 * @param source	 * @return	 * @List<T>	 * @author 	 * @throws IOException 	 * @date 	 */	public List<T> impExcel(InputStream source){		List<T> objs = new ArrayList<T>();		boolean iterateFlag = true;		int currRow = rowno;		try {			HSSFWorkbook wb = new HSSFWorkbook(new POIFSFileSystem(					new BufferedInputStream(source)));			String[] header = getExcelHeader(wb, sheetno, headerrowno, properties.length, i);			if(!hasErrors()){				HSSFSheet sheet = wb.getSheetAt(sheetno);				if(sheet == null){					errors.put("00", "導入文件sheet頁錯誤");					iterateFlag = false;				}				while (iterateFlag) {					if(maxRownum != 0 && currRow >= maxRownum + rowno){						//超過最大行數限制,多余數據忽略						break;					}					HSSFRow row = sheet.getRow(currRow);										if(row == null){//已到最后一行						break;					}					if(checkLastRow(row, this.properties.length)){//有空行即退出循環。如果是最后一行返回true						break;					}else{						T t = clazz.newInstance();						HSSFCell cell;						for (int i = 0; i < header.length; i++) {							cell = row.getCell(i + this.i);														if(cell == null){								if(this.notnull != null){									if(this.notnull[i]){//不可為空										errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息不能為空,請按要求填寫。");									}								}								continue;							}							String value = getStringValueFromCell(cell);							if(StringUtils.isBlank(value)){//值為空,不作處理。								continue;							}							//特殊處理屬性的類存在							if(this.specialProperties != null){								//特殊屬性不為空并且當前屬性屬于特殊屬性								if(this.specialProperties.getSpecialPropertiesList() != null && this.specialProperties.getSpecialPropertiesList().contains(this.properties[i])){									try {										value = this.specialProperties.dealSpecialMethod(properties[i], value);										BeanUtils.copyProperty(t, properties[i], value);									} catch (Exception e) {										e.printStackTrace();										errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列", header[i] + "信息錯誤,請按要求填寫。");									}									//不做其他校驗									continue;								}							}							if("code".equals(regepx[i])){								if(value.indexOf(" ") == -1){//代碼項不含空格,提示錯誤									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列", header[i] + "信息錯誤,應為選擇項,請按要求選擇。");									continue;								}else{									value = value.substring(0, value.indexOf(" "));								}																if(!Pattern.matches("^[a-zA-Z0-9_//-]*$", value)){//代碼項中只允許有字符和數字、下劃線、橫線									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息錯誤,請按要求選擇。");									continue;								}							}else if("int".equals(regepx[i])){								if(!Pattern.matches("^[1-9][0-9]*$", value)){//整數校驗									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息錯誤,請輸入整數。");									continue;								}							}else if("number".equals(regepx[i])){//校驗數字								try {									Double.valueOf(value);								} catch (Exception e) {									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息應為數字,請按要求填寫。");									continue;								}							}else if("cardid".equals(regepx[i])){//校驗身份證號								if(!Pattern.matches("^(([0-9]{17}[Xx]{1})|([1-9]{1}[0-9]{17}))$", value)){									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息為身份證號,現填的內容為" + value +",長度為" + value.length() + "。請按要求填寫。");									continue;								}							}else if(regepx[i] != null && regepx[i].startsWith("date,")){//date已英文逗號隔開date,format日期格式化								try {									String[] datesReg = regepx[i].split(",");									SimpleDateFormat format = new SimpleDateFormat(datesReg[1]);									Date date = format.parse(value.trim());									if(datesReg.length == 3){//保存成字符串格式										SimpleDateFormat dateFormat = new SimpleDateFormat(datesReg[2]);										BeanUtils.copyProperty(t, properties[i], dateFormat.format(date));									}else{										BeanUtils.copyProperty(t, properties[i], date);									}								} catch (Exception e) {									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息錯誤,請按要求填寫。");								}								continue;//時間賦值之后跳到下一個CELL							}else if(regepx[i] != null){//自定義校驗								if(!Pattern.matches(regepx[i], value)){									errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息格式不正確,請按要求填寫。");									continue;								}							}else{								//按普通字符串填寫							}							//校驗長度是否超范圍							if(value.length() > proLength[i]){								errors.put((currRow + 1) + "行" + (i + this.i + 1) + "列" , header[i] + "信息超過要求長度,請按要求填寫。");								continue;							}else{								BeanUtils.copyProperty(t, properties[i], value);							}						}						objs.add(t);					}					currRow++;				}			}			//關閉文件流			source.close();		} catch (Exception e) {			e.printStackTrace();		}		if(this.hasErrors()){//校驗出現錯誤,返回空。不進行導入。			return null;		}		this.setDatas(objs);//導入的數據存放于datas中,便于保存		return objs;	}		private String[] getExcelHeader(HSSFWorkbook workbook, int sheerno, int headerrow, int length, int i){		String[] header = new String[length];		try {			HSSFWorkbook wb = workbook;			if(sheetno > wb.getNumberOfSheets()){				return null;			}			HSSFSheet sheet = wb.getSheetAt(sheetno);			if (sheet == null) {				errors.put("header00", "導入文件sheet頁錯誤!");				throw new Exception("導入文件sheet頁錯誤!");			}			HSSFRow row = sheet.getRow(headerrowno);			if (row != null) {				for (int j = 0; j < length; j++) {					HSSFCell cell = (HSSFCell) row.getCell(j + i);					if(cell == null ){						continue;					}					String value;					if(getObjFormCell(cell) instanceof java.lang.String) {						value = String.valueOf(getObjFormCell(cell));					}else {						continue;					}					if(value!=null){						value=value.replaceAll(" ", "");						value=value.replaceAll("//n", "");						value=value.replaceAll("//*", "");					}					if (j == 0 && value != null && "end".equalsIgnoreCase(value)) {						break;					}					if(value != "" || value != null){						if(header[j]==null){							header[j] = value;						}else {							if(header[j]!=""){								header[j] += value;							}else if(i > 0){								header[j] = header[j-1]+value;							}						}					}				}			}		} catch (Exception ex) {			errors.put("header01", "獲取模板頭部信息時錯誤!");			throw new RuntimeException(ex);		}		return header;	}		private static Object getObjFormCell(HSSFCell cell) {		switch (cell.getCellType()) {			case HSSFCell.CELL_TYPE_NUMERIC :				if (HSSFDateUtil.isCellDateFormatted(cell)) {					return cell.getDateCellValue();				}				return (Object) new Double(cell.getNumericCellValue());							case HSSFCell.CELL_TYPE_STRING : 				return cell.getStringCellValue();							default:				return (Object) cell.getStringCellValue();		}	}	/**	 * @description 獲取excel表格中的字符串數據	 * @param cell	 * @return	 * @String	 * @author 	 * @date 	 */	private static String getStringValueFromCell(HSSFCell cell){		switch (cell.getCellType()) {			case HSSFCell.CELL_TYPE_NUMERIC :				if (HSSFDateUtil.isCellDateFormatted(cell)) {					Date date = cell.getDateCellValue();					return date == null ? null : date.toString();				}				cell.setCellType(HSSFCell.CELL_TYPE_STRING);//修改為文本數據				return cell.getStringCellValue();			case HSSFCell.CELL_TYPE_STRING : 				return cell.getStringCellValue();			default:				cell.setCellType(HSSFCell.CELL_TYPE_STRING);//修改為文本數據				return cell.getStringCellValue();		}	}	/**	 * @description 	 * @param row	 * @param cellNum 列數	 * @return	 * @boolean	 * @author	 * @date 	 */	private boolean checkLastRow(HSSFRow row, int cellNum){		boolean isLast = true;		if(row == null){			return isLast;		}else{//row不為空			for (int i = 0; i < cellNum; i++) {				HSSFCell cell = row.getCell(i);				if(cell != null){					//強制cell為String類型,以免取值發生錯誤					cell.setCellType(HSSFCell.CELL_TYPE_STRING);					String value = getStringValueFromCell(cell);					if(StringUtils.isNotBlank(value)){//有一個不為空既不是最后一行						isLast = false;						break;					}				}			}		}		return isLast;	}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马公市| 托克逊县| 琼海市| 临沧市| 城固县| 信丰县| 高邮市| 福泉市| 黑龙江省| 深泽县| 潜山县| 无为县| 兰溪市| 左贡县| 五台县| 隆子县| 南昌县| 镇康县| 突泉县| 两当县| 内丘县| 北宁市| 嘉峪关市| 营山县| 攀枝花市| 即墨市| 黄梅县| 江都市| 揭东县| 韶关市| 尉犁县| 九江市| 平安县| 桂林市| 信阳市| 津南区| 柳河县| 鲜城| 永清县| 衡阳县| 莫力|