|
|
|
@ -27,6 +27,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
|
|
|
|
import com.aspose.words.Bookmark;
|
|
|
|
|
import com.aspose.words.Document;
|
|
|
|
|
import com.aspose.words.Field;
|
|
|
|
|
import com.aspose.words.SaveFormat;
|
|
|
|
|
import com.teamcenter.rac.aif.AIFDesktop;
|
|
|
|
|
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
|
|
|
@ -56,12 +57,16 @@ public class PropertyToWordOrExcelOperation extends KOperation {
|
|
|
|
|
new Thread().sleep(1000);
|
|
|
|
|
InterfaceAIFComponent targetComponent = app.getTargetComponent();
|
|
|
|
|
TCComponentItemRevision revision = (TCComponentItemRevision) targetComponent;
|
|
|
|
|
|
|
|
|
|
// 获取首选项里的值
|
|
|
|
|
String[] prefVals = KUtil.getPrefVals(session, preName);
|
|
|
|
|
if(prefVals == null || prefVals.length == 0) {
|
|
|
|
|
KUtil.info(AIFDesktop.getActiveDesktop(), preName + "该首选项未配置,请联系管理员!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
String relatioin = prefVals[0];
|
|
|
|
|
|
|
|
|
|
// 获取版本对象下的数据集对象
|
|
|
|
|
TCComponent[] relatedComponents = revision.getRelatedComponents(relatioin);
|
|
|
|
|
if(relatedComponents == null || relatedComponents.length == 0) {
|
|
|
|
|
KUtil.info(AIFDesktop.getActiveDesktop(), "选中对象的 " + relatioin + " 关系下没有数据集");
|
|
|
|
@ -76,9 +81,12 @@ public class PropertyToWordOrExcelOperation extends KOperation {
|
|
|
|
|
nameMap.put(split[1],split[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历数据集
|
|
|
|
|
for (TCComponent tcComponent : relatedComponents) {
|
|
|
|
|
if (tcComponent instanceof TCComponentDataset) {
|
|
|
|
|
TCComponentDataset dataset = (TCComponentDataset) tcComponent;
|
|
|
|
|
// 工具包中获取系统临时变量的路径
|
|
|
|
|
File datasetFile = KUtil.getDatasetFile(dataset);
|
|
|
|
|
String type = tcComponent.getType();
|
|
|
|
|
String datasetType = "";
|
|
|
|
@ -198,15 +206,20 @@ public class PropertyToWordOrExcelOperation extends KOperation {
|
|
|
|
|
|
|
|
|
|
private String dealWord2(File datasetFile, TCComponentItemRevision revision, HashMap<String, String> nameMap,String type) throws FileNotFoundException, Exception {
|
|
|
|
|
String path = datasetFile.getAbsolutePath();
|
|
|
|
|
|
|
|
|
|
Document document2 = new Document(new FileInputStream(path));
|
|
|
|
|
OutputStream outputStream = null;
|
|
|
|
|
String newPath = path.replace(".doc", "temp.doc");
|
|
|
|
|
outputStream = new FileOutputStream(newPath);
|
|
|
|
|
Map<String, String> dataMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
for(String key : nameMap.keySet()) {
|
|
|
|
|
String preConfigValue = getPreConfigValue(revision,nameMap,nameMap.get(key));
|
|
|
|
|
|
|
|
|
|
System.out.println("dataMap("+key+","+preConfigValue+")");
|
|
|
|
|
dataMap.put(key, preConfigValue);
|
|
|
|
|
}
|
|
|
|
|
// 遍历文档中所有的书签
|
|
|
|
|
for (Bookmark bookmark : document2.getRange().getBookmarks()) {
|
|
|
|
|
String bookmarkName = bookmark.getName();
|
|
|
|
|
System.out.println("书签名:"+bookmarkName);
|
|
|
|
@ -215,6 +228,21 @@ public class PropertyToWordOrExcelOperation extends KOperation {
|
|
|
|
|
System.out.println("添加内容");
|
|
|
|
|
bookmark.setText(dataMap.get(bookmarkName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历文档中的所有域
|
|
|
|
|
for (Field field : document2.getRange().getFields()) {
|
|
|
|
|
// 获取域的名称
|
|
|
|
|
String fieldName = field.getFieldCode();
|
|
|
|
|
System.out.println("域名:" + fieldName);
|
|
|
|
|
|
|
|
|
|
for(String key : dataMap.keySet()) {
|
|
|
|
|
// 根据字段类型或其他条件设置值
|
|
|
|
|
if(fieldName.contains(key)) {// 假设您想处理表单输入域
|
|
|
|
|
System.out.println("添加内容");
|
|
|
|
|
field.setResult(dataMap.get(key)); // 设置域的值
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(type.equals("doc")) {
|
|
|
|
|
document2.save(outputStream, SaveFormat.DOC);
|
|
|
|
|