public SldBsp GetSldPrdInfoFromFile(IEdmVault5 poVault, string filePath) { SldBsp bspPrt = null; IEdmFolder5 opParentFolder; //bspPrt = new SldBuy(); IEdmFile5 poFile = poVault.GetFileFromPath(filePath, out opParentFolder); if (poFile == null) { bspPrt = new SldPrt(); bspPrt.type = 1; return(bspPrt); } IEdmEnumeratorVariable5 enumVar = poFile.GetEnumeratorVariable(); if (enumVar == null) { return(null); } object tmpVar; string partType = ""; if (enumVar.GetVar("Part Type", "@", out tmpVar)) { partType = tmpVar.ToString(); } if (partType == "自制件") { bspPrt = new SldPrt(); bspPrt.type = 1; SldPrt prt = (SldPrt)bspPrt; if (enumVar.GetVar("工艺路线", "@", out tmpVar)) { prt.route = tmpVar.ToString(); } } else if (partType == "标准件") { bspPrt = new SldStd(); bspPrt.type = 2; } else { bspPrt = new SldBuy(); bspPrt.type = 3; } bspPrt.path = filePath; return(bspPrt); }
public bool SavePrtToWorkbook(Workbook workbook, SldAsm asmPrd) { if (asmPrd.sldPrtList.Count <= 0 && asmPrd.sldStdList.Count <= 0 && asmPrd.sldBuyList.Count <= 0) { return(true); } int count = asmPrd.sldPrtList.Count; int perPageSize = WiseUtil.prtPageSize;// int pageSize = count / perPageSize + (count % perPageSize > 0 ? 1 : 0); bool insHead = true; //空行 if (insHead) { SldPrt prt = new SldPrt(); asmPrd.sldPrtList.Insert(0, prt); count++; } if (insHead && asmPrd.sldStdList.Count > 0) { SldPrt prt = new SldPrt(); prt.name = WiseUtil.stdStr; int thisCount = asmPrd.sldStdList.Count; prt.amout = thisCount / WiseUtil.stdPageSize + (thisCount % WiseUtil.stdPageSize > 0 ? 1 : 0); asmPrd.sldPrtList.Insert(0, prt); count++; } if (insHead && asmPrd.sldBuyList.Count > 0) { SldPrt prt = new SldPrt(); prt.name = WiseUtil.buyStr; int thisCount = asmPrd.sldBuyList.Count; prt.amout = thisCount / WiseUtil.buyPageSize + (thisCount % WiseUtil.buyPageSize > 0 ? 1 : 0); asmPrd.sldPrtList.Insert(0, prt); count++; } //最初count if (insHead && asmPrd.sldPrtList.Count > 0) { SldPrt prt = new SldPrt(); prt.name = WiseUtil.prtStr; count++;//先加一个 pageSize = count / WiseUtil.prtPageSize + (count % prtPageSize > 0 ? 1 : 0); prt.amout = pageSize; asmPrd.sldPrtList.Insert(0, prt); } pageSize = count / perPageSize + (count % perPageSize > 0 ? 1 : 0); int rowStartIndex = 4; Sheets sheets = workbook.Worksheets; Worksheet worksheet = (Worksheet)sheets.get_Item(WiseUtil.prtStr); if (count <= 0) { worksheet.Delete(); return(false); } List <SldPrt> .Enumerator iEnum = asmPrd.sldPrtList.GetEnumerator(); Worksheet nextWorksheet = null; for (int pageIndex = 0; pageIndex < pageSize; pageIndex++) { if (pageIndex < pageSize - 1)//最后一个不能再复制了,写sheet前复制,保证模板未被写 { worksheet.Copy(Type.Missing, worksheet); nextWorksheet = worksheet.Next; } Range dyn = worksheet.Cells.get_Item("31", "A");// worksheet.Cells.get_Item("25", "A").set_Value(asmPrd.ztdm); worksheet.Range["A25"].Value = asmPrd.ztdm; worksheet.Range["A31"].Value = asmPrd.zjdm; worksheet.Range["E30"].Value = asmPrd.bzr; worksheet.Range["H30"].Value = asmPrd.bzsj; worksheet.Range["E31"].Value = asmPrd.pzr; worksheet.Range["H31"].Value = asmPrd.pzsj; if (asmPrd.jdbj == "S") { worksheet.Range["K29"].Value = asmPrd.jdbj; } else if (asmPrd.jdbj == "A") { worksheet.Range["M29"].Value = asmPrd.jdbj; } else if (asmPrd.jdbj == "B") { worksheet.Range["O29"].Value = asmPrd.jdbj; } else { worksheet.Range["R29"].Value = asmPrd.jdbj; } worksheet.Range["K31"].Value = "共 " + pageSize + " 页"; worksheet.Range["S31"].Value = "第 " + (pageIndex + 1) + " 页"; worksheet.Range["W31"].Value = asmPrd.sbxh; int row = 0; while (iEnum.MoveNext()) { SldPrt prt = iEnum.Current; int totalIndex = row + rowStartIndex; worksheet.Range["B" + totalIndex].Value = prt.materialNumber; worksheet.Range["E" + totalIndex].Value = prt.number; worksheet.Range["J" + totalIndex].Value = prt.name; worksheet.Range["O" + totalIndex].Value = prt.amout == 0 ? "" : prt.amout.ToString(); worksheet.Range["Q" + totalIndex].Value = prt.material; worksheet.Range["S" + totalIndex].Value = prt.weight == 0 ? "" : prt.weight.ToString(); worksheet.Range["T" + totalIndex].Value = prt.totalWeight == 0 ? "" : prt.totalWeight.ToString(); worksheet.Range["U" + totalIndex].Value = prt.rawWeight == 0 ? "" : prt.rawWeight.ToString(); worksheet.Range["V" + totalIndex].Value = prt.route; worksheet.Range["AC" + totalIndex].Value = prt.remark; row++; if (row >= WiseUtil.prtPageSize) { break; } } worksheet = nextWorksheet; } return(true); }