导出数据时如何重命名excel标题列名称?

问题描述

通过ImpEx导出数据时,如何在项目属性旁边重命名添加新列?

我有以下内容

"#% impex.setTargetFile( ""attributes.csv"",true );"
insert_update ClassificationAttribute; pk[unique=true]; code ; creationtime; classes

但是我想除了代码和creationTime之外,还有它们的类和子类别/超类别的名称代码。目前,我只能获得PK。

我想重命名列,例如:code重命名attribute_code

解决方法

也许您想了解更多信息,

https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2005/en-US/8bef9530866910148e6cff59d9afa127.html

https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2005/en-US/1c8f5bebdc6e434782ff0cfdb0ca1847.html

https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2005/en-US/8bd9d5bb86691014ba9d95a88ede75f3.html

,

您不能使用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{
  1. 创建用于分类导出的自定义方法。此方法以列表的形式获取与每个分类属性对应的类,并将其转换为一组excel单元格。
  2. 创建一个元Excel工作表,该表存储实际属性与给定别名属性的映射(如果需要重新导入)。
  3. 在DefaultExcelImportService中实施导入的自定义逻辑。这应该使用元数据获取实际属性,将excel列转换为列表等