我们背着压力不停地追赶不断地努力,到最后才发觉,我们真正想要的就是幸福........................................
Travelling in real lify with my dream and enthusiasm
把excel 转换为xml的pio
String temp_excelPath="F:/report/ddd.xls"; 51Testing软件测试网@`t;wyj?
FileInputStream fis=null; 51Testing软件测试网 hZ!d7L'i5c_ _t)s t
String xmlstr=""; 51Testing软件测试网'[l F:cX)]"x%[]
HSSFWorkbook workbook=null; 51Testing软件测试网3y9w/h1_!MVd;~|D6d\
try{
:b-w2t3J6lO7bE"g"RG0 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软件测试网?$kRx2z:a
int rownum=hs.getPhysicalNumberOfRows();
9QWX#_q|y:z;BQ0 System.out .println("r="+rownum) ; 51Testing软件测试网K6OIT2Vf,Z/u
if(rownum>0){
}nn ZV8OQ0 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软件测试网ehm6v!`?
for(short j=0;j<colnum;j++){
w4Nj/xO0 HSSFCell hc=hr.getCell(j) ; 51Testing软件测试网,|w/LC._1p c
System.out.println("type="+hc.getCellType()) ;
}!j#vw'b wn3A0 /*if( HSSFDateUtil.isCellDateFormatted(hc)){ 51Testing软件测试网S Ks#\ x#e
Date date=hc.getDateCellValue();
T;o9E lVN^0 tempstr+="<Cell>"+date.toString()+"</Cell>"; 51Testing软件测试网lN7p2qY$n i
System.out .println("tempstr11="+tempstr) ;
/N|f9c9W_9}{lD4o0 }else{*/
'SO$NbA D*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$@0wlk u
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[%MWR0 } 51Testing软件测试网5D{5V1f4D[1te!fMB
51Testing软件测试网"Iviqe vO
//}
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软件测试网 ouXr5pE6~"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*?-Ir/o)G}0 try{
J/L E8Ak0|`r?0 fis.close() ;
l1fm;{0Xl%S0 }catch(Exception e){
MJ@]o0t1V5j0 e.printStackTrace() ;
6](XoEjg d0 } 51Testing软件测试网5rK"R[E}2J
} 51Testing软件测试网'|W B;HT6un3[B/NRz
}
FileInputStream fis=null; 51Testing软件测试网 hZ!d7L'i5c_ _t)s t
String xmlstr=""; 51Testing软件测试网'[l F:cX)]"x%[]
HSSFWorkbook workbook=null; 51Testing软件测试网3y9w/h1_!MVd;~|D6d\
try{
:b-w2t3J6lO7bE"g"RG0 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软件测试网?$kRx2z:a
int rownum=hs.getPhysicalNumberOfRows();
9QWX#_q|y:z;BQ0 System.out .println("r="+rownum) ; 51Testing软件测试网K6OIT2Vf,Z/u
if(rownum>0){
}nn ZV8OQ0 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软件测试网ehm6v!`?
for(short j=0;j<colnum;j++){
w4Nj/xO0 HSSFCell hc=hr.getCell(j) ; 51Testing软件测试网,|w/LC._1p c
System.out.println("type="+hc.getCellType()) ;
}!j#vw'b wn3A0 /*if( HSSFDateUtil.isCellDateFormatted(hc)){ 51Testing软件测试网S Ks#\ x#e
Date date=hc.getDateCellValue();
T;o9E lVN^0 tempstr+="<Cell>"+date.toString()+"</Cell>"; 51Testing软件测试网lN7p2qY$n i
System.out .println("tempstr11="+tempstr) ;
/N|f9c9W_9}{lD4o0 }else{*/
'SO$NbA D*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$@0wlk u
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[%MWR0 } 51Testing软件测试网5D{5V1f4D[1te!fMB
51Testing软件测试网"Iviqe vO
//}
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软件测试网 ouXr5pE6~"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*?-Ir/o)G}0 try{
J/L E8Ak0|`r?0 fis.close() ;
l1fm;{0Xl%S0 }catch(Exception e){
MJ@]o0t1V5j0 e.printStackTrace() ;
6](XoEjg d0 } 51Testing软件测试网5rK"R[E}2J
} 51Testing软件测试网'|W B;HT6un3[B/NRz
}
TAG: