XLSBeans.load 数据读不出来

wangzhongquan_ 发布于 2012/07/31 09:31
阅读 183
收藏 0

一个EXCEL表,一个BEAN,一个BEANLIST,和一个TEST.JAVA

 

package test;

import wzq.annotation.Column;

public class Workbean {
	private String buybook;
	private String write;
	private String read;
	public String getBuybook() {
		return buybook;
	}
	@Column(columnName="buybook")//这里配置EXCEL表中的对应的列名
	public void setBuybook(String buybook) {
		this.buybook = buybook;
	}
	public String getWrite() {
		return write;
	}
	@Column(columnName="write")//这里配置EXCEL表中的对应的列名
	public void setWrite(String write) {
		this.write = write;
	}
	public String getRead() {
		return read;
	}
	@Column(columnName="read")//这里配置EXCEL表中的对应的列名
	public void setRead(String read) {
		this.read = read;
	}
}

package test;

import java.util.List;

import wzq.annotation.HorizontalRecords;
import wzq.annotation.Sheet;

@Sheet(name="Sheet1")
public class WorkList {
	List<Workbean> list = null;

	public List<Workbean> getList() {
		return list;
	}
	@HorizontalRecords(tableLabel="works",recordClass=Workbean.class)
	public void setList(List<Workbean> list) {
		this.list = list;
	}
	
}

package test;

import java.util.List;

import wzq.XLSBeans;
import wzq.XLSBeansException;

public class Test {
	public static void main(String[] args) {
		WorkList worklist = null;
		List<Workbean> list = null;
		
		try {
			worklist = new XLSBeans().load(Test.class.getResourceAsStream("work.xls"),WorkList.class);
		} catch (XLSBeansException e) {
			e.printStackTrace();
		}
		list = worklist.getList();
		for (Workbean workbean : list) {
			System.out.println(workbean.getBuybook());
		}
	}
}

 

结果报错:

 

wzq.XLSBeansException: Column 'buybook' doesn't exist.
	at wzq.processor.RecordsProcessorUtil.checkColumns(RecordsProcessorUtil.java:41)
	at wzq.processor.HorizontalRecordsProcessor.createRecords(HorizontalRecordsProcessor.java:140)
	at wzq.processor.HorizontalRecordsProcessor.doProcess(HorizontalRecordsProcessor.java:40)
	at wzq.XLSBeans.loadSheet(XLSBeans.java:81)
	at wzq.XLSBeans.load(XLSBeans.java:196)
	at wzq.XLSBeans.load(XLSBeans.java:165)
	at wzq.XLSBeans.load(XLSBeans.java:54)
	at test.Test.main(Test.java:14)
Exception in thread "main" java.lang.NullPointerException
	at test.Test.main(Test.java:18)

请教高手,buybook这一列在EXCEL中有,注解中也配置好了的,为什么它读不出来,如果我把buybook这一列从表和注解中去掉,结果又是正常的,何解?

加载中
返回顶部
顶部