📄 fieldvariable.java
字号:
/*
* Created on 2006-7-26
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package net.excel.report.base.element;
import java.util.Map;
import net.excel.report.datasource.IDataSource;
import net.excel.report.util.AnalyseTempletTool;
/**
* 字段类变量的实现一个字段类变量的具体实例,其代表了某个数据源中的某个具体的字段值。
* @author juny
*/
public class FieldVariable extends Variable{
public FieldVariable(String fieldTemplet){
if(null != fieldTemplet && !"".equals(fieldTemplet)){
setName(fieldTemplet);
String[] temp = fieldTemplet.split(AnalyseTempletTool.DATASOURCE_FIELD_SEPARATOR_REGEX);
if(null != temp && temp.length > 1){
dsName = temp[0].trim();
fieldName = temp[1].trim();
}
}
}
/**
* 设置参数变量的参数
* @param dataSources
*/
public void setDataSource(Map dataSources){
if(null == ds){
ds = (IDataSource)dataSources.get(dsName);
//取得数据字段的类型
String type = ds.getFieldType(fieldName);
if(null != type){
setValueType(type);
}else{
setValueType(UNKNOWN);
}
}
}
/* (non-Javadoc)
* @see excel.report.util.Variable#getType()
*/
public byte getType() {
return VARIABLE_TYPE_FIELD;
}
/* (non-Javadoc)
* @see excel.report.util.Variable#getValue()
*/
public Object getValue() throws Exception {
if(ds.size() <= 0){
ds.queryData();
}
Object value = ds.getValue(fieldName);
if(value != null){
return getValueByType(value);
}
return null;
}
/*
* (non-Javadoc)
* @see net.excel.report.base.element.Variable#getString()
*/
public String getString() throws Exception {
if(ds.size() <= 0){
ds.queryData();
}
Object value = ds.getValue(fieldName);
if(value != null){
return value.toString();
}
return "";
}
public String toString(){
return "[" + dsName + "." +
fieldName + "]";
}
private String dsName = null;
private String fieldName = null;
private IDataSource ds = null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -