第1个回答 2012-05-14
MenuTreeInfoForm menuInfo = (MenuTreeInfoForm)form;
FormFile file = menuInfo.getFile();
InputStream ips = new FileInputStream( "" );
Workbook rwb = Workbook.getWorkbook(ips);
Sheet st = rwb.getSheet(0);
List<List> infoList = new ArrayList<List>();
List<String> infoArrList = new ArrayList<String>();
for(int i = 0; i < st.getRows(); i++) {
String name= st.getCell(0, i).getContents().trim();
String age = st.getCell(1, i).getContents().trim();
String sex = st.getCell(2, i).getContents().trim();
infoArrList.add(0, name);
infoArrList.add(1, age);
infoArrList.add(2, sex);
infoList.add(i,infoArrList);
}
//写如文件
OutputStream ops = new FileOutputStream("D:\test");
try {
WritableWorkbook wwb = Workbook.createWorkbook(ops);
WritableSheet ws = wwb.createSheet("new sheet", 0);
// 设定指定列的宽度
ws.setColumnView(0, 15);
ws.setColumnView(1, 15);
ws.setColumnView(2, 15);
ws.setColumnView(3, 15);
// 设定标签颜色
WritableFont wf_merge = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.NO_BOLD, false,UnderlineStyle.SINGLE_ACCOUNTING, Colour.RED);
WritableCellFormat wff_merge = new WritableCellFormat(wf_merge);
wff_merge.setBackground(Colour.WHITE);
// 设置首行标题栏
Label label00 = new Label(0, 0, "操作状态", wff_merge);
ws.addCell(label00);
Label label10 = new Label(1, 0, "帐号", wff_merge);
ws.addCell(label10);
Label label20 = new Label(2, 0, "密码", wff_merge);
ws.addCell(label20);
Label label30 = new Label(3, 0, "sip", wff_merge);
ws.addCell(label30);
int infoListSize = infoList.size();
UpLoadInfo upLoadInfo = null;
if(infoListSize>0){
for (int i = 1; i <= infoListSize; i++) {
List list = infoList.get(i-1);
for(int j = 1; j <= infoArrList.size(); j++){
ws.addCell(new Label(j, j, infoArrList.get(j)));
}
}
}
wwb.write();
wwb.close();
ops.close();
}catch (Exception e) {
}