span8
span4
我使用AttributeCreator为Excel writer准备一个列列表(a、B、C、D等)。我的问题是这份清单有4000项。我必须手动公开每个列标签,这是不可行的。我查了又查,没有找到解决办法。是否有一种方法,与PythonCaller标签的功能,作为公开?
在这种情况下,用Python代码替换更多的转换器可以极大地提高性能。例如:
# PythonCaller脚本示例导入fmeobjects #获取对应于列索引的Excel列名(A、B、C、…)。基于0的列索引def xlsxColumnName(index): alpha = ",而0 <= index: alpha = chr(index % 26 + 65) + alpha index = index // 26 - 1返回alpha类的FeatureProcessor(object): def init__(self): self。column_index = 0。is_target = lambda attr: \ not '(1900/01/00)' in attr \ and not attr.startswith('fme_') \ and not attr.startswith('csv_') def input(self, feature): # Collect target attribute names.如果self.is_target(a)] #第一列(列索引= 0)值是属性名,那么attribs = [a for a in features . getallattributenames () if self.is_target(a)]假设第一个引入的特性具有所有的目标属性。如果自我。column_index == 0: # Create and output a schema feature at first.numColumns = int(FME_MacroValues['NUM'])模式= fmeobjects.FMEFeature()模式。setAttribute('fme_feature_type_name', \ FME_MacroValues['DestExcelSheetName']) schema.setAttribute('fme_schema_handling', 'schema_only') for i in range(numColumns): schema.setAttribute('attribute{%d}.name' % i, xlsxColumnName(i)) schema.setAttribute('attribute{%d}.fme_data_type' % i, 'fme_real64') self.pyoutput(schema) item = fmeobjects.FMEFeature() for attr in attribs: item.setAttribute('_attr_name', attr) item.setAttribute('A', attr) self.pyoutput(item) self.column_index = 1 # Explode the incoming feature with the target attributes.项目= fmeobjects.FMEFeature() columnName = xlsxColumnName(self.column_index),用于attribs: item中的attr。setAttribute (_attr_name, attr)项目。setAttribute(columnName, feature.getAttribute(attr)) self.pyoutput(item) self.column_index += 1
还有改进的余地。
待续(或许)。
どういたしまして^ ^
此外,可以用一个PythonCreator替换前面示例中的CSV阅读器和所有转换器,这大大提高了性能。
如果csv字段不是要处理的目标,那么def close(self): # Return True。nottarget=lambda字段:\'(1900/01/00)'(在字段中返回与列索引相对应的Excel列名(A、B、C…)。#索引:基于0的列索引def xlsxcolumnname(index):name='',而0<=索引:name=chr(索引%26+65)+name index=index//26-1返回名称创建并输出架构功能。schema=fmeobjects.fme feature()attrttovalue={fme_feature_type_name':fme_macrovalues['destExcelSheetName','fme_schema_handling':'schema_only',}对于attr,值在attrttoValue.items():schema.setattribute(attr,value)对于范围内的i(int(fme_macrovalues['num']):schema.setattribute('attribute{%d}.name'%i,xlsxcolumnname(i)schema.setattribute('attribute{%d}.fme_data_type'%i,'fme_real64')self.pyoutput(schema)从源csv表获取单元格值并将其保存到字典中。#key=0为源字段(目标行)的索引;value=dictionary{destination column name:cell value}data={},open(fme_macrovalues['sourcedataset_csv2'],'r')为csvfile:nontargets=non e for i,row in enumerate(csv.reader(csvfile)):\collect from the first row(即字段名)。如果i==0:nontargets={k代表k,v代表枚举(row)如果nottarget(v)}c=xlsxcolumnname(i)代表k,v代表枚举(row):如果k不在nontargets:data.setdefault(k,{})[c]=v为目标excel表中的每一行创建和输出数据功能。对于排序中的k(data.keys()):feature=fmeobjects.fmefeature()对于数据中的c,v[k].items():feature.setattribute(c,v)self.pyoutput(feature)
excel编写器功能类型中的动态架构配置
如果不需要将字段名(A、B、C…)写入第一行,
您好!@FJCharp公司,我认为在聚合每个原始csv字段名的项功能之前,将属性重命名为目标excel列名会更容易,而不是创建一个列表然后重命名其元素。
如果将工作区实现为动态工作流,fme可以将属性重命名为目标excel列名,还可以自动配置目标要素类型架构。亚搏在线我认为本文中描述的方法适合于这种情况。
©2019安全亚搏在线软件公司法律