opreader.java
来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 137 行
JAVA
137 行
package com.corba.mnq.xls;
import java.io.File;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class OpReader {
public static String EOF = OpWriter.EOF;
public static String SHEET = OpWriter.SHEET;
public static String XXX_NAME = OpWriter.XXX_NAME;
private int currentLine = 1; // 0 was reserved by writeOp
private static common.Logger logger = common.Logger.getLogger(OpReader.class);
private File file;
private Workbook book;
private Sheet sheet;
private Sheet xxx;
class OpStruct {
public String opname;
public String cname;
public String ior;
}
class ParStruct {
public String id;
public String value;
}
public boolean open(String fileName) {
try {
logger.setSuppressWarnings(Boolean.getBoolean("jxl.nowarnings"));
file = new File(fileName);
book = Workbook.getWorkbook(file);
sheet = book.getSheet(SHEET);
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return true;
}
public boolean openXXX(String fileName) {
try {
logger.setSuppressWarnings(Boolean.getBoolean("jxl.nowarnings"));
file = new File(fileName);
book = Workbook.getWorkbook(file);
xxx = book.getSheet(XXX_NAME);
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return true;
}
public OpStruct getOp() {
OpStruct ret = new OpStruct();
Cell cell = sheet.getCell(0, 0);
ret.opname = cell.getContents();
cell = sheet.getCell(1, 0);
ret.cname = cell.getContents();
cell = sheet.getCell(2, 0);
ret.ior = cell.getContents();
return ret;
}
public OpStruct getOpXXX() {
OpStruct ret = new OpStruct();
Cell cell = xxx.getCell(0, 0);
ret.opname = cell.getContents();
cell = xxx.getCell(1, 0);
ret.cname = cell.getContents();
cell = xxx.getCell(2, 0);
ret.ior = cell.getContents();
return ret;
}
public ParStruct getNextPar() {
ParStruct ret = new ParStruct();
Cell cell = sheet.getCell(0, currentLine);
ret.id = cell.getContents();
cell = sheet.getCell(1, currentLine);
ret.value = cell.getContents();
currentLine++;
return ret;
}
public String getNextParXXX(int col, int line) {
Cell cell = xxx.getCell(col, line);
return cell.getContents();
}
public boolean eof() {
Cell cell = sheet.getCell(0, currentLine);
return cell.getContents().equals(EOF);
}
public boolean close() {
book.close();
return true;
}
/**
* @param args
*/
public static void main_(String[] args) {
OpReader op = new OpReader();
op.open("test.xls");
OpReader.OpStruct r = op.getOp();
System.out.println("opname=" + r.opname + ",cname=" + r.cname + ",ior=" + r.ior);
while (!op.eof()) {
OpReader.ParStruct ps = op.getNextPar();
System.out.println(ps.id + "=" + ps.value);
}
op.close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?