我们背着压力不停地追赶不断地努力,到最后才发觉,我们真正想要的就是幸福........................................
Travelling in real lify with my dream and enthusiasm
把excel 转换为xml的pio
String temp_excelPath="F:/report/ddd.xls"; 51Testing软件测试网fN)n z\
qR
FileInputStream fis=null;
U-_fZ my)rv0 String xmlstr="";
mM j*Vw e8^0 HSSFWorkbook workbook=null; 51Testing软件测试网ZHjfUB
try{ 51Testing软件测试网1ZogRw
fis=new FileInputStream(temp_excelPath);
W?#L TUex Gx Ru&f0 workbook=new HSSFWorkbook(fis); 51Testing软件测试网:I/hd#k7V BuE$IB.b
int sheetnum=workbook.getNumberOfSheets() ;
7R:lg0zD/D0 if(sheetnum>0){
xQLw dGy|`0dv0 HSSFSheet hs=workbook.getSheetAt(0);
z(k4V_ b$c0 String tempstr="";
}@8U$SX;SE6c0 int rownum=hs.getPhysicalNumberOfRows(); 51Testing软件测试网+Z7As/[ ^[:?
System.out .println("r="+rownum) ; 51Testing软件测试网(eO})t%ikb#d
if(rownum>0){ 51Testing软件测试网/Z'h6LJ&l+xS
for(int i=0;i<rownum;i++){
!N:v%N nL-Y1f{0 tempstr=""; 51Testing软件测试网G&YLK:hVE(k
HSSFRow hr=hs.getRow(i);
n;@My"b _0 int colnum=hr.getPhysicalNumberOfCells(); 51Testing软件测试网Y5b/|S's#L
System.out .println("c="+colnum) ; 51Testing软件测试网T)qM I]I'as
if(colnum>0){
[(z,H[%Px@0 for(short j=0;j<colnum;j++){
eGz%e+b0 HSSFCell hc=hr.getCell(j) ; 51Testing软件测试网*VZg"l-Uy)`H
System.out.println("type="+hc.getCellType()) ; 51Testing软件测试网R0~(YuJ
/*if( HSSFDateUtil.isCellDateFormatted(hc)){ 51Testing软件测试网!G8D-wl:r0}a
Date date=hc.getDateCellValue();
t;zg:K#g K1`0 tempstr+="<Cell>"+date.toString()+"</Cell>"; 51Testing软件测试网D'HD;G"`6|H&iR
System.out .println("tempstr11="+tempstr) ;
!uR pq5oY0 }else{*/ 51Testing软件测试网_s`GQ&Q
SEbA~?0 if(hc.getCellType()==HSSFCell.CELL_TYPE_STRING){ 51Testing软件测试网]z`QO%i;E.T
tempstr+="<Cell>"+hc.getStringCellValue()+"</Cell>"; 51Testing软件测试网wNrf%~7{{+|i4n
System.out .println("tempstr22="+tempstr) ; 51Testing软件测试网Vc \N"h7d.\
}
/}.D+wiT3dd0iGRT0 if(hc.getCellType()==HSSFCell.CELL_TYPE_NUMERIC ){
-xx-`Rvo0GQ&x0L!cT0 tempstr+="<Cell>"+Double.toString(hc.getNumericCellValue())+"</Cell>";
QEG%@ZL&V0 System.out .println("tempstr33="+tempstr) ;
o*\ J3n n8C6^}h0 } 51Testing软件测试网K4{0S~SBQ@p
if(hc.getCellType()==HSSFCell.CELL_TYPE_FORMULA ){
K~/Q.O;QR)Y!cOG0 tempstr+="<Cell>"+hc.getCellFormula()+"</Cell>"; 51Testing软件测试网&c"d*y$J7`C7O8Vv
System.out .println("tempstr33="+tempstr) ; 51Testing软件测试网4aR1T~)q _
} 51Testing软件测试网)| c+s-dW@`ww
TO?(ddi1F,j0 //} 51Testing软件测试网Q9N/OqgAj
} 51Testing软件测试网r4e/O6} {A
xmlstr+="<Row>"+tempstr+"</Row>"; 51Testing软件测试网XuN\ J2~
}
5h_-y'[&c0 }
+SwN3~4iR Eb0 xmlstr="<Table>"+xmlstr+"<Table>"; 51Testing软件测试网:V V-W)Rn a/w
} 51Testing软件测试网b&LuLT.~c
} 51Testing软件测试网V!i'y |IY
51Testing软件测试网tDnU$e^
}catch(Exception e){
*II!F"N yp{0 e.printStackTrace() ;
8Y w2Ib)sF o e#f0 }finally{ 51Testing软件测试网p5`H9Z7ig
if(fis!=null){
V9d"@M?l}%v0}0 try{ 51Testing软件测试网%P@ K0f9?
fis.close() ;
p]zk0KL`k0 }catch(Exception e){ 51Testing软件测试网z{-r d8nznP
e.printStackTrace() ;
S,g2R)m*]h"M0 } 51Testing软件测试网9_,NJu)hW4RfY
}
c1`A T n0 }
FileInputStream fis=null;
U-_fZ my)rv0 String xmlstr="";
mM j*Vw e8^0 HSSFWorkbook workbook=null; 51Testing软件测试网ZHjfUB
try{ 51Testing软件测试网1ZogRw
fis=new FileInputStream(temp_excelPath);
W?#L TUex Gx Ru&f0 workbook=new HSSFWorkbook(fis); 51Testing软件测试网:I/hd#k7V BuE$IB.b
int sheetnum=workbook.getNumberOfSheets() ;
7R:lg0zD/D0 if(sheetnum>0){
xQLw dGy|`0dv0 HSSFSheet hs=workbook.getSheetAt(0);
z(k4V_ b$c0 String tempstr="";
}@8U$SX;SE6c0 int rownum=hs.getPhysicalNumberOfRows(); 51Testing软件测试网+Z7As/[ ^[:?
System.out .println("r="+rownum) ; 51Testing软件测试网(eO})t%ikb#d
if(rownum>0){ 51Testing软件测试网/Z'h6LJ&l+xS
for(int i=0;i<rownum;i++){
!N:v%N nL-Y1f{0 tempstr=""; 51Testing软件测试网G&YLK:hVE(k
HSSFRow hr=hs.getRow(i);
n;@My"b _0 int colnum=hr.getPhysicalNumberOfCells(); 51Testing软件测试网Y5b/|S's#L
System.out .println("c="+colnum) ; 51Testing软件测试网T)qM I]I'as
if(colnum>0){
[(z,H[%Px@0 for(short j=0;j<colnum;j++){
eGz%e+b0 HSSFCell hc=hr.getCell(j) ; 51Testing软件测试网*VZg"l-Uy)`H
System.out.println("type="+hc.getCellType()) ; 51Testing软件测试网R0~(YuJ
/*if( HSSFDateUtil.isCellDateFormatted(hc)){ 51Testing软件测试网!G8D-wl:r0}a
Date date=hc.getDateCellValue();
t;zg:K#g K1`0 tempstr+="<Cell>"+date.toString()+"</Cell>"; 51Testing软件测试网D'HD;G"`6|H&iR
System.out .println("tempstr11="+tempstr) ;
!uR pq5oY0 }else{*/ 51Testing软件测试网_s`GQ&Q
SEbA~?0 if(hc.getCellType()==HSSFCell.CELL_TYPE_STRING){ 51Testing软件测试网]z`QO%i;E.T
tempstr+="<Cell>"+hc.getStringCellValue()+"</Cell>"; 51Testing软件测试网wNrf%~7{{+|i4n
System.out .println("tempstr22="+tempstr) ; 51Testing软件测试网Vc \N"h7d.\
}
/}.D+wiT3dd0iGRT0 if(hc.getCellType()==HSSFCell.CELL_TYPE_NUMERIC ){
-xx-`Rvo0GQ&x0L!cT0 tempstr+="<Cell>"+Double.toString(hc.getNumericCellValue())+"</Cell>";
QEG%@ZL&V0 System.out .println("tempstr33="+tempstr) ;
o*\ J3n n8C6^}h0 } 51Testing软件测试网K4{0S~SBQ@p
if(hc.getCellType()==HSSFCell.CELL_TYPE_FORMULA ){
K~/Q.O;QR)Y!cOG0 tempstr+="<Cell>"+hc.getCellFormula()+"</Cell>"; 51Testing软件测试网&c"d*y$J7`C7O8Vv
System.out .println("tempstr33="+tempstr) ; 51Testing软件测试网4aR1T~)q _
} 51Testing软件测试网)| c+s-dW@`ww
TO?(ddi1F,j0 //} 51Testing软件测试网Q9N/OqgAj
} 51Testing软件测试网r4e/O6} {A
xmlstr+="<Row>"+tempstr+"</Row>"; 51Testing软件测试网XuN\ J2~
}
5h_-y'[&c0 }
+SwN3~4iR Eb0 xmlstr="<Table>"+xmlstr+"<Table>"; 51Testing软件测试网:V V-W)Rn a/w
} 51Testing软件测试网b&LuLT.~c
} 51Testing软件测试网V!i'y |IY
51Testing软件测试网tDnU$e^
}catch(Exception e){
*II!F"N yp{0 e.printStackTrace() ;
8Y w2Ib)sF o e#f0 }finally{ 51Testing软件测试网p5`H9Z7ig
if(fis!=null){
V9d"@M?l}%v0}0 try{ 51Testing软件测试网%P@ K0f9?
fis.close() ;
p]zk0KL`k0 }catch(Exception e){ 51Testing软件测试网z{-r d8nznP
e.printStackTrace() ;
S,g2R)m*]h"M0 } 51Testing软件测试网9_,NJu)hW4RfY
}
c1`A T n0 }
TAG: