opflowwriter.java

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

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

import java.io.File;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

/*
 * type
 * op1,file1
 * rep,sid,tid
 * pattern,nodeid,value
 */
public class OpFlowWriter {
	public static String EOF = "EOF"; // end of file

	public static String SHEET = "OPFLOW";

	public static String CLIENT_FLOW = "0";

	public static String SERVER_FLOW = "1";

	public static String REPLACE_ITEM = "0";

	public static String PATTERN_ITEM = "1";

	public static String FILE_ITEM = "2";

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

	private File file;

	private WritableWorkbook book;

	private WritableSheet sheet;

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

	public boolean open(String fileName) {
		try {
			logger.setSuppressWarnings(Boolean.getBoolean("jxl.nowarnings"));
			file = new File(fileName);
			book = Workbook.createWorkbook(file);
			sheet = book.createSheet(SHEET, 0);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return true;
	}

	public boolean writeFlowType(String flowType) {
		Label lb1 = new Label(0, 0, flowType);
		try {
			sheet.addCell(lb1);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return true;
	}

	public boolean writeNextItem(String itemType, String value1, String value2) {
		Label lb1 = new Label(0, currentLine, itemType);
		Label lb2 = new Label(1, currentLine, value1);
		Label lb3 = new Label(2, currentLine, value2);

		try {
			sheet.addCell(lb1);
			sheet.addCell(lb2);
			sheet.addCell(lb3);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		currentLine++;
		return true;
	}

	public boolean close() {
		try {
			Label lb1 = new Label(0, currentLine, EOF);
			sheet.addCell(lb1);
			book.write();
			book.close();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return true;
	}

	/**
	 * @param args
	 */
	public static void main_(String[] args) {
		// TODO Auto-generated method stub
		OpFlowWriter op = new OpFlowWriter();
		op.open("test1.xls");
		op.writeFlowType(OpFlowWriter.CLIENT_FLOW);
		op.writeNextItem(OpFlowWriter.REPLACE_ITEM, "1.2.3", "4.5.6");
		op.writeNextItem(OpFlowWriter.PATTERN_ITEM, "1.2.3", "hello");
		op.writeNextItem(OpFlowWriter.FILE_ITEM, "d:\\x\\y.op", "");
		op.close();
	}

}

⌨️ 快捷键说明

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