Example #1
0
        public static void CreateBomExecl(AssembleModel assemble)
        {
            Session       theSession    = Session.GetSession();
            Part          workPart      = theSession.Parts.Work;
            MoldInfoModel mold          = assemble.Asm.MoldInfo;
            string        workpieceName = mold.MoldNumber + "-" + mold.WorkpieceNumber + mold.EditionNumber;
            string        bomPath       = assemble.Asm.WorkpieceDirectoryPath + workpieceName + "-Bom.xlsx";

            if (File.Exists(bomPath))
            {
                File.Delete(bomPath);
            }
            string dllPath           = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string excelTemplatePath = dllPath.Replace("application\\", "Cofigure\\ElectrodeBom_Template.xlsx");
            //string excelTemplatePath = @"C:\Users\ycchen10\OneDrive - kochind.com\Desktop\MolexPlugIn\Cofigure\ElectrodeBom_Template.xlsx";
            IWorkbook workbook = ExcelUtils.CreateExeclFile(excelTemplatePath);

            if (workbook == null)
            {
                return;
            }
            IFont font = workbook.CreateFont();

            font.FontName           = "微软雅黑";
            font.FontHeightInPoints = 10;
            ICellStyle style = ExcelUtils.SetCellStyle(workbook, font);
            ISheet     sheet = workbook.GetSheetAt(0);

            ExcelUtils.SetValue(sheet, style, 1, 1, mold.MoldNumber);
            ExcelUtils.SetValue(sheet, style, 2, 1, mold.WorkpieceNumber);
            ExcelUtils.SetValue(sheet, style, 3, 1, mold.EditionNumber);
            ExcelUtils.SetValue(sheet, style, 4, 1, mold.MoldType);
            ExcelUtils.SetValue(sheet, style, 5, 1, mold.CreatedDate);
            ExcelUtils.SetValue(sheet, style, 6, 1, mold.CreatorName);
            string workName = "";
            int    row      = 9;

            foreach (WorkModel wk in assemble.Works)
            {
                ExcelUtils.SetValue(sheet, style, row, 0, "WORK" + wk.WorkNumber);
                row++;
                List <ElectrodeModel> eles = assemble.Electrodes.Where(a => a.WorkNumber == wk.WorkNumber).ToList();
                eles.Sort();
                foreach (ElectrodeModel model in eles)
                {
                    SetRowData(sheet, style, row, model.EleInfo);
                    row++;
                }
            }

            FileStream fs = File.Create(bomPath);

            workbook.Write(fs);
            fs.Close();
            workbook.Close();
            NXOpen.UI.GetUI().NXMessageBox.Show("信息", NXMessageBox.DialogType.Information, "导出成功");
        }
Example #2
0
        public void CreateExcel()
        {
            string dllPath           = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string excelTemplatePath = dllPath.Replace("application\\", "Cofigure\\ShopDoc_Template-test.xlsx");
            string path = part.FullPath;

            path = System.IO.Path.GetDirectoryName(path) + "\\" + part.Name + ".xlsx";

            IWorkbook workbook = ExcelUtils.CreateExeclFile(excelTemplatePath);

            if (workbook == null)
            {
                return;
            }
            IFont font = workbook.CreateFont();

            font.FontName           = "微软雅黑";
            font.FontHeightInPoints = 8;
            ICellStyle style     = ExcelUtils.SetCellStyle(workbook, font);
            ICellStyle styleDate = ExcelUtils.SetCellStyle(workbook, font);

            styleDate.DataFormat = 21;
            ISheet sheet = workbook.GetSheetAt(0);

            if (PostPartInfo.IsPartInfo(part))
            {
                SetMoldInfoToExcel(new MoldInfoModel(part), sheet, style);
            }
            if (PostPartInfo.IsPartElectrode(part))
            {
                SetEleMoldInfoToExcel(new PostElectrodenfo(part), sheet, style);
            }
            string name = AttributeUtils.GetAttrForString(part, "CAMUser");

            if (name.Equals(""))
            {
                name = Environment.UserName;
            }

            SetUser(name, sheet, style);
            SetRowData(sheet, style, styleDate);
            FileStream fs = File.Create(path);

            workbook.Write(fs);
            fs.Close();
            workbook.Close();
        }
Example #3
0
        public void CreateExcel()
        {
            string dllPath           = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string excelTemplatePath = dllPath.Replace("application\\", "Cofigure\\ShopDoc_Template-test.xlsx");
            string path = part.FullPath;

            path = System.IO.Path.GetDirectoryName(path) + "\\" + part.Name + ".xlsx";

            IWorkbook workbook = ExcelUtils.CreateExeclFile(excelTemplatePath);

            if (workbook == null)
            {
                return;
            }
            IFont font = workbook.CreateFont();

            font.FontName           = "微软雅黑";
            font.FontHeightInPoints = 8;
            ICellStyle style     = ExcelUtils.SetCellStyle(workbook, font);
            ICellStyle styleDate = ExcelUtils.SetCellStyle(workbook, font);

            styleDate.DataFormat = 21;
            ISheet   sheet = workbook.GetSheetAt(0);
            MoldInfo mold  = this.info.GetMoldInfo();

            if (this.info.IsWorkpiece())
            {
                SetMoldInfoToExcel(mold, sheet, style);
            }
            else
            {
                SetEleMoldInfoToExcel(mold, sheet, style);
            }
            SetUser(sheet, style);
            SetRowData(sheet, style, styleDate);
            FileStream fs = File.Create(path);

            workbook.Write(fs);
            fs.Close();
            workbook.Close();
        }