You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
com.connor.jk.plm/exportHardwareBOM_Operation...

821 lines
26 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.connor.jk.plm.exportBOM;
import java.awt.Color;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.form.ItemRevisionMasterForm;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentForm;
import com.teamcenter.rac.kernel.TCComponentICO;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentTcFile;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.ics.ICSProperty;
import com.teamcenter.rac.util.MessageBox;
public class exportHardwareBOM_Operation extends AbstractAIFOperation {
private String text;
private String path;
private ProgressBarThread wait;
private TCSession session;
private TCComponentBOMLine comp;
private FileInputStream fis;
private XSSFWorkbook workbook;
private FileOutputStream out;
private TCPreferenceService preferenceService;
private List<exportHardwareBOM_Bean> list = new ArrayList<>();
private exportHardwareBOM_Bean bean;
private TCComponentBOMLine child;
private String jbName = "";// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private String SBH = "";// ʶ<><CAB6><EFBFBD><EFBFBD>
public exportHardwareBOM_Operation(String text, String path, ProgressBarThread wait, TCSession session,
TCComponentBOMLine comp) {
this.text = text;
this.path = path;
this.wait = wait;
this.session = session;
this.comp = comp;
}
Integer[] keys = null;
String[] vals = null;
private String realNumber = "";
@Override
public void executeOperation() throws Exception {
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ץȡfnd0ActuatedInteractiveTsks fnd0Performer fnd0EndDate fnd0AliasTaskName
String name1="";//<2F><><EFBFBD><EFBFBD>
String name2="";//<2F><><EFBFBD><EFBFBD>
String name3="";//<2F><>׼
TCComponent[] component=comp.getItemRevision().getTCProperty("fnd0ActuatedInteractiveTsks").getReferenceValueArray();
// System.out.println(component.length);
for (int i = 0; i < component.length; i++) {
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(component[i].getTCProperty("fnd0AliasTaskName").getStringValue().contains("<22><><EFBFBD><EFBFBD>")) {
name1=component[i].getTCProperty("fnd0Performer").getDisplayValue().split("\\(")[0];
name1=name1+"/"+component[i].getTCProperty("fnd0EndDate").getDisplayValue();
}else if(component[i].getTCProperty("fnd0AliasTaskName").getStringValue().contains("<22><><EFBFBD><EFBFBD>")) {
name2=component[i].getTCProperty("fnd0Performer").getDisplayValue().split("\\(")[0];
name2=name2+"/"+component[i].getTCProperty("fnd0EndDate").getDisplayValue();
}else if(component[i].getTCProperty("fnd0AliasTaskName").getStringValue().contains("<22><>׼")) {
name3=component[i].getTCProperty("fnd0Performer").getDisplayValue().split("\\(")[0];
name3=name3+"/"+component[i].getTCProperty("fnd0EndDate").getDisplayValue();
}
}
// if(true) {
// return;
// }
long start = System.currentTimeMillis();
int colsCount = 15;//2017.10.18<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TCComponentItemRevision itemRevision = comp.getItemRevision();
TCComponentICO[] icoS = itemRevision.getClassificationObjects();
int count = 0;
int count1 = 0;
for (int i = 0; i < icoS.length; i++) {
ICSProperty[] cPropS = icoS[i].getICSProperties(true);
for (int j = 0; j < cPropS.length; j++) {
// System.out.println(count);
count++;
}
keys = new Integer[count];
vals = new String[count];
for (int j = 0; j < cPropS.length; j++) {
// System.out.println(count);
keys[count1] = cPropS[j].getId();
// System.out.println("keys[" + count1 + "]================>" + keys[count1]);
vals[count1] = cPropS[j].getValue();
// System.out.println("vals[" + count1 + "]================>" + vals[count1]);
if (keys[count1] == -500293) {
jbName = vals[count1];
} else if (keys[count1] == -500301) {
SBH = vals[count1];
}
count1++;
}
}
String sxx = "jk_bom2_uid";// G8TlM0X6YvbLjA G8TlM0X6YvbLjA TJXl8kmSYvbLjA
File file = getExcel(sxx);
if (file == null) {
return;
}
getBomline(comp,realNumber);
System.out.println("<22><><EFBFBD><EFBFBD>BOM" + list.size() + "<22><>");
int rowCount = list.size();
fis = new FileInputStream(file);
workbook = new XSSFWorkbook(fis);
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
XSSFFont font2 = workbook.createFont();
font2.setFontName("<22><><EFBFBD><EFBFBD>");
font2.setFontHeightInPoints((short) 11);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>λ<EFBFBD>ŵȵ<C5B5><C8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
XSSFFont font4 = workbook.createFont();
font4.setFontName("<22><><EFBFBD><EFBFBD>");
font4.setFontHeightInPoints((short) 10);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
//B<><42><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>
XSSFFont font = workbook.createFont();
font.setFontName(<><CEA2><EFBFBD>ź<EFBFBD>");
font.setFontHeightInPoints((short) 9);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
//
// XSSFFont font3 = workbook.createFont();
// font3.setFontName("΢<><CEA2><EFBFBD>ź<EFBFBD>");
// font3.setFontHeightInPoints((short) 10);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
XSSFSheet sheet = workbook.getSheet(<><D3B2><EFBFBD>嵥");
XSSFRow row = sheet.getRow(1);
XSSFCell cell_0 = row.getCell(3);
cell_0.setCellValue(comp.getItemRevision().getTCProperty("item_id").getStringValue());
cell_0 = row.getCell(11);
cell_0.setCellValue(comp.getItemRevision().getTCProperty("item_revision_id").getStringValue());
row = sheet.getRow(2);
cell_0 = row.getCell(3);
cell_0.setCellValue(jbName);
cell_0 = row.getCell(11);
cell_0.setCellValue(SBH);
row = sheet.getRow(4);
cell_0 = row.getCell(3);
Date date=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String time= sdf.format(date);
time=time.replace("-", ".");
cell_0.setCellValue(time);//<2F><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
int startRow = 6;
XSSFCellStyle sty = workbook.createCellStyle();// <20>½<EFBFBD><C2BD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ĸ<EFBFBD>ʽ
XSSFCellStyle style = workbook.createCellStyle();// C<><43><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><CFB1>뵥Ԫ<EBB5A5><D4AA><EFBFBD>ĸ<EFBFBD>ʽ
// XSSFCellStyle sty2 = sheet.getRow(7).getCell(1).getCellStyle();
XSSFCellStyle sty2 = workbook.createCellStyle();//B<>е<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
sty2.setBorderBottom((short) 1);
sty2.setBorderLeft((short) 2);
sty2.setBorderRight((short) 1);
sty2.setBorderTop((short) 1);
sty2.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
sty2.setFont(font);
// XSSFCellStyle sty3 = sheet.getRow(6).getCell(13).getCellStyle();// N<>е<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ĸ<EFBFBD>ʽ
XSSFCellStyle sty3 = workbook.createCellStyle();// O<>б<EFBFBD>ע<EFBFBD><D7A2>Ԫ<EFBFBD><D4AA><EFBFBD>ĸ<EFBFBD>ʽ
XSSFCellStyle sty4 = workbook.createCellStyle();// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>еĸ<D0B5>ʽ
XSSFCellStyle sty5 = workbook.createCellStyle();// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ע<EFBFBD>ĸ<EFBFBD>ʽ
sty5.setBorderTop((short) 2);
sty5.setBorderRight((short) 2);
XSSFCellStyle sty6 = workbook.createCellStyle();// <20><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ĸ<EFBFBD>ʽ
XSSFCellStyle sty7 = workbook.createCellStyle();// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD>ڵ<EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ĸ<EFBFBD>ʽ
// XSSFCellStyle sty8 = workbook.createCellStyle();// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC>ĸ<EFBFBD>ʽ
// sty8.setBorderBottom((short) 2);
// sty8.setBorderLeft((short) 0);
// sty8.setBorderRight((short) 0);
sty6.setBorderBottom((short) 2);
sty6.setBorderLeft((short) 2);
sty6.setBorderRight((short) 1);
sty7.setBorderLeft((short) 1);
sty7.setBorderBottom((short) 2);
sty7.setBorderRight((short) 2);
// sty = sheet.getRow(7).getCell(11).getCellStyle();
// sty.setBorderBottom(CellStyle.BORDER_THIN);
sty.setBorderBottom((short) 1);
sty.setBorderLeft((short) 1);
sty.setBorderRight((short) 1);
sty.setBorderTop((short) 1);
// sty.setBottomBorderColor(IndexedColors.BLACK.getIndex());
sty.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);// <20><>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>
sty.setAlignment(XSSFCellStyle.ALIGN_LEFT);// ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD>
style.setBorderBottom(CellStyle.BORDER_THIN);
// style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setAlignment(XSSFCellStyle.ALIGN_CENTER); // <20><><EFBFBD><EFBFBD>
style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); // <20><><EFBFBD><EFBFBD>
style.setFont(font);
// sty2.setFont(font);
sty3.setBorderBottom((short) 1);
sty3.setBorderLeft((short) 1);
sty3.setBorderRight((short) 2);
// sty3.setBottomBorderColor(IndexedColors.BLACK.getIndex());
sty3.setBorderTop((short) 1);
// sty3.setTopBorderColor(IndexedColors.BLACK.getIndex());
sty4.setBorderBottom((short)2);
sty4.setBorderLeft((short)1);
sty4.setBorderRight((short)1);
// sty4.setBottomBorderColor(IndexedColors.BLACK.getIndex());
// sty4.setBorderTop(CellStyle.BORDER_THIN);
// sty4.setTopBorderColor(IndexedColors.BLACK.getIndex());
// sty4.setBorderLeft(CellStyle.BORDER_THIN);
// sty4.setLeftBorderColor(IndexedColors.BLACK.getIndex());
// sty4.setBorderRight(CellStyle.BORDER_THIN);
// sty4.setRightBorderColor(IndexedColors.BLACK.getIndex());
sty4.setFont(font2);
sty4.setAlignment(XSSFCellStyle.ALIGN_CENTER);
for (int i = 0; i < rowCount + 7; i++) {
XSSFRow r = null;
boolean isCreate = false;
// System.out.println("sheet.getLastRowNum()-------->" + sheet.getLastRowNum());
if ((i + startRow) > sheet.getLastRowNum()) {
r = sheet.createRow(i + startRow);
isCreate = true;
} else {
r = sheet.getRow(i + startRow);
isCreate = false;
}
if (i < rowCount + 3 && isCreate) {
CellRangeAddress cra = new CellRangeAddress(i + startRow, i + startRow, 8, 9);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(i + startRow, i + startRow, 6, 7);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(i + startRow, i + startRow, 4, 5);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(i + startRow, i + startRow, 2, 3);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(i + startRow, i + startRow, 11, 12);
sheet.addMergedRegion(cra);
}
for (int cols = 1; cols < colsCount; cols++) {
XSSFCell cell = null;
if (isCreate) {
cell = r.createCell(cols);
cell.setCellStyle(sty);
if (cols == 1) {
cell.setCellStyle(sty2);
} else if (cols == 14) {
cell.setCellStyle(sty3);
}
// TODO <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
} else {
// if (r == null) {
// r = sheet.createRow(i + startRow);
// System.out.println("<22><>û<EFBFBD>д<EFBFBD><D0B4><EFBFBD>");
// }
cell = r.getCell(cols);
}
if (cell == null) {
// cell = r.createCell(cols);
// cell.setCellStyle(sty);
}
cell.setCellType(XSSFCell.CELL_TYPE_STRING);// <20>ı<EFBFBD><C4B1><EFBFBD>ʽ
// XSSFCellStyle sty0=sheet.getRow(9).getCell(11).getCellStyle();
//<2F><><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD>
if (i < rowCount) {
int rwsTemp = list.get(i).getSpecCode().length()/10+1;
int rwsTemp1 = list.get(i).getRef_designator().length()/10+1;
int rwsTemp2 = list.get(i).getPackaging().length()/10+1;
int rwsTemp3 = list.get(i).getBl_substitute_list().length()/10+1;
int temp;
int a[]=new int[]{rwsTemp,rwsTemp1,rwsTemp2,rwsTemp3};
Arrays.sort(a);
for(int i1=0;i1<a.length;i1++) {
// System.out.println(a[i1]);
}
temp=a[2];
r.setHeight((short)(temp * 260));
cell.getCellStyle().setWrapText(true);
}
if (i < rowCount) {
switch (cols) {
case 1:// <20><><EFBFBD><EFBFBD>
if (list.get(i) == null) {
this.wait.setBool(true);
this.wait.interrupt();
MessageBox.post("BOM<4F>嵥Ϊ<E5B5A5><CEAA>", "<22><><EFBFBD><EFBFBD>", MessageBox.INFORMATION);
return;
} else {
if (i > 0) {
cell.setCellStyle(sty2);
}
cell.setCellValue(list.get(i).getNumber());
break;
}
case 2:// <20><><EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD>
// if(i>2) {
// sty0=sheet.getRow(9).getCell(cols).getCellStyle();
// cell.setCellStyle(sty0);
// }
if (i >= 2) {
cell.setCellStyle(style);
}
cell.setCellValue(list.get(i).getMaterialCode());// д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
break;
case 4:// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cell.getCellStyle().setFont(font4);
cell.getCellStyle().setAlignment(CellStyle.ALIGN_LEFT);
cell.setCellValue(list.get(i).getMaterialName());
break;
case 6:// <20><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD>
cell.getCellStyle().setFont(font4);
cell.setCellValue(list.get(i).getRef_designator());
System.out.println(<><CEBB>-------------<2D><>"+list.get(i).getRef_designator());
break;
case 8:// <20><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD>
cell.getCellStyle().setFont(font4);
cell.setCellValue(list.get(i).getSpecCode());
// cell.setCellStyle(styG);
break;
case 10:// <20><><EFBFBD><EFBFBD>
cell.getCellStyle().setFont(font4);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue(list.get(i).getQuantity());
System.out.println("--------------->"+list.get(i).getQuantity());
break;
case 11:// <20><>װ
cell.getCellStyle().setFont(font4);
cell.getCellStyle().setAlignment(CellStyle.ALIGN_LEFT);
cell.setCellValue(list.get(i).getPackaging());
break;
case 13:// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cell.setCellValue(list.get(i).getBl_substitute_list());
break;
case 14:// <20><>ע
cell.setCellStyle(sty3);
break;
}
}
}
}
XSSFCell cell14=sheet.getRow(6).getCell(14);
cell14.setCellStyle(sty5);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>еĵ<D0B5><C4B5>±߿<C2B1>
XSSFCell cellLast = null;
for (int cols = 1; cols < colsCount; cols++) {
cellLast = sheet.getRow(startRow + rowCount + 6).getCell(cols);
switch (cols) {
case 1:// <20><><EFBFBD><EFBFBD>
cellLast.setCellValue("<22><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>");
cellLast.setCellStyle(sty2);
break;
case 2:// <20><><EFBFBD><EFBFBD>
cellLast.setCellStyle(sty4);
break;
case 3:// <20><><EFBFBD><EFBFBD>
cellLast.setCellValue("<22><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>");
cellLast.setCellStyle(sty4);
break;
case 4:// <20><><EFBFBD><EFBFBD>
cellLast.setCellStyle(sty4);
break;
case 5:// <20><><EFBFBD><EFBFBD>
cellLast.setCellValue("<22><>׼/<2F><><EFBFBD><EFBFBD>");
cellLast.setCellStyle(sty4);
break;
case 6:// <20><><EFBFBD><EFBFBD>
cellLast.setCellStyle(sty4);
break;
case 7:// <20><><EFBFBD><EFBFBD>
cellLast.setCellValue("<22><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>");
cellLast.setCellStyle(sty4);
break;
case 8:// <20><><EFBFBD><EFBFBD>
cellLast.setCellStyle(sty4);
break;
case 9:// <20><><EFBFBD><EFBFBD>
cellLast.setCellValue("<22><><EFBFBD><EFBFBD>");
cellLast.setCellStyle(sty4);
break;
case 10:// <20><><EFBFBD><EFBFBD>
cellLast.setCellValue("<22><><EFBFBD><EFBFBD>");
cellLast.setCellStyle(sty4);
break;
case 11:// <20><><EFBFBD><EFBFBD>
cellLast.setCellValue("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>");
cellLast.setCellStyle(sty4);
break;
case 12:// <20><><EFBFBD><EFBFBD>
cellLast.setCellStyle(sty4);
break;
case 13:// <20><><EFBFBD><EFBFBD>
cellLast.setCellStyle(sty4);
break;
case 14:// <20><>ע
cellLast.setCellStyle(sty3);
break;
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD>߿<EFBFBD>
for (int i = startRow + rowCount+6; i < startRow + rowCount + 7; i++) {
XSSFCell cell = null;
for (int cols = 1; cols < colsCount; cols++) {
cell = sheet.getRow(i).getCell(cols);
switch (cols) {
case 1:// <20><><EFBFBD><EFBFBD>
cell.setCellStyle(sty6);
break;
case 14:// <20><>ע
if (i > 0) {
cell.setCellStyle(sty7);
}
break;
}
}
}
// <20>ϲ<EFBFBD>ǩ<EFBFBD><C7A9><EFBFBD>ĵ<EFBFBD>Ԫ<EFBFBD><D4AA>
CellRangeAddress cra = new CellRangeAddress(rowCount + startRow + 3, rowCount + startRow + 5, 1, 2);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 3, rowCount + startRow + 5, 3, 4);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 3, rowCount + startRow + 5, 5, 6);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 3, rowCount + startRow + 5, 7, 8);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 3, rowCount + startRow + 5, 9, 9);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 3, rowCount + startRow + 5, 10, 10);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 3, rowCount + startRow + 5, 11, 14);
sheet.addMergedRegion(cra);
// <20>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
cra = new CellRangeAddress(rowCount + startRow + 6, rowCount + startRow + 6, 1, 2);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 6, rowCount + startRow + 6, 3, 4);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 6, rowCount + startRow + 6, 5, 6);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 6, rowCount + startRow + 6, 7, 8);
sheet.addMergedRegion(cra);
cra = new CellRangeAddress(rowCount + startRow + 6, rowCount + startRow + 6, 11, 14);
sheet.addMergedRegion(cra);
// <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĵ<D0B5><C4B5>±߿<C2B1>
XSSFCell cell5 = null;
for (int cols = 1; cols < colsCount; cols++) {
cell5 = sheet.getRow(startRow + rowCount + 2).getCell(cols);
switch (cols) {
case 1:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 2:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 3:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 4:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 5:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 6:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 7:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 8:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 9:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 10:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 11:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 12:// <20><><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 13:// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cell5.setCellStyle(sty4);
break;
case 14:// <20><>ע
cell5.setCellStyle(sty4);
break;
}
}
XSSFCell cell0=sheet.getRow(startRow + rowCount + 2).getCell(1);
cell0.setCellStyle(sty6);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD>е<EFBFBD>Ԫ<EFBFBD><D4AA>A
cell0=sheet.getRow(startRow + rowCount + 2).getCell(14);
cell0.setCellStyle(sty7);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD>е<EFBFBD>Ԫ<EFBFBD><D4AA>O
XSSFCell cell1=sheet.getRow(startRow + rowCount + 4).getCell(1);
cell1.setCellStyle(sty6);
cell1=sheet.getRow(startRow + rowCount + 4).getCell(14);
cell1.setCellStyle(sty7);
// XSSFRow row1=sheet.getRow(startRow + rowCount + 3);
// row1.getCell(1).getCellStyle().getFont().setFontHeightInPoints((short) 10);
// row1.getCell(1).getCellStyle().getFont().setFontName("Tahoma");
XSSFCell cell2=sheet.getRow(startRow + rowCount + 3).getCell(1);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><34>A<EFBFBD><41>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ʽ
cell2.getCellStyle().getFont().setFontHeightInPoints((short) 10);
cell2.getCellStyle().getFont().setFontName("<22><><EFBFBD><EFBFBD>");
cell2.setCellValue(name1);
cell2=sheet.getRow(startRow + rowCount + 3).getCell(3);
cell2.setCellValue(name2);
cell2=sheet.getRow(startRow + rowCount + 3).getCell(5);
cell2.setCellValue(name3);
cell2 = sheet.getRow(startRow + rowCount + 3).getCell(1);
cell2.getCellStyle().setAlignment((short) 1);
cell2.getCellStyle().setVerticalAlignment((short) 1);
cell2.getCellStyle().setWrapText(true);//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
// cell2.getCellStyle().setFont(font3);
sheet.getRow(startRow + rowCount + 6).setHeight((short)402);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>еĸ߶<C4B8>
cellLast = sheet.getRow(startRow + rowCount + 6).getCell(1);
cellLast.getCellStyle().setAlignment(CellStyle.ALIGN_LEFT);
cellLast.getCellStyle().setVerticalAlignment(CellStyle.VERTICAL_CENTER);
cellLast = sheet.getRow(startRow + rowCount + 6).getCell(3);
cellLast.getCellStyle().setAlignment(CellStyle.ALIGN_LEFT);
cellLast.getCellStyle().setVerticalAlignment(CellStyle.VERTICAL_CENTER);
cellLast = sheet.getRow( 6).getCell(2);
cellLast.getCellStyle().setAlignment(CellStyle.ALIGN_CENTER);
cellLast = sheet.getRow( 7).getCell(2);
cellLast.getCellStyle().setAlignment(CellStyle.ALIGN_CENTER);
File fileout = new File(path + "\\" + text + ".xlsx");
try {
out = new FileOutputStream(fileout);
} catch (Exception e) {
this.wait.setBool(true);
this.wait.interrupt();
MessageBox.post("<22><><EFBFBD>ȹر<C8B9>ͬ<EFBFBD><CDAC><EFBFBD>ļ<EFBFBD>","",MessageBox.INFORMATION);
return;
}
workbook.write(out);
long end = System.currentTimeMillis();
float time2 = (end - start) / 1000.00f;
System.out.println("<22><>ʱ<EFBFBD><CAB1>" + time2 + "<22><>");
// System.out.println("<22>汾----------------------->"+comp.getItemRevision().getTCProperty("item_revision_id").getStringValue());
this.wait.setBool(true);
this.wait.interrupt();
MessageBox.post("<22><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>", "<22>ɹ<EFBFBD>", MessageBox.INFORMATION);
Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", path + "\\" + text + ".xlsx" });//
System.out.println("2017.10.26");
}
private File getExcel(String ssx) {
File file = null;
preferenceService = session.getPreferenceService();
String puid = preferenceService.getStringValue(ssx);
if (puid == null) {
MessageBox.post("<22><><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>", "<22><><EFBFBD><EFBFBD>", MessageBox.ERROR);
return null;
}
TCComponentDataset dataset = null;
try {
dataset = (TCComponentDataset) session.stringToComponent(puid);
} catch (TCException e) {
e.printStackTrace();
}
if (dataset == null) {
MessageBox.post("<22><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>", "<22><><EFBFBD><EFBFBD>", MessageBox.ERROR);
return null;
}
try {
TCComponentTcFile[] files = dataset.getTcFiles();
if (files.length == 0) {
MessageBox.post("<22><><EFBFBD>ݼ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ļ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD>", MessageBox.ERROR);
return null;
} else if (files.length > 1) {
MessageBox.post("<22><><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD>", MessageBox.ERROR);
return null;
} else {
file = files[0].getFmsFile();
}
} catch (TCException e) {
e.printStackTrace();
}
return file;
}
private void getBomline(TCComponentBOMLine bomline, String realNumber_0) {
AIFComponentContext[] childline = null;
String materialCode = "";// <20><><EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD>
String materialName = "";// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
String specCode = "";// <20><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD>
String quantity = "";// <20><><EFBFBD><EFBFBD>
String unit = "";// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
String ref_designator = "";// λ<><CEBB>
String packaging = "";// <20><>װ
String bl_substitute_list="";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int number_0 = 0;
try {
childline = bomline.getChildren();
for (int i = 0; i < childline.length; i++) {
number_0++;
bean = new exportHardwareBOM_Bean();
if (!bomline.getTCProperty("bl_formatted_parent_name").getStringValue().equals("")) {
if (i > 0) {
realNumber_0 = realNumber_0.substring(0, realNumber_0.lastIndexOf(".") + 1) + number_0;
} else {
realNumber_0 = realNumber_0 + "." + number_0;
}
} else {
realNumber_0 = number_0 + "";
}
bean.setNumber(realNumber_0);
child = (TCComponentBOMLine) childline[i].getComponent();
//2017.10.17<EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ըij<EFBFBD>"<22><><EFBFBD><EFBFBD>/<2F>汾"
materialCode = child.getItemRevision().getTCProperty("item_id").getStringValue()+"/"+ child.getItemRevision().getTCProperty("current_revision_id").getStringValue();
bean.setMaterialCode(materialCode);
materialName = child.getItemRevision().getTCProperty("object_name").getStringValue();
bean.setMaterialName(materialName);
packaging = "";
TCComponentICO[] icoS = child.getItemRevision().getClassificationObjects();
int count = 0;
int count1 = 0;
for (int j = 0; j < icoS.length; j++) {
ICSProperty[] cPropS = icoS[j].getICSProperties(true);
for (int k = 0; k < cPropS.length; k++) {
// System.out.println(count);
count++;
}
keys = new Integer[count];
vals = new String[count];
for (int k = 0; k < cPropS.length; k++) {
// System.out.println(count);
keys[count1] = cPropS[k].getId();
// System.out.println("keys[" + count1 + "]================>" + keys[count1]);
vals[count1] = cPropS[k].getValue();
// System.out.println("vals[" + count1 + "]================>" + vals[count1]);
if (keys[count1] == -500242) {
packaging = vals[count1];
}
count1++;
}
}
bean.setPackaging(packaging);
TCComponentForm form = (TCComponentForm) child.getItemRevision()
.getReferenceListProperty("IMAN_master_form_rev")[0];
// techCode = form.getTCProperty("jk8TechModel").getStringValue();
// bean.setTechCode(techCode);
specCode = form.getTCProperty("jk8SpecModel").getStringValue();
bean.setSpecCode(specCode);
ref_designator = child.getTCProperty("bl_ref_designator").getStringValue();
//
System.out.println("<22><><EFBFBD><EFBFBD>ָʾ<D6B8><CABE>------------------->" + ref_designator);
bean.setRef_designator(ref_designator);
//2017.10.26 <20><>C1-C3<43>ij<EFBFBD>C1,C2,C3<43>ĸ<EFBFBD>ʽ
String[] xx=ref_designator.split(",");
List<String> ref_designator_list=new ArrayList<>();
for (int k = 0; k < xx.length; k++) {
if(ref_designator_list.contains("-")) {
String strings1=xx[k].split("-")[0];//Сֵ
String strings2=xx[k].split("-")[1];//<2F><>ֵ
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
String up="";
int up_num=0;
for (int j = strings2.length()-1;j>=0; j--) {
if(Character.isDigit(strings2.charAt(j))==true) {
up=strings2.charAt(j)+up;
}else {
break;
}
}
up_num=Integer.valueOf(up);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сֵ
String down="";
int down_num=0;
int mark=0;
for(int j = strings1.length()-1;j>=0; j--) {
if(Character.isDigit(strings1.charAt(j))==true) {
down=strings1.charAt(j)+down;
}else {
mark=j;
break;
}
}
down_num=Integer.valueOf(down);
//<2F><>ͷ<EFBFBD><CDB7>λ<EFBFBD><CEBB>
String wh=strings1.substring(0, mark+1);
for (int j = down_num; j <= up_num; j++) {
String aa=wh+j;
ref_designator_list.add(aa);
}
}else if(!ref_designator_list.contains("-")) {
ref_designator_list.add(xx[k]);
}
}
quantity = child.getTCProperty("bl_quantity").getStringValue().split(".")[0];//2017.10.26 <20><><EFBFBD><EFBFBD>ʾС
// if(Integer.valueOf(quantity)>3) {
// quantity=quantity+"-";
// }
bean.setQuantity(quantity);
unit = child.getProperty("bl_uom");
bean.setUnit(unit);
//2017.10.18<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TCComponent[] components=child.getTCProperty("bl_substitute_list").getReferenceValueArray();
if(components.length==0) {
bl_substitute_list="";
}else if(components.length>0) {
for (int j = 0; j < components.length; j++) {
bl_substitute_list=bl_substitute_list+((TCComponentItem)components[j]).getTCProperty("item_id").getStringValue()+",";
}
}
if(bl_substitute_list.length()>=1) {
bl_substitute_list=bl_substitute_list.trim();
bl_substitute_list=bl_substitute_list.substring(0, bl_substitute_list.length()-1);
}
bean.setBl_substitute_list(bl_substitute_list);
list.add(bean);
if (child.getChildren().length > 0) {
getBomline(child,realNumber_0);
}
}
} catch (TCException e) {
e.printStackTrace();
}
}
}