使用Jacob读取数据的时候,数据也就8000左右,为什么会很慢呢?
求大牛指点下,谢谢
public static void main(String[] args) throws FileNotFoundException, IOException {
String filename="C:/text/1234.xlsx";
ComThread.InitSTA();
/**
* 声明变量
* */
String xuhao = "";
String xuhao1 ="";
String number1 = "";
String number = "";
String name = "";
String mps = "";
String count = "";
// String unit="";
String cl = "";
String lbjzl = "";
String ps = "";
String bz = "";
String unit = "";
String isEndItem = "n";
String pn = "";
int flag = 0;
List list = new LinkedList();
ActiveXComponent xl=new ActiveXComponent("Excel.Application");
xl.setProperty("Visible", new Variant(false));//Excel显示或者隐藏
Dispatch workbooks=xl.getProperty("Workbooks").toDispatch();//获得workBooks
Variant workbookV=workbooks.invoke(workbooks, "Open", //打开Excel
Dispatch.Method,
new Object[] { filename, new Variant(false),//Excel的位置
new Variant(false) },
new int[1]);
Dispatch workbook=workbookV.toDispatch();//获得workbook
Dispatch sheets= Dispatch.get(workbook,"Worksheets").toDispatch();//获得所有的Sheet
int SheetCount=Dispatch.get(sheets,"Count").getInt();//获得有多少个sheet
System.out.println("11111111111111111111111111111111111111111111");
for(int i=1;i<=SheetCount;i++){//遍历sheets
Dispatch sheet = Dispatch.invoke(sheets,
"Item",
Dispatch.Get,
new Object[] { new Integer(i) },
new int[1]).toDispatch();
String sheetName=Dispatch.get(sheet,"Name").toString();//获得sheet的名字
if(sheetName.indexOf("BOM")>=0){//判断sheet名字是否有包含BOM
//System.out.println(sheetName+"------------------------------------------");
Dispatch userRange=Dispatch.call(sheet, "UsedRange").toDispatch();//获取Excel使用的sheet
Dispatch row=Dispatch.call(userRange, "Rows").toDispatch();
int rowCount=Dispatch.get(row,"Count").getInt();//excel的使用的行数
//Dispatch cell=Dispatch.call(userRange, "Columns").toDispatch();
//int cellCount=Dispatch.get(cell,"Count").getInt();//Excel使用列数
int beginPosition = getRecordRow(userRange,1,rowCount);
System.out.println(sheetName+"------------------------------------------"+rowCount);
for(int j=beginPosition;j<=rowCount;j++){//循环Excel中sheet的行数
HashMap partInfo = new HashMap();
number=GetValue(row,"B"+(j-1));
xuhao=GetValue(row,"A"+(j-1));
if (number.equals("物料编号")) {
}else{
//if (xuhao.equals("编制:") && j==){
// break;
//}
if ((!number.equals(""))) {
flag = 0;
partInfo = getPartInfo(xuhao1, number1,
name, mps, count, unit, cl, lbjzl,
ps, pn, bz, isEndItem);
list.add(partInfo);
number1 = number;
xuhao1 =xuhao;
name=GetValue(row, "C"+j);
mps=GetValue(row, "D"+j);
count=GetValue(row, "L"+j);
unit=GetValue(row, "M"+j);
cl=GetValue(row, "N"+j);
lbjzl=GetValue(row, "O"+j);
ps=GetValue(row, "Q"+j);
pn=GetValue(row, "R"+j);
bz=GetValue(row, "T"+j);
if (xuhao.equals("0.1")) {
isEndItem = "y";
} else {
isEndItem = "n";
}