j**a中for循环里的冒号

时间:2013.09.09 发布人:womeiwh

j**a中for循环里的冒号

已解决问题

谷歌womeiwh用户在2013.09.09提交了关于“2046j**a中for循环里的冒号”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-10-25T20:48:10。importj**a.io.FileInputStream;
importj**a.io.FileOutputStream;
importj**a.io.IOException;
importj**a.io.InputStream;
importj**a.io.OutputStream;

importorg.apache.poi.hssf.usermodel.h**SSFWorkbook;
importorg.apache.poi.ss.usermodel.Cell;
importorg.apache.poi.ss.usermodel.Row;
importorg.apache.poi.ss.usermodel.Sheet;
importorg.apache.poi.ss.usermodel.Workbook;
importorg.apache.poi.xssf.usermodel.XSSFWorkbook;

publicclasspair{
publicstaticvoidmain(String[]args)throwsIOException{
Stringpath="y:/";
StringfileName="abc";
StringfileType="xlsx";
//writer(path,fileName,fileType);
read(path,fileName,fileType);
}
publicstaticvoidread(Stringpath,StringfileName,StringfileType)throwsIOException
{
InputStreamstream=newFileInputStream(path+fileName+"."+fileType);
Workbookwb=**ll;
if(fileType.equals("xls")){
wb=newh**SSFWorkbook(stream);
}
elseif(fileType.equals("xlsx")){
wb=newXSSFWorkbook(stream);
}
else{
System.out.println("Wrongexcelformat");
}
Sheetsheet1=wb.getSheetAt(0);
for(Rowrow:sheet1){
for(Cellcell:row){
System.out.print(cell.getNumericCellValue()+"");
}
System.out.println();

}
}
}
这其中的
for(Rowrow:sheet1){
for(Cellcell:row)
是什么意思,用比较笨的传统的for循环应该怎么写?求高手指导!急求!谢谢希望大家能够帮助她。

详细问题描述及疑问:importj**a.io.FileInputStream;
importj**a.io.FileOutputStream;
importj**a.io.IOException;
importj**a.io.InputStream;
importj**a.io.OutputStream;

importorg.apache.poi.hssf.usermodel.h**SSFWorkbook;
importorg.apache.poi.ss.usermodel.Cell;
importorg.apache.poi.ss.usermodel.Row;
importorg.apache.poi.ss.usermodel.Sheet;
importorg.apache.poi.ss.usermodel.Workbook;
importorg.apache.poi.xssf.usermodel.XSSFWorkbook;

publicclasspair{
publicstaticvoidmain(String[]args)throwsIOException{
Stringpath="y:/";
StringfileName="abc";
StringfileType="xlsx";
//writer(path,fileName,fileType);
read(path,fileName,fileType);
}
publicstaticvoidread(Stringpath,StringfileName,StringfileType)throwsIOException
{
InputStreamstream=newFileInputStream(path+fileName+"."+fileType);
Workbookwb=**ll;
if(fileType.equals("xls")){
wb=newh**SSFWorkbook(stream);
}
elseif(fileType.equals("xlsx")){
wb=newXSSFWorkbook(stream);
}
else{
System.out.println("Wrongexcelformat");
}
Sheetsheet1=wb.getSheetAt(0);
for(Rowrow:sheet1){
for(Cellcell:row){
System.out.print(cell.getNumericCellValue()+"");
}
System.out.println();

}
}
}
这其中的
for(Rowrow:sheet1){
for(Cellcell:row)
是什么意思,用比较笨的传统的for循环应该怎么写?求高手指导!急求!谢谢期待您的答案,你无异于雪中送炭,让我感激涕零 !

希望以下的回答,能够帮助你。

第1个回答

用户名:Rowix  

for(Rowrow:sheet1){
for(Cellcell:row)
}
相当于
for(inti=0;i<sheet1.length()-1;i++){//遍历页中的每一行,得到列的集合
for(intj=0;j<sheet1.get(i).length()-1;j++){//遍历列的集合,得到列
//得到列
sheet1.get(i).get(j);

}
}
这是j**a1.6中新添加的遍历,应该叫foreach遍历
:后面的就是你要遍历的对象
:前面例如Rowrow
Row是的类,row是类得对象
比如
List<Row>rowList=newArrayList<Row>();
遍历就有两种方式
1.就是
for(inti=0;i<rowList.size()-1;i++){
//得到
Rowrow=newRow();
row=rowList.get(i);

}
2.forech
for(Rowrow:rowList){
//直接得到row对象

}
//大致写了些,错的话就不好意思,