如何将网页上取到的数据导入到EXCEL表中?菜鸟求助! 要做个报表,数据库用的是ORACLE,还要改EXCEL的文件名字内容都是从网页上取的!求高人指点!最好有代码! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我举例说明,你看一下能不能修改使用public class ProjectInformCSVAction extends ActionSupport{ private static Logger log = Logger.getLogger(ProjectInformCSVAction.class); /** * 项目名称 */ private String ipoName; /** * 项目管理Service */ private ProjectManagerService projectManagerService; public String getIpoName() { return ipoName; } public void setIpoName(String ipoName) { this.ipoName = ipoName; } public void setProjectManagerService(ProjectManagerService projectManagerService) { this.projectManagerService = projectManagerService; } public InputStream getInputStream(){ FileInputStream fis=null; /** * 判断项目参数是否为空 */ try{ if(ipoName!=null&&!ipoName.equals("")){ try { ipoName=java.net.URLDecoder.decode(ipoName,"UTF-8"); } catch (UnsupportedEncodingException e) { log.error(e.getMessage()); } } List<ProjectManageVO> projectManageVos=new ArrayList<ProjectManageVO>(); try{ /** * 获取所有数据list */ projectManageVos=projectManagerService.getProjectsBylikeipoName(ipoName); /** * 把二维数组写成csv文件导出 */ String[][] csvReport; if(projectManageVos!=null){ csvReport=ConvertListtoArrayString(projectManageVos); }else{ csvReport=new String[][]{{"序号","ipo公司名称","创建日期","当前状态","保荐机构","关联文件名"}}; } String filepath = projectManagerService.getRefreshFilePath("getrootdirectory","csvRootDirectory"); File tempFile = new File(filepath+File.separator+"projectlist.csv"); CSVWriter writer=null; try { //writer= new CSVWriter(new FileWriter(tempFile)); writer= new CSVWriter(new OutputStreamWriter(new FileOutputStream(tempFile),"gbk")); for (int i = 0; i < csvReport.length; i++) { writer.writeNext(csvReport[i]); } fis=new FileInputStream(tempFile); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { if(writer!=null){ writer.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }catch(IPOException e){ log.error(e.getMessage()); } }catch (IPOException e) { log.error(e.getMessage()); } return fis; } /** * 把数据转为二维数据 * @param list * @return */ public String[][] ConvertListtoArrayString(List<ProjectManageVO> list){ int a = list.size(); String[] array0=new String[]{"序号","ipo公司名称","创建日期","当前状态","保荐机构","关联文件名"}; String[][] array = new String[a+1][6]; for (int i = 0;i<=list.size(); i++) { if(i==0){ array[i][0]="序号"; array[i][1]="ipo公司名称"; array[i][2]="创建日期"; array[i][3]="当前状态"; array[i][4]="保荐机构"; array[i][5]="关联用户名"; }else{ array[i][0]=i+""; array[i][1]=list.get(i-1).getIpoName(); array[i][2]=list.get(i-1).getOperTime(); if(list.get(i-1).getState().startsWith("0")){ array[i][3]="没有完成项目"; }else if(list.get(i-1).getState().startsWith("1")){ array[i][3]="已完成项目"; }else{ array[i][3]="撤销项目"; } array[i][4]=list.get(i-1).getUwName(); array[i][5]=list.get(i-1).getUserName(); } } return array; } public String getDownloadFileName() { /** * 返回给前台下载框中的文件名 */ String downloadFileName="项目列表.csv"; try { HttpServletResponse response=ServletActionContext.getResponse(); /** * 设置文件头类型 */ //response.setContentType("application/x-msdownload"); response.setContentType("text/csv"); /** * 转码文件名 */ downloadFileName=java.net.URLEncoder.encode(downloadFileName,"UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return downloadFileName; }} java串口通讯问题 新手求助,如果获取上一级标签. java cs jb6 报表如何制作,请给思路 请问JAVA与C#哪个好学 acess 数据库连接错误 一个有关snmp4j开源包的问题!!!急!!!小女子先谢过了!!!!在线等待 不好意思!又问问题了,我是个JAVA新手,刚学2个月,现在忙于赶项目,问题很多,但都不是很难!我觉得还没有完全理解Java的事件处理机制 关于用java来处理license的问题 问题 多多问题,请大家帮忙。 JTextField 失去焦点的问题 关于Java Gui编程
public class ProjectInformCSVAction extends ActionSupport{ private static Logger log = Logger.getLogger(ProjectInformCSVAction.class);
/**
* 项目名称
*/
private String ipoName;
/**
* 项目管理Service
*/
private ProjectManagerService projectManagerService;
public String getIpoName() {
return ipoName;
}
public void setIpoName(String ipoName) {
this.ipoName = ipoName;
}
public void setProjectManagerService(ProjectManagerService projectManagerService) {
this.projectManagerService = projectManagerService;
}
public InputStream getInputStream(){
FileInputStream fis=null;
/**
* 判断项目参数是否为空
*/
try{
if(ipoName!=null&&!ipoName.equals("")){
try {
ipoName=java.net.URLDecoder.decode(ipoName,"UTF-8");
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage());
}
}
List<ProjectManageVO> projectManageVos=new ArrayList<ProjectManageVO>();
try{
/**
* 获取所有数据list
*/
projectManageVos=projectManagerService.getProjectsBylikeipoName(ipoName);
/**
* 把二维数组写成csv文件导出
*/
String[][] csvReport;
if(projectManageVos!=null){
csvReport=ConvertListtoArrayString(projectManageVos);
}else{
csvReport=new String[][]{{"序号","ipo公司名称","创建日期","当前状态","保荐机构","关联文件名"}};
}
String filepath = projectManagerService.getRefreshFilePath("getrootdirectory","csvRootDirectory");
File tempFile = new File(filepath+File.separator+"projectlist.csv");
CSVWriter writer=null;
try {
//writer= new CSVWriter(new FileWriter(tempFile));
writer= new CSVWriter(new OutputStreamWriter(new FileOutputStream(tempFile),"gbk"));
for (int i = 0; i < csvReport.length; i++) {
writer.writeNext(csvReport[i]);
}
fis=new FileInputStream(tempFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
if(writer!=null){
writer.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }catch(IPOException e){
log.error(e.getMessage());
}
}catch (IPOException e) {
log.error(e.getMessage());
}
return fis;
}
/**
* 把数据转为二维数据
* @param list
* @return
*/
public String[][] ConvertListtoArrayString(List<ProjectManageVO> list){
int a = list.size();
String[] array0=new String[]{"序号","ipo公司名称","创建日期","当前状态","保荐机构","关联文件名"};
String[][] array = new String[a+1][6];
for (int i = 0;i<=list.size(); i++) {
if(i==0){
array[i][0]="序号";
array[i][1]="ipo公司名称";
array[i][2]="创建日期";
array[i][3]="当前状态";
array[i][4]="保荐机构";
array[i][5]="关联用户名";
}else{
array[i][0]=i+"";
array[i][1]=list.get(i-1).getIpoName();
array[i][2]=list.get(i-1).getOperTime();
if(list.get(i-1).getState().startsWith("0")){
array[i][3]="没有完成项目";
}else if(list.get(i-1).getState().startsWith("1")){
array[i][3]="已完成项目";
}else{
array[i][3]="撤销项目";
}
array[i][4]=list.get(i-1).getUwName();
array[i][5]=list.get(i-1).getUserName();
}
}
return array;
}
public String getDownloadFileName() {
/**
* 返回给前台下载框中的文件名
*/
String downloadFileName="项目列表.csv";
try {
HttpServletResponse response=ServletActionContext.getResponse();
/**
* 设置文件头类型
*/
//response.setContentType("application/x-msdownload");
response.setContentType("text/csv");
/**
* 转码文件名
*/
downloadFileName=java.net.URLEncoder.encode(downloadFileName,"UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }
return downloadFileName; }
}