这期内容当中小编将会给大家带来有关java怎样操作excel表,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
package excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
public class ReadExcel
{
public void readExcel()
{
try {
//构建Workbook对象, 只读Workbook对象
//直接从本地文件创建Workbook //从输入流创建Workbook
File file = new File("E:/temp/HodeOA_2005/Book1.xls");
InputStream is = new FileInputStream(file);
Workbook rwb = Workbook.getWorkbook(is);
//获得工作薄(Workbook)中工作表(Sheet)的个数
//int sheets = rwb.getNumberOfSheets();
//返回工作薄(Workbook)中工作表(Sheet)对象数组
Sheet[] sheets = rwb.getSheets();
for (int i = 0; i
System.out.println("-------------------------------");
System.out.println("【工作表Sheet"+i+"的信息】");
//获取获取工作表(Sheet)的名称
String sheetName = sheets[i].getName();
System.out.println("Sheet名称:" + sheetName);
//获取Sheet表中所包含的总列数
int rsColumns = sheets[i].getColumns();
System.out.println("Sheet总列数:" + rsColumns);
//获取Sheet表中所包含的总行数
int rsRows = sheets[i].getRows();
System.out.println("Sheet总行数:" + rsRows);
//逐行输出单元格信息
System.out.println("Sheet内容:" + rsRows);
for (int j = 0; j
System.out.print("行"+j+":");
//获取某一行的所有单元格,返回的是单元格对象数组,示例子:
Cell[] cell = sheets[i].getRow(j);
for (int k = 0; k
//获取单元内容
String cellContent = cell[k].getContents();
//获取单元类型
CellType cellType= cell[k].getType();
System.out.print(" "+cellContent+"["+cellType+"] ");
}
System.out.println();
}
}
rwb.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
ReadExcel re = new ReadExcel();
re.readExcel();
}
}
[@more@]package excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
public class ReadExcel
{
public void readExcel()
{
try {
//构建Workbook对象, 只读Workbook对象
//直接从本地文件创建Workbook //从输入流创建Workbook
File file = new File("E:/temp/HodeOA_2005/Book1.xls");
InputStream is = new FileInputStream(file);
Workbook rwb = Workbook.getWorkbook(is);
//获得工作薄(Workbook)中工作表(Sheet)的个数
//int sheets = rwb.getNumberOfSheets();
//返回工作薄(Workbook)中工作表(Sheet)对象数组
Sheet[] sheets = rwb.getSheets();
for (int i = 0; i
System.out.println("-------------------------------");
System.out.println("【工作表Sheet"+i+"的信息】");
//获取获取工作表(Sheet)的名称
String sheetName = sheets[i].getName();
System.out.println("Sheet名称:" + sheetName);
//获取Sheet表中所包含的总列数
int rsColumns = sheets[i].getColumns();
System.out.println("Sheet总列数:" + rsColumns);
//获取Sheet表中所包含的总行数
int rsRows = sheets[i].getRows();
System.out.println("Sheet总行数:" + rsRows);
//逐行输出单元格信息
System.out.println("Sheet内容:" + rsRows);
for (int j = 0; j
System.out.print("行"+j+":");
//获取某一行的所有单元格,返回的是单元格对象数组,示例子:
Cell[] cell = sheets[i].getRow(j);
for (int k = 0; k
//获取单元内容
String cellContent = cell[k].getContents();
//获取单元类型
CellType cellType= cell[k].getType();
System.out.print(" "+cellContent+"["+cellType+"] ");
}
System.out.println();
}
}
rwb.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
ReadExcel re = new ReadExcel();
re.readExcel();
}
}
上述就是小编为大家分享的java怎样操作excel表了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注编程网行业资讯频道。