问题描述
通过ImpEx导出数据时,如何在项目属性旁边重命名并添加新列?
"#% impex.setTargetFile( ""attributes.csv"",true );"
insert_update ClassificationAttribute; pk[unique=true]; code ; creationtime; classes
但是我想除了代码和creationTime之外,还有它们的类和子类别/超类别的名称和代码。目前,我只能获得PK。
我想重命名列,例如:code
列重命名为attribute_code
解决方法
也许您想了解更多信息,
和
和
,您不能使用impexes来实现此目的,除非您可以拥有两个csv,一个对应于classificationattribute,另一个对应于classsification class:
"#% impex.setTargetFile( ""ClassificationAttribute.csv"",true );"
insert_update ClassificationAttribute; pk[unique=true]; code ; creationtime;classes(&Item)
"#% impex.setTargetFile( ""ClassificationClass.csv"",true );"
insert_update ClassificationClass;&Item;code;name;supercategories(code)
超类别是一个列表,类也是一个列表,在单行impex中不支持列表方案的列表。即使设置了该位置,也无法使用重命名的属性重新导入数据。
但是,您可以使用自定义版本的excel导出和导入来实现相同目的,使用apache POI实现OOTB代码。扩展DefaultExcelExportService
并覆盖创建自定义导出分类属性。如果需要重新导入,请在扩展DefaultExcelImportService
之后编写相反的逻辑:
public class CustomClassificationExportServiceImpl extends DefaultExcelExportService implements CustomExportService{
public class CustomClassificationImportServiceImpl extends DefaultExcelImportService implements CustomImportService{
- 创建用于分类导出的自定义方法。此方法以列表的形式获取与每个分类属性对应的类,并将其转换为一组excel单元格。
- 创建一个元Excel工作表,该表存储实际属性与给定别名属性的映射(如果需要重新导入)。
- 在DefaultExcelImportService中实施导入的自定义逻辑。这应该使用元数据获取实际属性,将excel列转换为列表等