• 大小: 27MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-15
  • 语言: Java
  • 标签: javaweb  jsp  excel  

资源简介

这段时间闲来无事,想研究一下办公系统中的导出和导入excel表格功能,最后终于弄出来,现在给广大需要的新手朋友参考使用

资源截图

代码片段和文件信息

package com.hzys.excel.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellstyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.hzys.excel.dao.entity.Userinfo;
import com.hzys.excel.service.IUserService;
import com.opensymphony.xwork2.ActionSupport;


@Controller(“userAction“)
@ParentPackage(“struts-default“)
@Namespace(““)
@Scope(“prototype“)
@Action(“userAction“)
public class UserAction extends ActionSupport {

/**
 * 
 */
private static final long serialVersionUID = 1L;


@Resource(name=“userService“)
private IUserService userService;

private Userinfo userinfo;
public String xlsFileName;;
public File xls;
public String docContentType;

public File getXls() {
return xls;
}

public void setXls(File xls) {
this.xls = xls;
}

public String getDocContentType() {
return docContentType;
}

public void setDocContentType(String docContentType) {
this.docContentType = docContentType;
}

public Userinfo getUserinfo() {
return userinfo;
}

public void setUserinfo(Userinfo userinfo) {
this.userinfo = userinfo;
}

public String getXlsFileName() {
return xlsFileName;
}

public void setXlsFileName(String xlsFileName) {
this.xlsFileName = xlsFileName;
}

/*
 * 查询所有
 */
public String queryall() throws IOException{
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType(“text/html;charset=utf-8“);
try {
List userlist=userService.queryall();
JSONArray newlist=JSONArray.fromobject(userlist);
response.getWriter().write(newlist.toString());
} catch (Exception e) {
response.getWriter().write(“error“);
}
return null;
}

/*
 * 读取excel
 */
public String read() throws Exception IOException{

HttpServletResponse response=ServletActionContext.getResponse();
HttpServletRequest request=ServletActionContext.getRequest();

//获得文件上传的上传目录
String filepath=ServletActionContext.getServletContext().getRealPath(“/filelib“);
//保存文件的文件名称
System.out.println(“文件名字:“+this.getXlsFileName());
String f

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        834  2015-04-16 14:52  excel\.classpath

     文件       1038  2015-04-16 14:52  excel\.project

     文件        503  2015-04-16 14:52  excel\.settings\.jsdtscope

     文件        364  2015-04-16 14:52  excel\.settings\org.eclipse.jdt.core.prefs

     文件        467  2015-04-16 14:52  excel\.settings\org.eclipse.wst.common.component

     文件        345  2015-04-16 14:52  excel\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2015-04-16 14:52  excel\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2015-04-16 14:52  excel\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件       8720  2015-04-16 14:52  excel\build\classes\com\hzys\excel\action\UserAction.class

     文件       1183  2015-04-16 14:52  excel\build\classes\com\hzys\excel\dao\entity\Userinfo.class

     文件        427  2015-04-16 14:52  excel\build\classes\com\hzys\excel\dao\mapper\UserMapper.class

     文件       1443  2015-04-16 14:52  excel\build\classes\com\hzys\excel\dao\mapper\UserMapper.xml

     文件        303  2015-04-16 14:52  excel\build\classes\com\hzys\excel\service\IUserService.class

     文件       1003  2015-04-16 14:52  excel\build\classes\com\hzys\excel\service\spring\UserService.class

     文件       7892  2015-04-16 14:52  excel\src\com\hzys\excel\action\UserAction.java

     文件        650  2015-04-16 14:52  excel\src\com\hzys\excel\dao\entity\Userinfo.java

     文件        353  2015-04-16 14:52  excel\src\com\hzys\excel\dao\mapper\UserMapper.java

     文件       1443  2015-04-16 14:52  excel\src\com\hzys\excel\dao\mapper\UserMapper.xml

     文件        225  2015-04-16 14:52  excel\src\com\hzys\excel\service\IUserService.java

     文件        686  2015-04-16 14:52  excel\src\com\hzys\excel\service\spring\UserService.java

     文件       3401  2015-04-16 14:52  excel\WebContent\index.jsp

     文件     275529  2015-04-16 14:52  excel\WebContent\js\jquery-1.8.3.js

     文件         39  2015-04-16 14:52  excel\WebContent\meta-INF\MANIFEST.MF

     文件       7451  2015-04-16 14:52  excel\WebContent\outexcel.jsp

     文件          0  2015-04-16 14:52  excel\WebContent\WEB-INF\app-config\email.properties

     文件        605  2015-04-16 14:52  excel\WebContent\WEB-INF\app-config\ibatis-config\SqlMapConfig.xml

     文件        373  2015-04-16 14:52  excel\WebContent\WEB-INF\app-config\jdbc.properties

     文件       2020  2015-04-16 14:52  excel\WebContent\WEB-INF\app-config\log4j.properties

     文件       2299  2015-04-16 14:52  excel\WebContent\WEB-INF\app-config\mybatis-config\mybatis.xml

     文件        913  2015-04-16 14:52  excel\WebContent\WEB-INF\app-config\spring-config\applicationContext-bean.xml

............此处省略121个文件信息

评论

共有 条评论