java写入Excel并读取文件
来源:互联网 发布:费洛伊德算法 编辑:程序博客网 时间:2024/05/01 16:06
java
/**
* 返回设备申请基本信息列表
* @param sourceFile
* @param targetFile
* @param undoTasks
* @return
*/
public static boolean applyInfo(File sourceFile, File targetFile , List undoTasks) {
int size = undoTasks.size();
try {
Workbook wb = Workbook.getWorkbook(sourceFile);
WritableWorkbook wwb = Workbook.createWorkbook(targetFile, wb);
// 读取第一张工作表统计列表
WritableSheet ws1 = wwb.getSheet(0);
String userName = null;
String userDepart = null;
String userPost = null;
String requestType = null;
String requestReason = null;
String requestPurpose = null;
BpmShenheMenu shenHe = null;
for(int i=0; i<size; i++) {
shenHe = (BpmShenheMenu)undoTasks.get(i);
userName = shenHe.getUserName();
userDepart = shenHe.getUserDepartName();
userPost = shenHe.getPostName()==null?" ":shenHe.getPostName();
requestType = shenHe.getRequestTypeName();
requestReason = shenHe.getRequestReason();
requestPurpose = shenHe.getReqeustPurposeName();
Label label = new Label(0, (i+1), (i+1)+"", getNormolCell());
ws1.addCell(label);
label = new Label(1, (i+1), userName, getNormolCell());
ws1.addCell(label);
label = new Label(2, (i+1), userDepart, getNormolCell());
ws1.addCell(label);
label = new Label(3, (i+1), userPost, getNormolCell());
ws1.addCell(label);
label = new Label(4, (i+1), requestType, getNormolCell());
ws1.addCell(label);
label = new Label(5, (i+1), requestReason, getNormolCell());
ws1.addCell(label);
label = new Label(6, (i+1), requestPurpose, getNormolCell());
ws1.addCell(label);
}
wwb.write();
wwb.close();
wb.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 设置单元格样式
*
* @return
*/
public static WritableCellFormat getNormolCell() {// 12号字体,上下左右居中,带黑色边框
WritableFont font = new WritableFont(WritableFont.createFont("宋体"), 9);
WritableCellFormat format = new WritableCellFormat(font);
try {
format.setAlignment(jxl.format.Alignment.CENTRE);
format.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
} catch (WriteException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return format;
}
jsp
function downloadEvent(){
<%
if(hasData) {
File sourcefile = new File(application.getRealPath("/")
+ "//reports//sourceFiles//applyInfo.xls");
File targetfile = new File(application.getRealPath("/")
+ "//reports//targetFiles//applyInfo.xls");
boolean readSuccess=false;
if(targetfile.exists()){
targetfile.delete();
}
readSuccess=ReadXls.applyInfo(sourcefile, targetfile,undoTasks);
if(readSuccess && targetfile.exists()){
%>
window.open("../reports/targetFiles/applyInfo.xls");
<%
}
} else {
%>
alert("无数据!");
<%
}
%>
}
- java写入Excel并读取文件
- Java读取Excel文件并写入数据库
- java读取excel文件并写入另一个excel文件
- java读取和写入Excel文件
- java读取和写入Excel文件
- java读取与写入Excel文件
- 使用JAVA读取和写入EXCEL文件
- Java读取excel文件写入txt
- Java读取或写入Excel文件
- java写入、读取excel文件1
- 使用JAVA读取和写入EXCEL文件
- EXCEL 读取 写入文件
- 读取excel,写入文件
- 利用Java读取并写入Word文件
- 利用Java读取并写入Word文件
- 利用Java读取并写入Word文件
- java读取Excel数据,然后写入到txt文件,并批量保存到oracle数据库中
- PHP读取Excel文件的内容并写入Mysql数据库
- css的sytle解析
- 多做一点就能解决问题
- 如何将 Access 数据库转换到 SQL Server
- 通过AIDL及反射机制,使用隐藏API挂断电话
- 利用底层键盘钩子拦载任意按键(回调版)
- java写入Excel并读取文件
- 有点不知所措
- Web前端开发必备手册下载
- UNIX环境高级编程学习之第十三章守护进程 - 初始化一个守护进程
- Vampires
- jsp按照部门分层统计数据 可折叠
- java.io.PrintWriter 中 write() 与 print() 的区别
- Linux内核访问外设I/O资源的方式
- 模拟电子技术16 26------——放大电路 动态分析 交流负载线 续