java 读取excel文件内容
2015-05-15 09:18
555 查看
代码扫描被读取excel单元格内容
/**
* 读取excel文件单元格内容
* @param model
* @param request
* @param response
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/excelIndex")
public String excel() {
try {
String fileName = "E:/test/testIntoExcel.xls"; // Excel文件所在路径
File file = new File(fileName); // 创建文件对象
Workbook wb = Workbook.getWorkbook(file); // 从文件流中获取Excel工作区对象(WorkBook)
// Sheet st = rwb.getSheet("original");//读取页的方法有两种,一种是使用页名读取,另一种是使用页码读取(从0开始)
Sheet sheet = wb.getSheet(0); // 从工作区中取得页(Sheet)
for (int i = 0; i < sheet.getRows(); i++) { // 扫描行
for (int j = 0; j < sheet.getColumns(); j++) { // 扫描列
Cell cell = sheet.getCell(j, i);
System.err.println(i);
// System.err.println(j);
System.out.println(""+i+""+j+":"+cell.getContents());
System.out.println(cell.getType());
}
System.out.println();
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "excelIndex";
}
读取指定列内每个单元格数据,读取每行的可以根据读取列的进行变通,这里不做累述。
/**
* 获得指定excel指定列的内容
* @param model
* @param request
* @param response
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/getExcelCell")
public String getExcelCell() {
String s="测试3";
try {
String fileName = "E:/test/testIntoExcel.xls"; // Excel文件所在路径
File file = new File(fileName); // 创建文件对象
Workbook wb = Workbook.getWorkbook(file); // 从文件流中获取Excel工作区对象(WorkBook)
// Sheet st = rwb.getSheet("original");//读取页的方法有两种,一种是使用页名读取,另一种是使用页码读取(从0开始)
Sheet sheet = wb.getSheet(0); // 从工作区中取得页(Sheet)
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell = sheet.getCell(j, 0);
if(cell.getContents().equals(s)){
for (int i = 0; i < sheet.getRows(); i++) {
cell = sheet.getCell(j, i);
System.out.println(""+0+""+j+":"+cell.getContents());
System.out.println(cell.getType());
}
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "excelIndex";
}
/**
* 读取excel文件单元格内容
* @param model
* @param request
* @param response
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/excelIndex")
public String excel() {
try {
String fileName = "E:/test/testIntoExcel.xls"; // Excel文件所在路径
File file = new File(fileName); // 创建文件对象
Workbook wb = Workbook.getWorkbook(file); // 从文件流中获取Excel工作区对象(WorkBook)
// Sheet st = rwb.getSheet("original");//读取页的方法有两种,一种是使用页名读取,另一种是使用页码读取(从0开始)
Sheet sheet = wb.getSheet(0); // 从工作区中取得页(Sheet)
for (int i = 0; i < sheet.getRows(); i++) { // 扫描行
for (int j = 0; j < sheet.getColumns(); j++) { // 扫描列
Cell cell = sheet.getCell(j, i);
System.err.println(i);
// System.err.println(j);
System.out.println(""+i+""+j+":"+cell.getContents());
System.out.println(cell.getType());
}
System.out.println();
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "excelIndex";
}
读取指定列内每个单元格数据,读取每行的可以根据读取列的进行变通,这里不做累述。
/**
* 获得指定excel指定列的内容
* @param model
* @param request
* @param response
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/getExcelCell")
public String getExcelCell() {
String s="测试3";
try {
String fileName = "E:/test/testIntoExcel.xls"; // Excel文件所在路径
File file = new File(fileName); // 创建文件对象
Workbook wb = Workbook.getWorkbook(file); // 从文件流中获取Excel工作区对象(WorkBook)
// Sheet st = rwb.getSheet("original");//读取页的方法有两种,一种是使用页名读取,另一种是使用页码读取(从0开始)
Sheet sheet = wb.getSheet(0); // 从工作区中取得页(Sheet)
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell = sheet.getCell(j, 0);
if(cell.getContents().equals(s)){
for (int i = 0; i < sheet.getRows(); i++) {
cell = sheet.getCell(j, i);
System.out.println(""+0+""+j+":"+cell.getContents());
System.out.println(cell.getType());
}
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "excelIndex";
}
相关文章推荐
- 使用Java读取Excel文件内容
- 使用Java读取Excel文件内容
- 使用Java读取Excel文件内容
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- Java中读取Excel文件的内容和导出数据到Excel文件
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- 使用Java读取Excel文件内容
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。
- java读取excel、txt 文件内容,传到、显示到另一个页面的文本框里面。
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例 .
- Java+Flex+POI 解析Excel文件(读取文件中想要的内容)
- Java程序员从笨鸟到菜鸟之(一百零三)java操作office和pdf文件(一)java读取word,excel和pdf文档内容
- Java程序员从笨鸟到菜鸟之(一百零三)java操作office和pdf文件(一)java读取word,excel和pdf文档内容
- Java程序员从笨鸟到菜鸟之(一百零三)java操作office和pdf文件(一)java读取word,excel和pdf文档内容
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例
- java读取EXCEL文件内容
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法
- java读取Excel文件内容公式的处理
- JAVA读取WORD,EXCEL,PDF,TXT,RTF,HTML文件文本内容的方法示例