All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xworker.dataObject.java.ExcelDataObject.xer.txt Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
^1413358947824
@
sname
ExcelDataObject
slabel
ExcelDataObject
sdescriptors
xworker.lang.MetaDescriptor3
sextends
xworker.dataObject.java.ListDataObject
smany
true
seditCols
2
sinitialization
false
smodifier
public
sinheritDescription
false
Sdescription
#$@text#$@

功能:处理Excel格式的数据的数据对象,使用jxl包处理Excel文件,目前保存到Excel的内容都是文本格式。

Excel数据源:是一个文件。

注意事项:由于所有数据是保存到内存中的,所以:

  • 适合处理小批量数据,处理大批量的数据时可能会速度慢。
  • 如果数据不需要再使用了,调用doActin("clearExcelDatas", actionContext)方法清空临时数据。
  • 调用saveExcelDatas可以保存临时数据到Csv源。

 

 

#$@text#$@ sth_createIndex false @/@actions sname actions sdescriptors xworker.lang.MetaDescriptor3/@actions sth_createIndex false @/@actions/@loadTempDatas sname loadExcelDatas sisSynchronized false sthrowException true suseOtherAction false svarScope Local sdisableGlobalContext false Scode #$@text#$@ import ognl.Ognl; import jxl.Workbook; //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //Excel数据源 def filePath = self.filePath; try{ if(filePath != null && filePath != ""){ filePath = Ognl.getValue(filePath, actionContext); } }catch(Exception e){ } def workbook = null; if(filePath != null){ try{ workbook = Workbook.getWorkbook(new File(filePath)); }catch(Exception e){ log.error("ExcelDataObject: create workbook from file error", e); } } //读取Excel的数据 if(workbook == null){ self.setData(Constants.HEADERS, [:]); self.setData(Constants.DATAS, []); self.setData(Constants.COLUMNCOUNT, 0); }else{ //列最大数 def columnCount = 0; log.info("sheet lengths=" + workbook.getSheets().length); def sheet = null; if(self.sheetName != null && self.sheetName != ""){ sheet = workbook.getSheet(self.sheetName); }else{ sheet = workbook.getSheet(0); } if(sheet == null){ log.warn("ExcelDataObject: sheet is null, sheetName=" + self.sheetName); self.setData(Constants.HEADERS, [:]); self.setData(Constants.DATAS, []); self.setData(Constants.COLUMNCOUNT, 0); return; } //头-标题 def headMap = [:]; def rowCount = sheet.getRows(); def currentRow = 0; if(rowCount > 0 && self.getBoolean("haveHeaders")){ def cell = sheet.getRow(currentRow); currentRow++; columnCount = cell.length; for(int i=0; i装载Csv数据到临时变量里。

sdescriptors xworker.lang.actions.Actions/@GroovyAction sth_createIndex false @/@actions/@clearCsvDatas sname clearExcelDatas sisSynchronized false sthrowException true suseOtherAction false svarScope Local sdisableGlobalContext false Scode #$@text#$@ //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); self.setData(Constants.HEADERS, null); self.setData(Constants.DATAS, null); self.setData(Constants.COLUMNCOUNT, null); #$@text#$@ sdescription

清除临时变量数据,清理后如要对Excel数据操作需要重新装载数据(loadExcelDatas)。

sdescriptors xworker.lang.actions.Actions/@GroovyAction sth_createIndex false @/@actions/@saveCsvDatas sname saveExcelDatas sisSynchronized false sthrowException true suseOtherAction false svarScope Local sdisableGlobalContext false Scode #$@text#$@ import ognl.Ognl; import jxl.Workbook; import jxl.write.Label; //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //Csv数据源 def filePath = self.filePath; try{ if(filePath != null && filePath != ""){ filePath = Ognl.getValue(filePath, actionContext); } }catch(Exception e){ } def workbook = null; if(filePath != null){ try{ def file = new new File(filePath); if(!file.exists() && self.getBoolean("autoCreateExcel")){ workbook = Workbook.createWorkbook(file); }else{ workbook = Workbook.getWorkbook(file); } }catch(Exception e){ log.error("ExcelDataObject: create workbook from file error", e); } } //保存数据 if(workbook == null){ return false; }else{ try{ //数据 def headers = self.getData(Constants.HEADERS); def datas = self.getData(Constants.DATAS); def columnCount = self.getData(Constants.COLUMNCOUNT); //检查最大行数,如果属性映射的列超过了最大列数,那么自动扩充 for(attribute in self.get("attribute@")){ try{ def column = Integer.parse(self.propertyPath.substring(1, self.propertyPath)); if(columnCount < column){ columnCount = column; } }catch(Exception e){ } } if(self.sheetName != null && self.sheetName != ""){ sheet = workbook.getSheet(self.sheetName); }else{ sheet = workbook.getSheet(0); } //移除原有的行,保存新行 while(sheet.getRows() > 0){ sheet.removeRow(0); } int row = 0; //保存头-标题 if(self.getBoolean("haveHeaders")){ for(int i=0; i将临时数据保存到Excel源中,会使用临时变量中的数据覆盖EXCEL源,如果选择自动创建那么会自动创建文件。

sdescriptors xworker.lang.actions.Actions/@GroovyAction sth_createIndex false @/@actions/@load sname doLoad sisSynchronized false sthrowException true suseOtherAction false svarScope Global sdisableGlobalContext false Scode #$@text#$@ //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //临时数据 def datas = self.getData(Constants.DATAS); if(datas == null || datas.size() == 0){ self.doAction("loadExcelDatas", actionContext); datas = self.getData(Constants.DATAS); } def listDataName = "__datas__"; self.set("listData", listDataName); self.set("dataClassName", "java.util.HashMap"); try{ def bindings = actionContext.push(null); bindings.put(listDataName, datas); //使用ListDataObject的load方法 def action = world.getAction("xworker.dataObject.java.ListDataObject/@actions1/@load"); return action.run(actionContext); }finally{ actionContext.pop(); } #$@text#$@ sinterpretationType Action ssaveReturn false sdescriptors xworker.lang.actions.Actions/@GroovyAction @/@actions/@load/@ins sisValidate false sname ins sdescriptors xworker.lang.actions.Inout/@ins @/@actions/@load/@ins/@theData sname theData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@create sname doCreate sisSynchronized false sthrowException true suseOtherAction false svarScope Global sdisableGlobalContext false Scode #$@text#$@ //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //临时数据 def datas = self.getData(Constants.DATAS); if(datas == null || datas.size() == 0){ self.doAction("loadExcelDatas", actionContext); datas = self.getData(Constants.DATAS); } def listDataName = "__datas__"; self.set("listData", listDataName); self.set("dataClassName", "java.util.HashMap"); try{ def bindings = actionContext.push(null); bindings.put(listDataName, datas); //使用ListDataObject的load方法 def action = world.getAction("xworker.dataObject.java.ListDataObject/@actions1/@create"); def obj = action.run(actionContext); if(obj != null && self.getBoolean("autoSave")){ self.doAction("saveCsvDatas", actionContext); } return obj; }finally{ actionContext.pop(); } #$@text#$@ sinterpretationType Action ssaveReturn false sdescriptors xworker.lang.actions.Actions/@GroovyAction @/@actions/@create/@ins sisValidate false sname ins sdescriptors xworker.lang.actions.Inout/@ins @/@actions/@create/@ins/@theData sname theData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@update sname doUpdate sisSynchronized false sthrowException true suseOtherAction false svarScope Global sdisableGlobalContext false Scode #$@text#$@ //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //临时数据 def datas = self.getData(Constants.DATAS); if(datas == null || datas.size() == 0){ self.doAction("loadExcelDatas", actionContext); datas = self.getData(Constants.DATAS); } def listDataName = "__datas__"; self.set("listData", listDataName); self.set("dataClassName", "java.util.HashMap"); try{ def bindings = actionContext.push(null); bindings.put(listDataName, datas); //使用ListDataObject的load方法 def action = world.getAction("xworker.dataObject.java.ListDataObject/@actions1/@update"); def obj = action.run(actionContext); if(obj == true && self.getBoolean("autoSave")){ self.doAction("saveCsvDatas", actionContext); } return obj; }finally{ actionContext.pop(); } #$@text#$@ sinterpretationType Action ssaveReturn false sdescriptors xworker.lang.actions.Actions/@GroovyAction @/@actions/@update/@ins sisValidate false sname ins sdescriptors xworker.lang.actions.Inout/@ins @/@actions/@update/@ins/@theData sname theData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@updateBatch sname updateBatch sisSynchronized false sthrowException true suseOtherAction false svarScope Global sdisableGlobalContext false Scode #$@text#$@ //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //临时数据 def datas = self.getData(Constants.DATAS); if(datas == null || datas.size() == 0){ self.doAction("loadExcelDatas", actionContext); datas = self.getData(Constants.DATAS); } def listDataName = "__datas__"; self.set("listData", listDataName); self.set("dataClassName", "java.util.HashMap"); try{ def bindings = actionContext.push(null); bindings.put(listDataName, datas); //使用ListDataObject的load方法 def action = world.getAction("xworker.dataObject.java.ListDataObject/@actions1/@updateBatch"); def obj = action.run(actionContext); if(obj > 0 && self.getBoolean("autoSave")){ self.doAction("saveCsvDatas", actionContext); } return obj; }finally{ actionContext.pop(); } #$@text#$@ sdescription

批量更新,根据查询条件查找并更新符合条件的记录。

sdescriptors xworker.lang.actions.Actions/@GroovyAction sth_createIndex false @/@actions/@updateBatch/@ins sisValidate false sname ins sdescriptors xworker.lang.actions.Inout/@ins @/@actions/@updateBatch/@ins/@theData sname theData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@updateBatch/@ins/@conditionConfig sname conditionConfig stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@updateBatch/@ins/@conditionData sname conditionData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@delete sname doDelete sisSynchronized false sthrowException true suseOtherAction false svarScope Global sdisableGlobalContext false Scode #$@text#$@ //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //临时数据 def datas = self.getData(Constants.DATAS); if(datas == null || datas.size() == 0){ self.doAction("loadExcelDatas", actionContext); datas = self.getData(Constants.DATAS); } def listDataName = "__datas__"; self.set("listData", listDataName); self.set("dataClassName", "java.util.HashMap"); try{ def bindings = actionContext.push(null); bindings.put(listDataName, datas); //使用ListDataObject的load方法 def action = world.getAction("xworker.dataObject.java.ListDataObject/@actions1/@delete"); def obj = action.run(actionContext); if(obj == true && self.getBoolean("autoSave")){ self.doAction("saveCsvDatas", actionContext); } return obj; }finally{ actionContext.pop(); } #$@text#$@ sinterpretationType Action ssaveReturn false sdescriptors xworker.lang.actions.Actions/@GroovyAction @/@actions/@delete/@ins sisValidate false sname ins sdescriptors xworker.lang.actions.Inout/@ins @/@actions/@delete/@ins/@theData sname theData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@deleteBatch sname deleteBatch sisSynchronized false sthrowException true suseOtherAction false svarScope Global sdisableGlobalContext false Scode #$@text#$@ //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //临时数据 def datas = self.getData(Constants.DATAS); if(datas == null || datas.size() == 0){ self.doAction("loadExcelDatas", actionContext); datas = self.getData(Constants.DATAS); } def listDataName = "__datas__"; self.set("listData", listDataName); self.set("dataClassName", "java.util.HashMap"); try{ def bindings = actionContext.push(null); bindings.put(listDataName, datas); //使用ListDataObject的load方法 def action = world.getAction("xworker.dataObject.java.ListDataObject/@actions1/@deleteBatch"); def obj = action.run(actionContext); if(obj > 0 && self.getBoolean("autoSave")){ self.doAction("saveCsvDatas", actionContext); } return obj; }finally{ actionContext.pop(); } #$@text#$@ sdescription

批量删除,根据查询条件查找并删除符合条件的记录。

sdescriptors xworker.lang.actions.Actions/@GroovyAction sth_createIndex false @/@actions/@deleteBatch/@ins sisValidate false sname ins sdescriptors xworker.lang.actions.Inout/@ins @/@actions/@deleteBatch/@ins/@theData sname theData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@deleteBatch/@ins/@conditionConfig sname conditionConfig stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@deleteBatch/@ins/@conditionData sname conditionData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@query sname doQuery sisSynchronized false sthrowException true suseOtherAction false svarScope Global sdisableGlobalContext false Scode #$@text#$@ //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); //临时数据 def datas = self.getData(Constants.DATAS); if(datas == null || datas.size() == 0){ self.doAction("loadExcelDatas", actionContext); datas = self.getData(Constants.DATAS); } def listDataName = "__datas__"; self.set("listData", listDataName); self.set("dataClassName", "java.util.HashMap"); try{ def bindings = actionContext.push(null); bindings.put(listDataName, datas); //使用ListDataObject的load方法 def action = world.getAction("xworker.dataObject.java.ListDataObject/@actions1/@query"); return action.run(actionContext); }finally{ actionContext.pop(); } #$@text#$@ Sdescription #$@text#$@

可能会包含一个分页信息。

pageInfo.start          记录起始索引
pageInfo.limit            返回记录最大条数
pageInfo.datas         查询的结果,应该是一个List或数组
pageInfo.success   是否查询成功
pageInfo.msg           操作的结果提示信息
pageInfo.totalCount 记录总数
pageInfo.sort           排序字段
pageInfo.dir             排序的方向,ASC或DESC

#$@text#$@ sinterpretationType Action ssaveReturn false sdescriptors xworker.lang.actions.Actions/@GroovyAction @/@actions/@query/@ins sisValidate false sname ins sdescriptors xworker.lang.actions.Inout/@ins @/@actions/@query/@ins/@theData sname conditionConfig stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@query/@ins/@conditionData sname conditionData stypeCheck false soptional true scheck false scheckLevel exception sdescriptors xworker.lang.actions.Inout/@ins/@param @/@actions/@getAttributeDescriptor sname getAttributeDescriptor stype string svalue xworker.dataObject.java.ExcelDataObject/@attribute sinterpretationType Self svarScope Local sdescriptors xworker.lang.actions.Actions/@ValueFactory sth_createIndex false @/@actions/@getMappingFields sname getMappingFields sisSynchronized false sthrowException true suseOtherAction false svarScope Local sdisableGlobalContext false Scode #$@text#$@ import xworker.dataObject.DataObject; //常量类 def Constants = world.getActionClass("xworker.dataObject.java.CsvDataObject/@actions/@Constants", actionContext); def headers = self.getData(Constants.HEADERS); if(headers == null){ //再重新读取一次,有可能之前没有读取过 self.doAction("loadExcelDatas", actionContext); headers = self.getData(Constants.HEADERS); if(headers == null){ return []; } } def datas = []; for(key in headers.keySet()){ datas.add(["colName":key, "colTitle":headers.get(key)]); } return datas; #$@text#$@ sinterpretationType Action screateLocalVarScope false ssaveReturn false sdescriptors xworker.lang.actions.Actions/@GroovyAction sth_createIndex false @/@name sname name sreadOnly false sinheritDescription false svalidateAllowBlank true LvalidateOnBlur true LallowDecimals true LallowNegative true sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false @/@label sname label sreadOnly false sinheritDescription false svalidateAllowBlank true LvalidateOnBlur true LallowDecimals true LallowNegative true sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false @/@filePath sname filePath sinputtype file sshowLabel true ssize 60 scolspan 2 sreadOnly false sinheritDescription false sdescription

文件路径,首先作为Ognl表达式从actionContext获取,如果没有其次当作文件路径名。

svalidateAllowBlank true LvalidateOnBlur true LallowDecimals true LallowNegative true snotXmlAttribute false sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false @/@csvVarName sname sheetName sreadOnly false sinheritDescription false sdescription

如果没有设定取第一个sheet。

svalidateAllowBlank true LvalidateOnBlur true LallowDecimals true LallowNegative true sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false @/@autoSave sname autoSave sinputtype truefalse sreadOnly false sdefault true sinheritDescription false sdescription

