- 浏览: 186211 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
kjmmlzq19851226:
这个和排序米有关系吧
一个排好序的数组,找出两数之和为m的所有组合 -
ileson:
...
spring在web.xml中的配置
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.cnpc.oms.om.pojo.CommOmWorkStatus;
/**
*
* 标题:Excel导入工具类
*
* 作者:ShengLiguo
*
*/
public class OmImportExcelUtil {
public static List analysis03ExcelDate(InputStream inStream, String[] head)
throws Exception {
List list = new ArrayList();
HSSFWorkbook book = new HSSFWorkbook(inStream);
HSSFSheet sheet = book.getSheetAt(0);
HSSFRow row = null;
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Map map = new HashMap();
String questionSenderOrg = "";
String questionType = "";
int k = 0;
row = sheet.getRow(i);
for (int j = 0; j < head.length; j++) {
if (head[j].equals("questionSenderOrg")) {
if (!"".equals(questionSenderOrg)
&& !"".equals(getCellValue(row.getCell(j)))) {
questionSenderOrg = questionSenderOrg + "-"
+ getCellValue(row.getCell(j));
} else {
questionSenderOrg = questionSenderOrg
+ getCellValue(row.getCell(j));
}
if (k++ == 2) {
map.put(head[j], questionSenderOrg);
k = 0;
}
continue;
}
if (head[j].equals("questionType")) {
if (!"".equals(questionType)
&& !"".equals(getCellValue(row.getCell(j)))) {
questionType = questionType + "-"
+ getCellValue(row.getCell(j));
} else {
questionType = questionType
+ getCellValue(row.getCell(j));
}
if (k++ == 4) {
map.put(head[j], questionType);
k = 0;
}
continue;
}
map.put(head[j], getCellValue(row.getCell(j)));
}
list.add(map);
}
return list;
}
public static List analysis07ExcelDate(InputStream inStream, String[] head)
throws Exception {
List list = new ArrayList();
XSSFWorkbook book = new XSSFWorkbook(inStream);
XSSFSheet sheet = book.getSheetAt(0);
XSSFRow row = null;
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Map map = new HashMap();
String questionSenderOrg = "";
String questionType = "";
int k = 0;
row = sheet.getRow(i);
for (int j = 0; j < head.length; j++) {
if (head[j].equals("questionSenderOrg")) {
if (!"".equals(questionSenderOrg)
&& !"".equals(getCellValue(row.getCell(j)))) {
questionSenderOrg = questionSenderOrg + "-"
+ getCellValue(row.getCell(j));
} else {
questionSenderOrg = questionSenderOrg
+ getCellValue(row.getCell(j));
}
if (k++ == 2) {
map.put(head[j], questionSenderOrg);
k = 0;
}
continue;
}
if (head[j].equals("questionType")) {
if (!"".equals(questionType)
&& !"".equals(getCellValue(row.getCell(j)))) {
questionType = questionType + "-"
+ getCellValue(row.getCell(j));
} else {
questionType = questionType
+ getCellValue(row.getCell(j));
}
if (k++ == 4) {
map.put(head[j], questionType);
k = 0;
}
continue;
}
map.put(head[j], getCellValue(row.getCell(j)));
}
list.add(map);
}
return list;
}
private static Object getCellValue(Cell cell) {
if (cell.getCellType() == cell.CELL_TYPE_STRING) {
return cell.getStringCellValue();
}
if (cell.getCellType() == cell.CELL_TYPE_NUMERIC) {
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue();
} else {
Format format = new DecimalFormat("#");
return format.format(cell.getNumericCellValue());
}
}
return "";
}
private static PropertyDescriptor[] getPropertyDescriptors(Object obj) {
BeanInfo ObjInfo;
try {
ObjInfo = Introspector.getBeanInfo(obj.getClass());
} catch (IntrospectionException e) {
return new PropertyDescriptor[0];
}
PropertyDescriptor[] propertyDesc = ObjInfo.getPropertyDescriptors();
return propertyDesc;
}
public static Object setPropertyValue(Map map, Object obj) {
PropertyDescriptor[] propertyDesc = getPropertyDescriptors(obj);
for (int i = 0; i < propertyDesc.length; i++) {
if (propertyDesc[i].getName().compareToIgnoreCase("class") == 0)
continue;
Object objValue = map.get(propertyDesc[i].getName()) == null ? ""
: map.get(propertyDesc[i].getName());
Object value = parseObject(objValue, propertyDesc[i]
.getPropertyType());
try {
propertyDesc[i].getWriteMethod().invoke(obj, value);
} catch (Exception e) {
e.printStackTrace();
}
}
return obj;
}
public static Object parseObject(Object fromObj, Class toClass) {
Object objReturn = null;
if (fromObj.equals("")) {
return objReturn;
}
String fromClassName = fromObj.getClass().getName();
String toClassName = toClass.getName();
if (fromClassName.equals(toClassName)) {
objReturn = fromObj;
} else if ("java.lang.Short".equals(toClassName)
|| "java.lang.Integer".equals(toClassName)
|| "java.lang.Long".equals(toClassName)
|| "java.lang.Float".equals(toClassName)
|| "java.lang.Double".equals(toClassName)
|| "java.math.BigDecimal".equals(toClassName)) {
try {
Constructor constructor = toClass
.getConstructor(new Class[] { String.class });
objReturn = constructor.newInstance(new Object[] { fromObj });
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new IllegalArgumentException("From " + fromClassName + " To "
+ toClassName + ", Unsupported");
}
return objReturn;
}
public static void main(String[] args) throws Exception {
String[] head = { "title", "questionSenderOrg", "questionSenderOrg",
"questionSenderOrg", "questionType", "questionType",
"questionType", "questionType", "questionType",
"questionReceiver", "solveStatus", "questionAskDate",
"questionSolveDate", "questionFrom", "questionSolver",
"questionSolveMethod", "questionSender", "questionSenderTel" };
InputStream in = new FileInputStream(
"C:/Documents and Settings/ShengLiGuo/桌面/工单.xlsx");
List<Map> mapList = analysis07ExcelDate(in, head);
CommOmWorkStatus workStatus = new CommOmWorkStatus();
for (Map map : mapList) {
setPropertyValue(map, workStatus);
System.out.println("======" + workStatus.getTitle());
System.out.println("======" + workStatus.getQuestionFrom());
}
}
}
发表评论
-
java对称加密算法的使用
2014-05-26 09:55 2758package utils; import java.io ... -
java使用ganymed-ssh2执行linux操作系统命令
2013-12-31 10:10 2021public static void main(Strin ... -
一个排好序的数组,找出两数之和为m的所有组合
2013-06-13 18:46 1501public static void main(Strin ... -
java中文API
2012-04-17 12:25 844http://www.oschina.net/home/api ... -
javase7官方API
2012-04-17 11:38 1091Java™ Platform, Standard Edit ... -
javase6中文API
2012-04-01 20:15 2450概述 软件包 类 使用 ... -
javase6官方API
2012-04-01 20:10 964Overview Package C ... -
java.util.concurrent官方API文档
2012-04-01 20:03 1909Overview Package C ... -
java.util.concurrent中文API
2012-04-01 19:45 1594概述 软件包 类 使用 ... -
java.util.concurrent介绍(转)
2012-04-01 19:33 980本文由 cnblogs 博主 ... -
JDK6下开发WebService
2012-03-17 09:06 1545周末闲来无事,在家中复习了一下JDK6下开发WebServi ... -
日期正则表达式
2012-01-13 17:58 1089一、简单的 日期判断(YYYY/MM/DD):^\d{4 ... -
使用JAVA API上传文件到FTP服务器
2011-12-02 12:41 1176private void FtpUpload() throw ... -
Java发送邮件
2011-11-04 17:24 935import java.io.UnsupportedEncod ... -
使用JAVA API从FTP服务器下载文件
2011-11-04 16:28 1747import java.io.IOException; im ... -
Java读取Properties文件
2011-11-04 16:06 775使用J2SE API读取Properties文件的六种方法 ... -
java获取服务器IP
2011-10-27 12:04 1200java.net.InetAddress.getLocalHo ... -
java 获取真实客户端IP(转载)
2011-10-27 11:33 2230原文出处:http://jun-li-leo.iteye. ... -
JDBC连接字符串
2011-10-26 11:17 20861. MySQL Class.forName(&quo ... -
java中filter的用法
2011-10-19 11:45 970filter过滤器主要使用于前台向后台传递数据是的过滤操作。程 ...
相关推荐
POI导入Excel并返回校验后的错误文件(原样数据文件,并添加批注,注:由于批注只能加1000条,会在Excel后面添加一栏错误信息)下载以及页面展示校验错误信息,同时添加导入进度条,提供页面js和css代码,后端...
poi就是批量的操作文件或数据的导入以及导出。,poi导入excel表需要的jar
这个是使用java语言 poi导入excel到数据库中,同时使用了xml对excel的每个单元格数据进行了非空验证。经测试,导入数据库成功。
POI导入Excel,详细内容查看博客 POI导入Excel文件--form表单提交 内容
POI把Excel表格数据导入到数据库的小例子
java_poi实现excel导入导出功能,有详细的注解
poi导入excel2003,2007通用
POI 导入Excel 提醒LeftoverDataException求帮助
SpringMvc+POI 导入Excel文件,采用简单的form表单提交方式和Jquery.form.js插件提供的异步表单方式导入Excel数据
POI导入excel大数据处理,支持excel2003,2007, 有例子,可以直接运行
poi导入excel 兼容2003-2007兼容版本,测试可以成功;poi导入excel 兼容2003-2007兼容版本,测试可以成功;
NULL 博文链接:https://dengwenjun.iteye.com/blog/1903904
java导入excel的工具类。支持单个对象的赋值,列表对象的赋值,指定坐标的赋值。主要利用的是poi的技术,java反射和自定义注解。 20170915,解决了不能导入带有公式字段的excel的问题
通用的POI导入excel解决方法,方便,简易,内附jar包
poi excel 导入 导出poi excel 导入 导出poi excel 导入 导出poi excel 导入 导出poi excel 导入 导出poi excel 导入 导出
poi导入excel示例文件.xlsx
主要是springboot+myBatis+poi+mysql的使用,从数据库查询到结果集导出excel到本地,从本地中的excel文件导入到数据库中。
java导入excel的工具类。支持单个对象的赋值,列表对象的赋值,指定坐标的赋值。主要利用的是poi的技术,java反射和自定义注解
但导入Excel相对麻烦点,一般情况下,导入的程序无法通用的主要原因是:对于不同的导入模板,字段field与单元格cellRef的映射关系是不相同的,这就导致对每一个导入模板都要去写一套相似的代码;我们应该想办法解决...
poi导入excel示例文件.xlsx