请教:JAVA怎么检索EXCEL并返回是哪个单元格,最好能把检索到的单元格高亮起来。
发布网友
发布时间:2022-05-19 19:19
我来回答
共1个回答
热心网友
时间:2023-10-16 12:45
HSSF POI
package com.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
public class ThreadGroupDemo{
public static void main(String args[]){
InputStream in;
try {
in = new FileInputStream("d:/test.xls");
HSSFWorkbook work = new HSSFWorkbook(in);
HSSFSheet sheet = work.getSheetAt(0);
HSSFRow row=sheet.getRow(16);
Iterator<Cell> cells=row.cellIterator();
while(cells.hasNext()){
Cell cell= cells.next();
System.out.println(cell);
try{
Double d=Double.parseDouble(cell.toString());
System.out.println(d);
}catch(Exception e){
e.printStackTrace();
}
CellStyle cst=cell.getCellStyle();
int a=cst.getFillBackgroundColor();
int b=cst.getFillForegroundColor();
System.out.println(a+"--"+b);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
这是个能得到单元格背景色的东西(当然也可以设置背景色).我拿的是十六行一行的背景..希望对你有用