opflowreader.java

来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 93 行

JAVA
93
字号
package com.corba.mnq.xls;

import java.io.File;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class OpFlowReader {

	public static String EOF = OpFlowWriter.EOF;

	public static String SHEET = OpFlowWriter.SHEET;

	private int currentLine = 1; // 0 was reserved by writeOp

	private static common.Logger logger = common.Logger
			.getLogger(OpFlowReader.class);

	private File file;

	private Workbook book;

	private Sheet sheet;

	class FlowItemStruct {
		public String type;

		public String value1;

		public String value2;
	}

	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 String getFlowType() {
		Cell cell = sheet.getCell(0, 0);
		return cell.getContents();
	}

	public FlowItemStruct getNextItem() {
		FlowItemStruct ret = new FlowItemStruct();
		Cell cell = sheet.getCell(0, currentLine);
		ret.type = cell.getContents();
		cell = sheet.getCell(1, currentLine);
		ret.value1 = cell.getContents();
		cell = sheet.getCell(2, currentLine);
		ret.value2 = cell.getContents();
		currentLine++;
		return ret;
	}

	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) {

		OpFlowReader op = new OpFlowReader();
		op.open("test1.xls");

		String type = op.getFlowType();
		System.out.println("flowtype=" + type);

		while (!op.eof()) {
			OpFlowReader.FlowItemStruct ps = op.getNextItem();
			System.out.println(ps.type + "," + ps.value1 + "," + ps.value2);
		}
		op.close();
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?