如何从java中读取excel [英] How to read from excel in java

查看:66
本文介绍了如何从java中读取excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读取excel.Can有人详细解释了这个循环: - 这将是什么输出



for( int i = 1; i< totalNoOfRows; i ++){

for(int j = 0; j< totalNoOfCols; j ++){

arrayExcelData [i-1] [j] = sh.getCell(j,i).getContents();

}

}



我尝试过:



for(int i = 1; i< totalNoOfRows; i ++){

for(int j = 0; j< totalNoOfCols; j ++){

arrayExcelData [i-1] [j] = sh.getCell(j,i).getContents();

}

}

I am reading from excel.Can someone explain this loop in detail :-what will be the output for this

for (int i= 1 ; i < totalNoOfRows; i++) {
for (int j=0; j < totalNoOfCols; j++) {
arrayExcelData[i-1][j] = sh.getCell(j, i).getContents();
}
}

What I have tried:

for (int i= 1 ; i < totalNoOfRows; i++) {
for (int j=0; j < totalNoOfCols; j++) {
arrayExcelData[i-1][j] = sh.getCell(j, i).getContents();
}
}

推荐答案

如果代码正常工作(即:它能够从Excel读取数据)没有错误),您的 arrayExcelData 可能填充了第1行到 totalNoOfRows 的字符串数据(不包括第一行)可能是标题行的行和从索引0到 totalNoOfCols 的列。



您没有指定你正在使用什么样的功能,但我猜它们是jxl。

然后看工作表getCell(int,int) [ ^ ]和细胞getContents() [ ^ ]。
If the code is working (that is: it is able to read data from Excel without an error), your arrayExcelData is probably filled with the string data from the rows 1 to totalNoOfRows (excluding the first row which might be a header row) and columns from index 0 to totalNoOfCols.

You did not specify what kind of functions you are using but I guess they are jxl.
Then see Sheet getCell(int, int)[^] and Cell getContents()[^].


引用:

我正在读取excel.Can有人详细解释这个循环: - 这将是什么输出

I am reading from excel.Can someone explain this loop in detail :-what will be the output for this

为什么不问作者?



当你不理解你的代码在做什么或为什么它做它的作用时,答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java -application.html [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有找到错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。

Why not ask the author ?

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于如何从java中读取excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