excel 2007代码(部分代码与另一篇2003共享)
来源:互联网 发布:apache base64 编辑:程序博客网 时间:2024/06/15 00:07
import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.text.DecimalFormat;import java.util.ArrayList;import java.util.List;import javax.servlet.http.HttpServletResponse;import org.apache.poi.xssf.usermodel.XSSFCell;import org.apache.poi.xssf.usermodel.XSSFRow;import org.apache.poi.xssf.usermodel.XSSFSheet;import org.apache.poi.xssf.usermodel.XSSFWorkbook;import com.nufront.euht.excel.imports.interfaces.ExcelInterface;import com.nufront.euht.model.CapEbu;import com.nufront.euht.model.CapEdu;import com.nufront.euht.model.TrainLine;import com.nufront.euht.pageModel.JsonTipMessage;import com.nufront.euht.util.StringUtil;public class Excel2007 implements ExcelInterface{private StringBuffer errorMessage = new StringBuffer();private DecimalFormat decimalFormat = new DecimalFormat("0");// 格式化 number String@Overridepublic boolean importExcel(String excelPath, List<TrainLine> lines) {if (lines == null)lines = new ArrayList<TrainLine>();File file = new File(excelPath);boolean isSuccess = true;XSSFWorkbook hwb;XSSFRow row = null;XSSFSheet sheet =null;try {hwb = new XSSFWorkbook(new FileInputStream(file));sheet = hwb.getSheetAt(0);} catch (Exception e) {errorMessage.append("发生未知异常,读取excel内容失败");isSuccess = false;e.printStackTrace();} String preLineName = "";String preEduName = "";CapEdu edu = null;for (int i = sheet.getFirstRowNum()+1; i < sheet.getPhysicalNumberOfRows(); i++) {row = sheet.getRow(i);if (row == null) continue;//判断是否要新增对象String currentLineName = getValue(row, COL_LINE_NAME);if ( !StringUtil.isNullOrBlank(currentLineName) && !preLineName.equals(currentLineName)) {TrainLine line = new TrainLine();line.setLineName(currentLineName);lines.add(line);preLineName = currentLineName;}String currentEduName = getValue(row, COL_EDU_NAME);if ( !StringUtil.isNullOrBlank(currentEduName) && !preEduName.equals(currentEduName)) {edu = new CapEdu();edu.setEduName(currentEduName);TrainLine line = lines.get(lines.size()-1);line.getCapEduList().add(edu);preEduName = currentEduName;}CapEbu ebu = new CapEbu();if (edu != null) {edu.setEduIp(getValue(row, COL_EDU_IP));edu.setEduModel(getValue(row, COL_EDU_MODEL));edu.setEduIp(getValue(row, COL_EDU_IP));edu.getCapEbuList().add(ebu);}ebu.setEbuCode(getValue(row, COL_EBU_CODE));ebu.setLocation(getValue(row, COL_EBU_LOCATION));ebu.setHardwareVersion(getValue(row, COL_EBU_HARDWARE_VERSION));ebu.setEbuIp(getValue(row, COL_EBU_IP));ebu.setEbuMac(getValue(row, COL_EBU_MAC));// ebu.setRegion(getValue(row, COL_EBU_REGION);}return isSuccess;}public String getValue(XSSFRow row, int column) {XSSFCell cell = row.getCell(column);String value = null;if (cell == null) return null;if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING){value = cell.getStringCellValue();}else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC){value = decimalFormat.format(cell.getNumericCellValue());}return value;}@Overridepublic void exportExcel(HttpServletResponse response, List<TrainLine> lines, String strSheetName, String strFileName)throws IOException {// TODO Auto-generated method stub}@Overridepublic JsonTipMessage importExcel(InputStream is, List<TrainLine> lines) {// TODO Auto-generated method stubreturn null;}}
0 0
- excel 2007代码(部分代码与另一篇2003共享)
- 代码共享与可重入
- PostgreSQL共享缓冲区部分代码阅读总结(一)
- JPush极光推送代码(已弃用,请参照另一篇)
- 共享一段Excel导入Notes的代码
- java poi 导出excel 部分代码
- php导出excel表格部分代码
- delphi与Excel(二)delphi控制Excel具体代码
- excel 2003代码
- 代码 部分
- 部分代码
- 共享Binding共享代码
- zoj部分题目代码(仅代码)
- Linux 网络代码导读(接收与发送部分)
- Linux 网络代码导读(接收与发送部分)
- C#导出到Excel的代码,现共享给大家
- 页与页之间如何共享代码
- 页与页之间如何共享代码
- Java获取泛型的实际类型
- Java 后台管理开发框架!CURD 一键生成,再也不要重复搬砖了!
- js图片转base64编码压缩上传
- XML解析方式
- [Python]第四讲:print语句
- excel 2007代码(部分代码与另一篇2003共享)
- 软考程序员随笔-----7
- Android ListView、GridView等性能优化
- jsp页面 报core 找不到
- 2016 百度之星 B题(java实现)
- 新优麒麟版本发布PK微软Windows
- Tex中的引号
- VMWare虚拟机中的MacOSX使用XCode运行无法连接iPhone设备
- Failed to install Python Cryptography package