【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“TianenExcel.java”一文,供大家参考学习
//TianenExcel.java
import java.io.File;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
class TianenExcel
{
public static String getText(String path) throws Exception
{
StringBuffer sb = new StringBuffer("");
//打开文件
Workbook book = Workbook.getWorkbook(new File(path));
//sheet数量
int numSheet = book.getNumberOfSheets();
//遍历sheet
for(int i=0;i<numSheet;i++)
{
//获得当前工作单对象
Sheet sheet = book.getSheet(i);
//行数
int numRow = sheet.getRows();
//列数
int numCol = sheet.getColumns();
for(int j=0;j<numRow;j++)
{
for(int k=0;k<numCol;k++)
{
Cell c = sheet.getCell(k,j);
sb.append(c.getContents());
}
}
}
return sb.toString();
}
public static void main(String args[]) throws Exception
{
String s = TianenExcel.getText("齐天大圣孙悟空.xls");
System.out.println(s);
}
}