如果自动保存,那么当数据对象创建、修改和删除时自动同步到文件或文本变量中。

svalidateAllowBlank true LvalidateOnBlur true LallowDecimals true LallowNegative true sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false @/@haveHeaders sname haveHeaders sinputtype truefalse sreadOnly false sdefault true sinheritDescription false sdescription

是否有顶部的标题行。

svalidateAllowBlank true LvalidateOnBlur true LallowDecimals true LallowNegative true sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false @/@autoCreateCsv sname autoCreateExcel sinputtype truefalse sreadOnly false sdefault true sinheritDescription false sdescription

如果Excel文件不存在,是否自动创建。

svalidateAllowBlank true LvalidateOnBlur true LallowDecimals true LallowNegative true sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false @/@attribute sname attribute slabel Attribute sdescriptors xworker.lang.MetaDescriptor2/@thing sextends xworker.dataObject.Attribute smany true seditCols 2 sdescription

基本类型的属性。

sid attribute szh_label 属性 Szh_description #$@text#$@

attribute things, used to describe the properties of a thing.

description of the property is also used to edit attributes, the properties of the various properties of things, defines how to edit the method described properties can be adjusted by setting the relevant parameters editing interface.

property editor control, the name of the default in the action context "attribute name> + Input, such as attribute named name, then it's the name of the edit control nameInput.

If the specified edit control for the list, drop-down box, multiple choice, radio, etc., you can set the property value to specify the multiple-choice sub-things the value, you can write a getValues action to return the value of multiple-choice at this time getValues should return a List .

this property to achieve a number of things that the default edit control, custom edit control if needed, you can edit the settings by defining the SWT child to achieve things.

#$@text#$@ @/@attribute/@name sname name sgroup Attribute sdescriptors xworker.lang.MetaDescriptor2/@attribute sth_createIndex false @/@attribute/@label sname label sgroup Attribute sdescriptors xworker.lang.MetaDescriptor2/@attribute sth_createIndex false @/@attribute/@propertyPath sname propertyPath ssize 60 scolspan 2 sgroup Attribute sdescription

Ognl表达式,从数据上获取值。

sdescriptors xworker.lang.MetaDescriptor2/@attribute sth_createIndex false @/@thing sname thing slabel Thing sdescriptors xworker.lang.MetaDescriptor2/@thing sextends xworker.dataObject.RelationDataObject smany true seditCols 2 sdescription

与其他数据对象有关联的属性或属性列表。

sid thing szh_label 事物 Szh_description #$@text#$@ MetaDescriptorX是对元事物的扩展,MetaDescriptor3是目前常用的元事物扩展。

因元事物任意事物的结构的结构,如果说Schema是XML的结构的话,那么可以说元事物是Scehma的Schema,所以元事物主要是用来定义结构(描述者或Schema)的事物。

因元事物比较简单,用其直接定义结构功能比较弱,比如通过元事物不能定义属性的类型等,所以在此依次定义MetaDescriptorX了。

事物编辑器的动态输入表单是根据MetaDescriptor3所设计,定义结构的根本是元事物,所以可以根据实际的需要定义元事物的扩展。 #$@text#$@ @/@actions1 sname actions slabel Actions sdescriptors xworker.lang.MetaDescriptor2/@thing sextends xworker.lang.actions.Actions sid actions szh_label 动作 @/@actions1/@name sname name sid name sdescriptors xworker.lang.MetaDescriptor2/@attribute @/@listData sname listData sinputtype text ssize 60 scolspan 2 sgroup DataObject sreadOnly false sdefault __datas__ sinheritDescription false sdescription

不要修改默认值。

svalidateAllowBlank true LvalidateOnBlur false LallowDecimals false LallowNegative false sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false @/@dataClassName sname dataClassName ssize 60 scolspan 2 sgroup DataObject sreadOnly false sdefault java.util.HashMap sinheritDescription false sdescription

不要修改这里面的值。

svalidateAllowBlank true LvalidateOnBlur false LallowDecimals false LallowNegative false sdescriptors xworker.lang.MetaDescriptor3/@attribute sth_createIndex false




© 2015 - 2025 Weber Informatics LLC | Privacy Policy