我们背着压力不停地追赶不断地努力,到最后才发觉,我们真正想要的就是幸福........................................ Travelling in real lify with my dream and enthusiasm

把excel 转换为xml的pio

上一篇 / 下一篇  2007-09-22 15:12:05

String   temp_excelPath="F:/report/ddd.xls";   51Testing软件测试网@ `t;wyj?
                  FileInputStream   fis=null;   51Testing软件测试网 hZ!d7L'i5c_ _t)s t
                  String   xmlstr="";   51Testing软件测试网'[lF:cX)]"x%[]
                  HSSFWorkbook   workbook=null;   51Testing软件测试网3y9w/h1_!MVd;~|D6d\
                  try{  
:b-w2t3J6lO7bE"g"R G0                          fis=new   FileInputStream(temp_excelPath);   51Testing软件测试网"]V9cW s)g
                          workbook=new   HSSFWorkbook(fis);  
gF6k?]Tn:m0                          int   sheetnum=workbook.getNumberOfSheets()   ;  
Q[t)MRv0                          if(sheetnum>0){   51Testing软件测试网;Z(zZ-U1{7~u!?F
                                  HSSFSheet   hs=workbook.getSheetAt(0);  
0S(t[dB0                                  String   tempstr="";   51Testing软件测试网?$kR x2z:a
                                  int   rownum=hs.getPhysicalNumberOfRows();  
9QWX#_q| y:z;BQ0                                  System.out   .println("r="+rownum)   ;   51Testing软件测试网K6OIT2Vf,Z/u
                                  if(rownum>0){  
}nnZV8OQ0                                          for(int   i=0;i<rownum;i++){   51Testing软件测试网QC$\4M\$}
                                                  tempstr="";  
*L V+p$B4ZvR0                                                  HSSFRow   hr=hs.getRow(i);  
9H JX9} x5z0                                                  int   colnum=hr.getPhysicalNumberOfCells();  
fV|{4J0A,l#h[0                                                  System.out   .println("c="+colnum)   ;  
$P&fj[ wwi,v0                                                  if(colnum>0){   51Testing软件测试网eh m6v!`?
                                                          for(short   j=0;j<colnum;j++){  
w4Nj/xO0                                                                  HSSFCell   hc=hr.getCell(j)   ;   51Testing软件测试网,|w/LC._1pc
                                                                  System.out.println("type="+hc.getCellType())   ;  
}!j#vw'b wn3A0                                                                  /*if(   HSSFDateUtil.isCellDateFormatted(hc)){   51Testing软件测试网S Ks#\x#e
                                                                          Date   date=hc.getDateCellValue();  
T;o9ElVN^0                                                                          tempstr+="<Cell>"+date.toString()+"</Cell>";   51Testing软件测试网lN7p2qY$n i
                                                                          System.out   .println("tempstr11="+tempstr)   ;  
/N|f9c9W_9}{lD4o0                                                                  }else{*/  
'SO$NbAD*b0   
L1W7j bd)P*s a0                                                                          if(hc.getCellType()==HSSFCell.CELL_TYPE_STRING){  
;J,Ty'PXZ C ~%^k;s0                                                                                  tempstr+="<Cell>"+hc.getStringCellValue()+"</Cell>";   51Testing软件测试网0YM6N0jhw.|
                                                                                  System.out   .println("tempstr22="+tempstr)   ;  
H6_JJ*`^B,E0                                                                          }   51Testing软件测试网M:pr{-x$@0wl ku
                                                                          if(hc.getCellType()==HSSFCell.CELL_TYPE_NUMERIC   ){  
x0uMK)n R!S0                                                                                  tempstr+="<Cell>"+Double.toString(hc.getNumericCellValue())+"</Cell>";   51Testing软件测试网@C/zX/GA
                                                                                  System.out   .println("tempstr33="+tempstr)   ;  
+VG[ {8~N&yP0                                                                          }   51Testing软件测试网)W;OZ;xzK
                                                                          if(hc.getCellType()==HSSFCell.CELL_TYPE_FORMULA   ){   51Testing软件测试网QgN$iU
                                                                                  tempstr+="<Cell>"+hc.getCellFormula()+"</Cell>";   51Testing软件测试网D8n1GUK#H*M
                                                                                  System.out   .println("tempstr33="+tempstr)   ;  
yqX_f[%M WR0                                                                          }   51Testing软件测试网5D{5V1f4D[1te!fMB
    51Testing软件测试网"Ivi qe v O
                                                                  //}  
s['Ij)f0                                                          }  
Hw EI1f0                                                          xmlstr+="<Row>"+tempstr+"</Row>";   51Testing软件测试网!l#a Kkl8@!j-__,}
                                                  }   51Testing软件测试网o{^8`$_Or
                                          }   51Testing软件测试网+fG)u'@:]:O o)a*_Hd"L
                                          xmlstr="<Table>"+xmlstr+"<Table>";   51Testing软件测试网ouXr5p E6~"N2b-Sj
                                  }  
P!w8KC~;LX:p0                          }   51Testing软件测试网HK4D'Z[+Z
    51Testing软件测试网 x'O$Z+o8z-sB.|L-M
                  }catch(Exception   e){   51Testing软件测试网e{*ru5G
                          e.printStackTrace()   ;   51Testing软件测试网,~pkT9i D3d%g.S]
                  }finally{   51Testing软件测试网d}#H*B([]5Y5E4[K
                          if(fis!=null){  
S3h*?-I r/o)G}0                                  try{  
J/LE8Ak0|`r?0                                          fis.close()   ;  
l1fm;{0Xl%S0                                  }catch(Exception   e){  
MJ@]o0t1V5j0                                          e.printStackTrace()   ;  
6](XoEjg d0                                  }   51Testing软件测试网5rK"R[E}2J
                          }   51Testing软件测试网'| WB;HT6un3[B/N Rz
                  }

TAG:

 

评分:0

我来说两句

日历

« 2024-05-22  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 14007
  • 日志数: 30
  • 图片数: 1
  • 建立时间: 2007-03-17
  • 更新时间: 2008-01-04

RSS订阅

Open Toolbar