main
parent
6be6fdb918
commit
83335fb52d
@ -1,2 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/com/connor/jd/plm/handlers/Wf001ScheduleHandler.java=UTF-8
|
||||
encoding//src/com/connor/jd/plm/utils/JDMethodUtil.java=UTF-8
|
||||
|
@ -0,0 +1,264 @@
|
||||
package com.connor.jd.operations;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import com.teamcenter.rac.kernel.TCComponent;
|
||||
|
||||
public class ExcelOperation {
|
||||
private static final String XLS = "xls";
|
||||
private static final String XLSX = "xlsx";
|
||||
|
||||
public static void writeExcel(File file, String outpath, Map<String, List<TCComponent>> jfw) {
|
||||
if (jfw.size() == 1) {
|
||||
writeoneExcel(file, outpath, jfw);
|
||||
} else {
|
||||
writeallExcel(file, outpath, jfw);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeallExcel(File file, String outpath, Map<String, List<TCComponent>> jfw) {
|
||||
Workbook workbook;
|
||||
try {
|
||||
workbook = getworkbook(file);
|
||||
System.out.println("已有文件");
|
||||
Workbook newwb = getWorkbook(outpath);
|
||||
Sheet newsheet = newwb.createSheet();
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
CellStyle style = workbook.createCellStyle();
|
||||
Row row = sheet.getRow(0);
|
||||
row.setRowStyle(style);
|
||||
Row newrow0 = newsheet.createRow(0);
|
||||
for (int i = 0; i < row.getLastCellNum(); i++) {
|
||||
Cell newCell = newrow0.createCell(i);
|
||||
newCell.setCellValue(row.getCell(i).getStringCellValue());
|
||||
}
|
||||
List<CellRangeAddress> cellRangeList = getCombineCell(sheet);
|
||||
for (Entry<String, List<TCComponent>> ever : jfw.entrySet()) {
|
||||
List<TCComponent> itemList = ever.getValue();
|
||||
String sfname = ever.getKey();
|
||||
System.out.println("itemList长度" + itemList.size());
|
||||
for (int i = 0; i < cellRangeList.size(); i++) {
|
||||
CellRangeAddress ca = cellRangeList.get(i);
|
||||
int firstColumn = 0;
|
||||
int firstRow = ca.getFirstRow();
|
||||
int lastRow = ca.getLastRow();
|
||||
Row fRow = sheet.getRow(firstRow);
|
||||
Cell fCell = fRow.getCell(firstColumn);
|
||||
String cellVelue = fCell.getStringCellValue();
|
||||
System.out.println("合并单元格的内容" + cellVelue);
|
||||
System.out.println("起始行" + firstRow + "最后行" + lastRow);
|
||||
if (sfname.equals(cellVelue)) {
|
||||
for (int z = firstRow; z <= lastRow; z++) {
|
||||
Row newRow = sheet.getRow(z);
|
||||
String value = newRow.getCell(1).getStringCellValue();
|
||||
System.out.println("表格内容" + value);
|
||||
for (int p = 0; p < itemList.size(); p++) {
|
||||
if (itemList.get(p).getTCProperty("object_type").getDisplayableValue().equals(value)) {
|
||||
TCComponent[] revlist = itemList.get(p).getTCProperty("revision_list")
|
||||
.getReferenceValueArray();
|
||||
TCComponent component = null;
|
||||
for (int revlength = 0; revlength < revlist.length; revlength++) {
|
||||
String status = revlist[revlength].getProperty("release_status_list");
|
||||
if (!status.equals("")) {
|
||||
component = revlist[revlength];
|
||||
}
|
||||
}
|
||||
String[] info = new String[4];
|
||||
if (component != null) {
|
||||
info[0] = component.getProperty("owning_group");
|
||||
info[1] = component.getProperty("owning_user");
|
||||
info[2] = component.getProperty("creation_date");
|
||||
info[3] = component.getProperty("item_id");
|
||||
} else {
|
||||
info[0] = "";
|
||||
info[1] = "";
|
||||
info[2] = "";
|
||||
info[3] = "";
|
||||
}
|
||||
for (int v = 0; v < info.length; v++) {
|
||||
Cell cellvalue = newRow.createCell(v + 2);
|
||||
cellvalue.setCellValue(info[v]);
|
||||
System.out.println("内容是" + info[v]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(outpath);
|
||||
workbook.write(fos);
|
||||
workbook.close();
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeoneExcel(File file, String outpath, Map<String, List<TCComponent>> jfw) {
|
||||
Workbook workbook;
|
||||
try {
|
||||
workbook = getworkbook(file);
|
||||
System.out.println("已有文件");
|
||||
Workbook newwb = getWorkbook(outpath);
|
||||
Sheet newsheet = newwb.createSheet();
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
CellStyle style = newwb.createCellStyle();
|
||||
Row row = sheet.getRow(0);
|
||||
Row newrow0 = newsheet.createRow(0);
|
||||
for (int i = 0; i < row.getLastCellNum(); i++) {
|
||||
Cell oldCell = row.getCell(i);
|
||||
style.cloneStyleFrom(oldCell.getCellStyle());
|
||||
|
||||
Cell newCell = newrow0.createCell(i);
|
||||
newCell.setCellStyle(style);
|
||||
newCell.setCellValue(oldCell.getStringCellValue());
|
||||
|
||||
}
|
||||
List<CellRangeAddress> cellRangeList = getCombineCell(sheet);
|
||||
for (Entry<String, List<TCComponent>> ever : jfw.entrySet()) {
|
||||
List<TCComponent> itemList = ever.getValue();
|
||||
String sfname = ever.getKey();
|
||||
System.out.println("itemList长度" + itemList.size());
|
||||
for (int i = 0; i < cellRangeList.size(); i++) {
|
||||
CellRangeAddress ca = cellRangeList.get(i);
|
||||
int firstColumn = 0;
|
||||
int firstRow = ca.getFirstRow();
|
||||
int lastRow = ca.getLastRow();
|
||||
Row fRow = sheet.getRow(firstRow);
|
||||
Cell fCell = fRow.getCell(firstColumn);
|
||||
String cellVelue = fCell.getStringCellValue();
|
||||
System.out.println("合并单元格的内容" + cellVelue);
|
||||
System.out.println("起始行" + firstRow + "最后行" + lastRow);
|
||||
|
||||
if (sfname.equals(cellVelue)) {
|
||||
List<String> valueList = new ArrayList<String>();
|
||||
for (int z = firstRow; z <= lastRow; z++) {
|
||||
Row oldRow = sheet.getRow(z);
|
||||
String value = oldRow.getCell(1).getStringCellValue();
|
||||
|
||||
valueList.add(value);
|
||||
}
|
||||
|
||||
for (int j = 1; j <= lastRow - firstRow + 1; j++) {
|
||||
Row newRow = newsheet.createRow(j);
|
||||
Cell cell = newRow.createCell(0);
|
||||
cell.setCellValue(cellVelue);
|
||||
Cell cell2 = newRow.createCell(1);
|
||||
cell2.setCellValue(valueList.get(j - 1));
|
||||
System.out.println("特殊表格内容" + valueList.get(j - 1));
|
||||
for (int p = 0; p < itemList.size(); p++) {
|
||||
if (itemList.get(p).getTCProperty("object_type").getDisplayableValue()
|
||||
.equals(valueList.get(j - 1))) {
|
||||
System.out.println(
|
||||
"类型:" + itemList.get(p).getTCProperty("object_type").getDisplayableValue());
|
||||
TCComponent[] revlist = itemList.get(p).getTCProperty("revision_list")
|
||||
.getReferenceValueArray();
|
||||
TCComponent component = null;
|
||||
for (int revlength = 0; revlength < revlist.length; revlength++) {
|
||||
String status = revlist[revlength].getProperty("release_status_list");
|
||||
if (!status.equals("")) {
|
||||
component = revlist[revlength];
|
||||
}
|
||||
}
|
||||
String[] info = new String[4];
|
||||
if (component != null) {
|
||||
info[0] = component.getProperty("owning_group");
|
||||
info[1] = component.getProperty("owning_user");
|
||||
info[2] = component.getProperty("creation_date");
|
||||
info[3] = component.getProperty("item_id");
|
||||
} else {
|
||||
info[0] = "";
|
||||
info[1] = "";
|
||||
info[2] = "";
|
||||
info[3] = "";
|
||||
}
|
||||
for (int v = 0; v < info.length; v++) {
|
||||
System.out.println("开始创建内容");
|
||||
Cell cellvalue = newRow.createCell(v + 2);
|
||||
cellvalue.setCellValue(info[v]);
|
||||
System.out.println("内容是" + info[v]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CellRangeAddress region = new CellRangeAddress(1, lastRow - firstRow + 1, 0, 0);
|
||||
newsheet.addMergedRegion(region);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(outpath);
|
||||
newwb.write(fos);
|
||||
newwb.close();
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并单元格处理,获取合并行
|
||||
*
|
||||
* @param sheet
|
||||
* @return List<CellRangeAddress>
|
||||
*/
|
||||
public static List<CellRangeAddress> getCombineCell(Sheet sheet) {
|
||||
List<CellRangeAddress> list = new ArrayList<>();
|
||||
// 获得一个 sheet 中合并单元格的数量
|
||||
int sheetmergerCount = sheet.getNumMergedRegions();
|
||||
// 遍历所有的合并单元格
|
||||
for (int i = 0; i < sheetmergerCount; i++) {
|
||||
// 获得合并单元格保存进list中
|
||||
CellRangeAddress ca = sheet.getMergedRegion(i);
|
||||
list.add(ca);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Workbook getWorkbook(String file) throws IOException {
|
||||
Workbook workbook = null;
|
||||
// FileInputStream in = new FileInputStream(file);
|
||||
if (file.endsWith(XLS)) {
|
||||
System.out.println("xls");
|
||||
workbook = new HSSFWorkbook();
|
||||
} else if (file.endsWith(XLSX)) {
|
||||
System.out.println("xlsx");
|
||||
workbook = new XSSFWorkbook();
|
||||
} else {
|
||||
System.out.println("格式错误");
|
||||
}
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public static Workbook getworkbook(File file) throws IOException {
|
||||
Workbook workbook = null;
|
||||
FileInputStream in = new FileInputStream(file);
|
||||
if (file.getName().endsWith(XLS)) {
|
||||
System.out.println("xls");
|
||||
workbook = new HSSFWorkbook(in);
|
||||
} else if (file.getName().endsWith(XLSX)) {
|
||||
System.out.println("xlsx");
|
||||
workbook = new XSSFWorkbook(in);
|
||||
} else {
|
||||
System.out.println("格式错误");
|
||||
}
|
||||
in.close();
|
||||
return workbook;
|
||||
}
|
||||
}
|
@ -1,5 +1,39 @@
|
||||
package com.connor.jd.plm.dialogs;
|
||||
|
||||
public class CSXWHDialog {
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.teamcenter.rac.aif.AbstractAIFApplication;
|
||||
import com.teamcenter.rac.kernel.TCException;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class CSXWHDialog extends Application {
|
||||
|
||||
private AbstractAIFApplication app;
|
||||
|
||||
public CSXWHDialog() throws TCException {
|
||||
|
||||
}
|
||||
|
||||
private JPanel Panel;
|
||||
private Object[] obj = new Object[] { "序号", "产品类型", "试验项目", "试验时间", "样品数量", "试验费用" };// 民用表
|
||||
private Object[] obj2 = new Object[] { "序号", "类别", "项目", "项目费用" };// 工业表
|
||||
|
||||
public void initUI() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage arg0) throws Exception {
|
||||
Stage primaryStage = new Stage();
|
||||
Pane root = new Pane();
|
||||
Scene scene = new Scene(root, 382, 178);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("测试项维护");
|
||||
primaryStage.show();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.connor.jd.plm.utils;
|
||||
|
||||
import com.teamcenter.rac.kernel.TCPreferenceService;
|
||||
import com.teamcenter.rac.kernel.TCSession;
|
||||
import com.teamcenter.rac.kernel.TCUserService;
|
||||
|
||||
public class JDMethodUtil {
|
||||
|
||||
public static TCPreferenceService service;
|
||||
public static TCUserService userservice;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param prefName
|
||||
* @return
|
||||
*/
|
||||
public static String getPrefStr(String prefName, TCSession session) {
|
||||
if (service == null) {
|
||||
service = session.getPreferenceService();
|
||||
}
|
||||
String str = service.getString(TCPreferenceService.TC_preference_site, prefName);
|
||||
if (str == null) {
|
||||
str = new String("");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param prefName
|
||||
* @return
|
||||
*/
|
||||
public static String[] getPrefStrArray(String prefName, TCSession session) {
|
||||
if (service == null) {
|
||||
service = session.getPreferenceService();
|
||||
}
|
||||
String[] strs = service.getStringArray(TCPreferenceService.TC_preference_site, prefName);
|
||||
service.getStringValues(prefName);
|
||||
service.getStringValue(prefName);
|
||||
if (strs == null) {
|
||||
strs = new String[] { "" };
|
||||
}
|
||||
return strs;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue