- 浏览: 136585 次
- 性别:
- 来自: 北京
文章分类
package com.longtuo.client.action.admin.job;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
//加入自己的类
import *.*;
/**
* 媒体数据导入
*
* @author xjmfc
*
*/
public class ImportMediaAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = 1L;
private File newsFile = null;
private String savePath = null;
private String contentType = null;
private String fileName = null;
private JobService jobService = null;
private UserInfoService userInfoService = null;
private String type = null;
public JobService getJobService() {
return jobService;
}
public void setJobService(JobService jobService) {
this.jobService = jobService;
}
public String getNewsFileContentType() {
return contentType;
}
public void setNewsFileContentType(String contentType) {
this.contentType = contentType;
}
public String getNewsFileFileName() {
return fileName;
}
public void setNewsFileFileName(String fileName) {
this.fileName = fileName;
}
public File getNewsFile() {
return newsFile;
}
public void setNewsFile(File newsFile) {
this.newsFile = newsFile;
}
public String getSavePath() {
return savePath;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
private List<MediaMeta> getList(Sheet sheet, int rowCount, int columnCount) throws Exception {
UserInfo user = null;
Media media=null;
MediaMeta mmeta=null;
List<MediaMeta> lst = new ArrayList<MediaMeta>();
for (int i = 0; i < rowCount; i++) {
if (i == 0) {
continue;
}
user = new UserInfo();
mmeta=new MediaMeta();
media=new Media();
user.setLoginTimes(ATTMedia.DEFAULT_LOGINTIME);
user.setStatus(ATTUserInfo.STATUS_USER_DEFAULT);
user.setCate("m");
user.setRoleId("200");
user.setCreateDate(new Date());
media.setCreateDate(new Date());
media.setDownloadTimes(ATTMedia.DEFAULT_DOWNLOADTIME);
media.setLev(ATTMedia.LEVEL_DEFAULT_MEDIA);
media.setCreateDate(new Date());
user.setStatus("0");
user.setPasswd(new MD5Util().getMD5ofStr("000000"));
// 1用户名 2.邮箱 3.名称 4.媒体类型 5,6 省市 7.真实姓名 8. 9.电话
String province=null;
for (int j = 0; j < columnCount; j++) {
Cell cell = sheet.getCell(j, i);
switch (j) {
case 0:
user.setUserName(cell.getContents());
break;
case 1:
user.setEmail(cell.getContents());
break;
case 2:
media.setMName(cell.getContents());
break;
case 3:
if (cell.getContents().indexOf("平面") != -1) {
media.setRangs("001001");
} else if (cell.getContents().indexOf("影视媒体") != -1) {
media.setRangs("001002");
} else if (cell.getContents().indexOf("网络") != -1) {
media.setRangs("001003");
}else if(cell.getContents().indexOf("其他")!=-1){
media.setRangs("001004");
}else{
media.setRangs("001004");
}
break;
case 4:
province =cell.getContents();
break;
case 5:
media.setAddress(province+cell.getContents());
province = null;
break;
case 6:
user.setRealName(cell.getContents());
media.setName(cell.getContents());
break;
case 7:
break;
case 8:
if(cell.getContents().indexOf("1") != -1){
media.setPhone(cell.getContents());
}else{
media.setMobile(cell.getContents());
}
break;
case 9:
break;
case 10:
break;
case 11:
media.setPosition(cell.getContents());
break;
default:
break;
}
mmeta.setMedia(media);
mmeta.setUser(user);
}
lst.add(mmeta);
}
return lst;
}
private boolean saveImportData(File ioFile) throws Exception {
int rowCount = 0;
int columnCount = 0;
Workbook workbook = Workbook.getWorkbook(ioFile);
Sheet sheet = workbook.getSheet(0);
rowCount = sheet.getRows();
columnCount = sheet.getColumns();
if (rowCount == 0) {
this.addFieldError("importError", "您导入的文件没数据");
return false;
}
List<MediaMeta> lstMedia = getList(sheet, rowCount, columnCount);
for (MediaMeta meta : lstMedia) {
userInfoService.saveMediaInfo(meta);
}
return false;
}
public String execute() throws Exception {
UserInfo user = this.getUser();
if (user == null) {
return ATTSystem.LOGIN;
}
if (newsFile != null) {
if (saveImportData(newsFile)) {
if (this.getFieldErrors().isEmpty()) {
if (type.equals(ATTJob.SOC_POSITION)) {
this.setAttr("_status", "社会职位批量导入数据成功!");
this.setAttr("type", type);
return SUCCESS;
} else if (type.equals(ATTJob.STU_POSITION)) {
this.setAttr("_status", "学生职位批量导入数据成功!");
this.setAttr("type", type);
return SUCCESS;
}
}
}
}
return INPUT;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public UserInfoService getUserInfoService() {
return userInfoService;
}
public void setUserInfoService(UserInfoService userInfoService) {
this.userInfoService = userInfoService;
}
}
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
//加入自己的类
import *.*;
/**
* 媒体数据导入
*
* @author xjmfc
*
*/
public class ImportMediaAction extends BaseAction {
/**
*
*/
private static final long serialVersionUID = 1L;
private File newsFile = null;
private String savePath = null;
private String contentType = null;
private String fileName = null;
private JobService jobService = null;
private UserInfoService userInfoService = null;
private String type = null;
public JobService getJobService() {
return jobService;
}
public void setJobService(JobService jobService) {
this.jobService = jobService;
}
public String getNewsFileContentType() {
return contentType;
}
public void setNewsFileContentType(String contentType) {
this.contentType = contentType;
}
public String getNewsFileFileName() {
return fileName;
}
public void setNewsFileFileName(String fileName) {
this.fileName = fileName;
}
public File getNewsFile() {
return newsFile;
}
public void setNewsFile(File newsFile) {
this.newsFile = newsFile;
}
public String getSavePath() {
return savePath;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
private List<MediaMeta> getList(Sheet sheet, int rowCount, int columnCount) throws Exception {
UserInfo user = null;
Media media=null;
MediaMeta mmeta=null;
List<MediaMeta> lst = new ArrayList<MediaMeta>();
for (int i = 0; i < rowCount; i++) {
if (i == 0) {
continue;
}
user = new UserInfo();
mmeta=new MediaMeta();
media=new Media();
user.setLoginTimes(ATTMedia.DEFAULT_LOGINTIME);
user.setStatus(ATTUserInfo.STATUS_USER_DEFAULT);
user.setCate("m");
user.setRoleId("200");
user.setCreateDate(new Date());
media.setCreateDate(new Date());
media.setDownloadTimes(ATTMedia.DEFAULT_DOWNLOADTIME);
media.setLev(ATTMedia.LEVEL_DEFAULT_MEDIA);
media.setCreateDate(new Date());
user.setStatus("0");
user.setPasswd(new MD5Util().getMD5ofStr("000000"));
// 1用户名 2.邮箱 3.名称 4.媒体类型 5,6 省市 7.真实姓名 8. 9.电话
String province=null;
for (int j = 0; j < columnCount; j++) {
Cell cell = sheet.getCell(j, i);
switch (j) {
case 0:
user.setUserName(cell.getContents());
break;
case 1:
user.setEmail(cell.getContents());
break;
case 2:
media.setMName(cell.getContents());
break;
case 3:
if (cell.getContents().indexOf("平面") != -1) {
media.setRangs("001001");
} else if (cell.getContents().indexOf("影视媒体") != -1) {
media.setRangs("001002");
} else if (cell.getContents().indexOf("网络") != -1) {
media.setRangs("001003");
}else if(cell.getContents().indexOf("其他")!=-1){
media.setRangs("001004");
}else{
media.setRangs("001004");
}
break;
case 4:
province =cell.getContents();
break;
case 5:
media.setAddress(province+cell.getContents());
province = null;
break;
case 6:
user.setRealName(cell.getContents());
media.setName(cell.getContents());
break;
case 7:
break;
case 8:
if(cell.getContents().indexOf("1") != -1){
media.setPhone(cell.getContents());
}else{
media.setMobile(cell.getContents());
}
break;
case 9:
break;
case 10:
break;
case 11:
media.setPosition(cell.getContents());
break;
default:
break;
}
mmeta.setMedia(media);
mmeta.setUser(user);
}
lst.add(mmeta);
}
return lst;
}
private boolean saveImportData(File ioFile) throws Exception {
int rowCount = 0;
int columnCount = 0;
Workbook workbook = Workbook.getWorkbook(ioFile);
Sheet sheet = workbook.getSheet(0);
rowCount = sheet.getRows();
columnCount = sheet.getColumns();
if (rowCount == 0) {
this.addFieldError("importError", "您导入的文件没数据");
return false;
}
List<MediaMeta> lstMedia = getList(sheet, rowCount, columnCount);
for (MediaMeta meta : lstMedia) {
userInfoService.saveMediaInfo(meta);
}
return false;
}
public String execute() throws Exception {
UserInfo user = this.getUser();
if (user == null) {
return ATTSystem.LOGIN;
}
if (newsFile != null) {
if (saveImportData(newsFile)) {
if (this.getFieldErrors().isEmpty()) {
if (type.equals(ATTJob.SOC_POSITION)) {
this.setAttr("_status", "社会职位批量导入数据成功!");
this.setAttr("type", type);
return SUCCESS;
} else if (type.equals(ATTJob.STU_POSITION)) {
this.setAttr("_status", "学生职位批量导入数据成功!");
this.setAttr("type", type);
return SUCCESS;
}
}
}
}
return INPUT;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public UserInfoService getUserInfoService() {
return userInfoService;
}
public void setUserInfoService(UserInfoService userInfoService) {
this.userInfoService = userInfoService;
}
}
- jxl.jar (692.5 KB)
- 下载次数: 4
- ImportMediaAction.java.tar.gz (1.9 KB)
- 下载次数: 3
发表评论
-
storm 安装
2013-09-02 16:32 3029------------------------------- ... -
动态代理性能比较
2013-01-18 17:02 1126转自http://javatar.iteye.com/blog ... -
java 类加载器学习
2012-12-14 10:47 999引用1.自定义类加载器 public interface ... -
jackson 学习
2012-11-13 15:42 9801.json 转为object对象 public clas ... -
java 线程池 异常 处理 机制 分析
2012-10-31 19:34 2072public class ThreadTest { ... -
ThreadPoolExecutor 原理-- java 线程池
2012-08-08 19:14 1105整个ThreadPoolExecutor的任务处理有4 ... -
java 缓冲
2012-08-08 19:12 986import org.apache.log4j.Logge ... -
java 程序消耗 cpu 100% 查找方法
2012-05-16 14:38 17176问题原因:由于HashMap是非线程安全的,在多线程访问时,造 ... -
java io
2012-04-24 11:06 8831、按字节读取文件内容 2、按字符读取文件内容 3、按行读取 ... -
java 内省
2011-11-20 22:58 786java内省 -
系统常用工具类
2011-04-20 17:46 9781.ArithUtil.java ... -
spring 面向切面编程
2010-12-27 17:03 1054@Aspect public class AspectCoup ... -
jxl 写入excel
2010-11-10 13:52 9911.程序调用 ReportInterface report ... -
java 生成略缩图
2010-10-20 17:21 1175import java.awt.Graphics2D; imp ... -
XStream简单介绍
2010-09-10 15:44 1648创建能够序列化的类 这是一组简单的类。XStream能把这 ... -
java中对集合类的排序
2010-05-04 13:47 8681.第一种 public class User impleme ... -
Java 获取操作系统信息与Desktop类
2009-11-17 16:24 1347import java.util.Properties; ... -
java 事物处理
2009-10-15 10:52 1397public boolean deleteSchedule ...
相关推荐
完美解决java读取excel内存溢出问题,希望可以帮到大家
Java读取Excel内容 v Java读取Excel内容 Java读取Excel内容
JAVA读取 excelJAVA读取 excel
java读取excel数据导入数据库源码 java读取excel数据导入数据库源码
java 读取Excel文件中的内容 java 读取Excel文件中的内容
java读写excel包括utf8转码为可识别汉字gbk,jxl方式读取excel,生成一个新的excel
通过Java读取Excel文件中的数据时,需要自动判断当前Cell中的数据格式是否日期格式,如果是就要做特殊处理,以便读出数据的格式与预想的相符。
java 读取excel内容 创建excel 插入文字及图片 可以直接运行
java读取excel表格的数据,并将其保存!已经调试过了,可以使用!
ExcelDemo_Excel导出_下载_POI读excel_JXL读写excel_java读写excel_列宽_读取合并或拆分单元格内容
Java 操作Excel poi读写excel,所需要的jar包 https://blog.csdn.net/u014646662/article/details/83217382
java读写excel文件,新手参考高手绕道。
JAVA读取excel
Java读取excel
JAVA读取Excel,建库建表,并生成java实体
java读取excel所有页的数据,可能会有bug 毕竟我测试是没有,小白一个,大佬勿喷啊,网上搜的资源然后改写的读取所有页,可能会有不足的地方。01年的弟弟,不喜勿喷
java读写Excel,POI.JAR,Word内容读取
java 读取 excel,代码绝对没有错误。请放心下载,祝大家好运
java读取Excel表中的内容,可以读取多个sheet,生成自定义格式的xml文件
使用Java读取Excel文件的内容,主要是使用POI框架,可以读取最新的Excel文件xlsx后缀文件,即2007版本之后的。