易截截图软件、单文件、免安装、纯绿色、仅160KB

java读取本地excel文件代码

package cn.com.view.read;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadExcel {
 
 public static void main(String[] args){
  read("d://air.xls");
 }
 
 public static Cell[][] read(String fileName){
  Workbook rwb = null;
  InputStream is;
  try {
   is = new FileInputStream(fileName);
   rwb = Workbook.getWorkbook(is);
   
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (BiffException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  int sheets = rwb.getNumberOfSheets();
  Sheet rs = rwb.getSheet(0);
  String sheetName = rs.getName();//获取Sheet的名称
  int rsColumns = rs.getColumns();//获取Sheet表中所包含的总列数
  Cell[] cellCol = rs.getColumn(1);  //获取某一列的所有单元格,返回的是单元格对象数组
  int rsRows = rs.getRows();  //获取Sheet表中所包含的总行数
  Cell[] cellRow = rs.getRow(1); //获取某一行的所有单元格,返回的是单元格对象数组
//  Cell cell = rs.getCell(0, 0); //第一个是列数,第二个是行数
  System.out.println("Sheet的个数:"+sheets);
  System.out.println("Sheet的名称:"+sheetName);
  System.out.println("列数:"+rsColumns);
  System.out.println("行数:"+rsRows);
 /* for(int i = 0;i < cellCol.length;i++){
   System.out.println("第一列字段:"+cellCol[i].getContents());
  


相关文档:

关于java中的URL类的使用一个问题


      我使用URL类来访问FTP服务器,当地址中没有中文时没有问题,但是
    当ftp中的文件夹有中文时,就无法访问了,我试过encoder和decoder类,都不行,有什么解决方法么?
            URL now = new URL("ftp://202.204.208.124/软件/");
......

[备份]java中XML解析利器 dom4j的使用简介


要使用dom4j读写XML文档,需要先下载dom4j包,dom4j官方网站在 http://www.dom4j.org/
目前最新dom4j包下载地址: http://nchc.dl.sourceforge.net/sourceforge/dom4j/dom4j-1.6.1.zip
解开后有两个包,仅操作XML文档的话把dom4j-1.6.1.jar加入工程就可以了,如果需要使用XPath的话还需要加入包jaxen-1.1-beta-7.jar.
以下 ......

Java可变参数列表

public class TestClass{
public static void main(String args[]){
VarArgs(1, "one");
VarArgs(2, "one", "two");
VarArgs(3, "one", "two", "three");
VarArgs(0); // Attention!
}
static void VarArgs(int nRequired, String... trailing){
System.out.print("Required: " + nRequired + " "); ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号