java 读取excel文件 我需要去读到每一行的每一个数据。 然后操作一番。 最后生成一个XML文件
3个回答
展开全部
jxl
package com.cj.fw.xml;
import java.io.File;import java.io.IOException;
import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;
import jxl.Workbook;import jxl.WorkbookSettings;import jxl.read.biff.BiffException;import jxl.write.Label;import jxl.write.WritableCell;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;import jxl.write.WriteException;import com.cj.pro.domain.Drilling;
public class DrillingExport {
// 模板文件位置 private final static String TempletFile = "/attachments/template/emergencydrill.xls"; // 数据 private Drilling log = null; private String leixing=null;
/** * 构造函数 */ public DrillingExport( Drilling log,String leixing) { this.log=log; this.leixing=leixing; }
/** * 安全培训日志导出表 * @throws IOException * @throws BiffException * @throws WriteException */ public boolean export(HttpServletRequest request,HttpServletResponse response) throws BiffException, IOException, WriteException { String fileName=""; if("1".equals(leixing)){ fileName="应急演练信息导出表.xls"; }else if("2".equals(leixing)){ fileName="消防演练演练信息导出表.xls"消誉数; } response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-type","application/拿首file"); response.setHeader("Content-Disposition", "attachment;filename=" + new String( fileName.getBytes("gb2312"), "ISO8859-1" )); File file = new File(request.getSession().getServletContext().getRealPath(TempletFile)); WorkbookSettings workbookSettings=new WorkbookSettings(); workbookSettings.setEncoding("ISO-8859-1"); //关键代虚拿码,解决中文乱码 Workbook workbook = Workbook.getWorkbook(file,workbookSettings); WritableWorkbook wwb = Workbook.createWorkbook(response.getOutputStream(), workbook); WritableSheet ws = wwb.getSheet(0); WritableCell cell = null; if("1".equals(leixing)){ cell = new Label(1,0,"应急演练单",ws.getCell(1,0).getCellFormat()); ws.addCell(cell); }else if("2".equals(leixing)){ cell = new Label(1,0,"消防演练单",ws.getCell(1,0).getCellFormat()); ws.addCell(cell); } if(log!=null){ cell = new Label(2,1,log.getRiqi(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(5,1,log.getDidian(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(2,2,log.getMingcheng(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(5,2,log.getZuzhidanwei(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(2,3,log.getJiaoben(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(2,4,log.getBeizhu(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); }else{ cell = new Label(2,4,"导出出错",ws.getCell(1,0).getCellFormat()); ws.addCell(cell); } //合计小写 wwb.write(); wwb.close(); workbook.close(); return true; }
}
上面的是导出 你可以变变
package com.cj.fw.xml;
import java.io.File;import java.io.IOException;
import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;
import jxl.Workbook;import jxl.WorkbookSettings;import jxl.read.biff.BiffException;import jxl.write.Label;import jxl.write.WritableCell;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;import jxl.write.WriteException;import com.cj.pro.domain.Drilling;
public class DrillingExport {
// 模板文件位置 private final static String TempletFile = "/attachments/template/emergencydrill.xls"; // 数据 private Drilling log = null; private String leixing=null;
/** * 构造函数 */ public DrillingExport( Drilling log,String leixing) { this.log=log; this.leixing=leixing; }
/** * 安全培训日志导出表 * @throws IOException * @throws BiffException * @throws WriteException */ public boolean export(HttpServletRequest request,HttpServletResponse response) throws BiffException, IOException, WriteException { String fileName=""; if("1".equals(leixing)){ fileName="应急演练信息导出表.xls"; }else if("2".equals(leixing)){ fileName="消防演练演练信息导出表.xls"消誉数; } response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-type","application/拿首file"); response.setHeader("Content-Disposition", "attachment;filename=" + new String( fileName.getBytes("gb2312"), "ISO8859-1" )); File file = new File(request.getSession().getServletContext().getRealPath(TempletFile)); WorkbookSettings workbookSettings=new WorkbookSettings(); workbookSettings.setEncoding("ISO-8859-1"); //关键代虚拿码,解决中文乱码 Workbook workbook = Workbook.getWorkbook(file,workbookSettings); WritableWorkbook wwb = Workbook.createWorkbook(response.getOutputStream(), workbook); WritableSheet ws = wwb.getSheet(0); WritableCell cell = null; if("1".equals(leixing)){ cell = new Label(1,0,"应急演练单",ws.getCell(1,0).getCellFormat()); ws.addCell(cell); }else if("2".equals(leixing)){ cell = new Label(1,0,"消防演练单",ws.getCell(1,0).getCellFormat()); ws.addCell(cell); } if(log!=null){ cell = new Label(2,1,log.getRiqi(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(5,1,log.getDidian(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(2,2,log.getMingcheng(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(5,2,log.getZuzhidanwei(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(2,3,log.getJiaoben(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); cell = new Label(2,4,log.getBeizhu(),ws.getCell(1,1).getCellFormat()); ws.addCell(cell); }else{ cell = new Label(2,4,"导出出错",ws.getCell(1,0).getCellFormat()); ws.addCell(cell); } //合计小写 wwb.write(); wwb.close(); workbook.close(); return true; }
}
上面的是导出 你可以变变
展开全部
使用 xstream-1.2.2.jar 将对首御象李姿转者扰岩xml
Student student = new Student();
XStream xstream = new XStream();
String xmlString = xstream.toXML(student);
Student student = new Student();
XStream xstream = new XStream();
String xmlString = xstream.toXML(student);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
jxl
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |