public FormNewProductBat(ref SystemParam param, ProductBatInfo batInfo) { sysParam = param; prdBatInfo = new ProductBatInfo(); prdBatInfo = batInfo; InitializeComponent(); }
public int CreateExcelFile(ProductBatInfo prdBatInfo, ProductParameter prdParm) { awExcle = new AwExcel(); string dataPath = ""; if (prdParm.DataPath.Length == 0) { dataPath = systemParam.CurrentPath + "\\data"; } else { dataPath = prdParm.DataPath; } if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } //客户编号:QE123,流水号:124343,随工单号:GH323,文件名设置为:QE123-124343-GH323.XLS string fileName = ""; return(awExcle.CreateDataBase(dataPath + "\\" + fileName, prdParm, prdBatInfo)); }
public int CreateDataBase(string fileName, ProductParameter prdParm, ProductBatInfo prdBatInfo) { try { fName = fileName; // Check if the file is existing xls_exp = new Microsoft.Office.Interop.Excel.ApplicationClass(); if (System.IO.File.Exists(fileName)) { xls_book = xls_exp.Workbooks.Open(fileName, Missing.Value, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); if (xls_book != null) { // find the last index xls_sheet = (Microsoft.Office.Interop.Excel._Worksheet)xls_book.Worksheets.get_Item(1); int i = xls_sheet.UsedRange.Rows.Count; if (i >= 9) { startIndex = 9; } else { startIndex = i + 1; } index = i + 1; Close(); return(0); } } // Create a new file //xls_exp = new Microsoft.Office.Interop.Excel.ApplicationClass(); xls_book = xls_exp.Workbooks.Add(true); xls_sheet = (Microsoft.Office.Interop.Excel._Worksheet)xls_book.Worksheets.get_Item(1); object misValue = System.Reflection.Missing.Value; //xls_sheet.Cells[1, 1] = "客户编号"; //xls_sheet.Cells[1, 2] = prdBatInfo.customCode; //xls_sheet.Cells[2, 1] = "随工单号"; //xls_sheet.Cells[2, 2] = prdBatInfo.suigongCode; //xls_sheet.Cells[3, 1] = "操作员"; //xls_sheet.Cells[3, 2] = prdBatInfo.operatorCode; //xls_sheet.Cells[4, 1] = "入纤功率"; //xls_sheet.Cells[4, 2] = prdBatInfo.ruQianPower.ToString() + "dBm"; //xls_sheet.Cells[5, 1] = "机器号"; //xls_sheet.Cells[5, 2] = prdParm.MachineCode; //xls_sheet.Cells[6, 1] = "测试序号"; //xls_sheet.Cells[6, 2] = "VPP(MV)"; //xls_sheet.Cells[6, 3] = "耦合时间"; xls_sheet.Cells[6, 1] = "目标值(mV/uA)"; xls_sheet.Cells[6, 2] = prdParm.MinimumVpp.ToString(); xls_sheet.Cells[7, 1] = "生产信息"; xls_sheet.Cells[8, 1] = "Index"; xls_sheet.Cells[8, 2] = "产品编号"; xls_sheet.Cells[8, 3] = "Vpp(mV)/Iop(uA)"; xls_sheet.Cells[8, 4] = "Vbr(V)"; xls_sheet.Cells[8, 5] = "LX1(um)"; xls_sheet.Cells[8, 6] = "LY1(um)"; xls_sheet.Cells[8, 7] = "LZ(um)"; xls_sheet.Cells[8, 8] = "LX2(um)"; xls_sheet.Cells[8, 9] = "LY2(um)"; xls_sheet.Cells[8, 10] = "Coupling Time(S)"; xls_sheet.Cells[8, 11] = "Total Time(S)"; xls_sheet.Cells[8, 12] = "Date in producted"; xls_sheet.Cells[8, 13] = "Vpp/Iop_10V(mV/uA)"; xls_sheet.Cells[8, 14] = "Vpp/Iop_Check(mV/uA)"; xls_book.Saved = true; xls_book.SaveAs(fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); //xls_book.Save(); startIndex = 9; index = 9; Close(); } catch (Exception ee) { Close(); error = ee.Message; return(-1); } return(0); }