public static bool CreateToolListExcel_XinWu(string cusName, string partNo, string cusVer, string opVer, string op1, DB_TEMain sDB_TEMain, IList <Com_ToolList> cCom_ToolList) { //判斷Server的Template是否存在 if (!File.Exists(sDB_TEMain.excelTemplateFilePath)) { return(false); } ApplicationClass excelApp = new ApplicationClass(); Workbook workBook = null; Worksheet workSheet = null; Range workRange = null; try { //設定輸出路徑 OutputPath = string.Format(@"{0}\{1}_{2}_{3}\{4}_{5}_{6}_{7}" , Environment.GetFolderPath(Environment.SpecialFolder.Desktop) , partNo , cusVer , opVer , partNo , cusVer , opVer , sDB_TEMain.comTEMain.ncGroupName + "_" + "ToolList" + ".xls"); //1.開啟Excel //2.將Excel設為不顯示 //3.取得第一頁Sheet workBook = (Workbook)excelApp.Workbooks.Open(sDB_TEMain.excelTemplateFilePath); excelApp.Visible = false; workSheet = (Worksheet)workBook.Sheets[1]; //建立Sheet頁數符合所有的Operation //之後應該要改成同一頁然後一直新增ROW status = Excel_CommonFun.AddNewSheet(cCom_ToolList.Count, 40, excelApp, workSheet); if (!status) { MessageBox.Show("建立Sheet頁失敗,請聯繫開發工程師"); return(false); } //修改每一個Sheet名字和頁數 status = Excel_CommonFun.ModifySheet(partNo, "ToolList", workBook, workSheet, workRange, sDB_TEMain.factory); if (!status) { MessageBox.Show("修改Sheet名字和頁數失敗,請聯繫開發工程師"); return(false); } //開始填表 int CurrentRow = 6, ToolNumberColumn = 1, ToolERPColumn = 2, ToolCutterQtyColumn = 3, ToolCutterLifeColumn = 4, ToolFluteQtyColumn = 5, ToolTitleColumn = 6, ToolSpecColumn = 8, ToolNoteColumn = 10; RowColumn sRowColumn; int StartRow = 0, EndRow = 0; for (int i = 0; i < cCom_ToolList.Count; i++) { //GetExcelRowColumn(i, out sRowColumn); //取得當前Operation該放置的Sheet int currentSheet_Value = (i / 40); if (currentSheet_Value == 0) { workSheet = (Worksheet)workBook.Sheets[1]; } else { workSheet = (Worksheet)workBook.Sheets[currentSheet_Value + 1]; } CurrentRow = CurrentRow + 1; StartRow = CurrentRow; workRange = (Range)workSheet.Cells; workRange[CurrentRow, ToolNumberColumn] = cCom_ToolList[i].toolNumber; workRange[CurrentRow, ToolERPColumn] = cCom_ToolList[i].erpNumber; workRange[CurrentRow, ToolCutterQtyColumn] = cCom_ToolList[i].cutterQty; workRange[CurrentRow, ToolCutterLifeColumn] = cCom_ToolList[i].cutterLife; workRange[CurrentRow, ToolFluteQtyColumn] = cCom_ToolList[i].fluteQty; workRange[CurrentRow, ToolTitleColumn] = cCom_ToolList[i].title; workRange[CurrentRow, ToolSpecColumn] = cCom_ToolList[i].specification; workRange[CurrentRow, ToolNoteColumn] = cCom_ToolList[i].note; if (cCom_ToolList[i].accessory != "") { string[] SplitAccessory = cCom_ToolList[i].accessory.Split('?'); foreach (string j in SplitAccessory) { CurrentRow = CurrentRow + 1; string[] Spliti = j.Split('!'); workRange[CurrentRow, ToolERPColumn] = Spliti[0]; workRange[CurrentRow, ToolTitleColumn] = Spliti[1]; workRange[CurrentRow, ToolSpecColumn] = Spliti[2]; } } EndRow = CurrentRow; //合併儲存格 workSheet.get_Range("A" + StartRow, "A" + EndRow).Merge(false); } //加入 料號.品名.設計.審核.批准 workRange[52, 10] = partNo; workRange[51, 10] = "OIS-" + sDB_TEMain.ncGroupName.Split('P')[1].Split('_')[0]; workRange[52, 5] = sDB_TEMain.comTEMain.designed; workRange[52, 6] = sDB_TEMain.comTEMain.reviewed; workRange[52, 7] = sDB_TEMain.comTEMain.approved; if (File.Exists(OutputPath)) { File.Delete(OutputPath); } workBook.SaveAs(OutputPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); if (File.Exists(OutputPath)) { File.Delete(OutputPath); } workBook.SaveAs(OutputPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); File.Delete(OutputPath); return(false); } finally { Dispose(excelApp, workBook, workSheet, workRange); } return(true); }
public static bool CreateIPQCExcel_XiAn(string cusName, string partNo, string cusVer, string opVer, string op1, DB_MEMain sDB_MEMain, IList <Com_Dimension> cCom_Dimension) { //判斷Server的Template是否存在 if (!File.Exists(sDB_MEMain.excelTemplateFilePath)) { return(false); } ApplicationClass excelApp = new ApplicationClass(); Workbook workBook = null; Worksheet workSheet = null; Range workRange = null; try { //設定輸出路徑 OutputPath = string.Format(@"{0}\{1}_{2}_{3}\{4}_{5}_{6}_{7}" , Environment.GetFolderPath(Environment.SpecialFolder.Desktop) , partNo , cusVer , opVer , partNo , cusVer , opVer , op1 + "_" + sDB_MEMain.factory + ".xls"); //判斷Server的Template是否存在 if (!File.Exists(sDB_MEMain.excelTemplateFilePath)) { return(false); } //1.開啟Excel //2.將Excel設為不顯示 //3.取得第一頁Sheet workBook = excelApp.Workbooks.Open(sDB_MEMain.excelTemplateFilePath); excelApp.Visible = false; workSheet = (Worksheet)workBook.Sheets[1]; //建立Sheet頁數符合所有的Dimension status = Excel_CommonFun.AddNewSheet(cCom_Dimension.Count, 15, excelApp, workSheet); if (!status) { MessageBox.Show("建立Sheet頁失敗,請聯繫開發工程師"); workBook.SaveAs(sDB_MEMain.excelTemplateFilePath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing , XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); return(false); } //修改每一個Sheet名字和頁數 status = Excel_CommonFun.ModifySheet(partNo, "IPQC", workBook, workSheet, workRange, sDB_MEMain.factory); if (!status) { MessageBox.Show("修改Sheet名字和頁數失敗,請聯繫開發工程師"); //workBook.SaveAs(sDB_MEMain.excelTemplateFilePath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing // , XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); return(false); } RowColumn sRowColumn = new RowColumn(); int currentSheet_Value; for (int i = 0; i < cCom_Dimension.Count; i++) { GetExcelRowColumn(i, sDB_MEMain.factory, out sRowColumn); currentSheet_Value = (i / 15); if (currentSheet_Value == 0) { workSheet = (Worksheet)workBook.Sheets[1]; } else { workSheet = (Worksheet)workBook.Sheets[currentSheet_Value + 1]; } workRange = (Range)workSheet.Cells; /*workSheet.Range[sRowColumn.DimensionRow, sRowColumn.DimensionColumn].Characters[1]*/ status = Excel_CommonFun.MappingDimenData(cCom_Dimension[i], workSheet, sRowColumn.DimensionRow, sRowColumn.DimensionColumn); if (!status) { MessageBox.Show("MappingDimenData時發生錯誤,請聯繫開發工程師"); //workBook.SaveAs(sDB_MEMain.excelTemplateFilePath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing //, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); return(false); } #region 泡泡、泡泡位置、檢具、刀號、頻率、料號、製程序、客戶版次、日期 workRange[sRowColumn.BallonRow, sRowColumn.BallonColumn] = cCom_Dimension[i].ballon; workRange[sRowColumn.LocationRow, sRowColumn.LocationColumn] = cCom_Dimension[i].location; workRange[sRowColumn.GaugeRow, sRowColumn.GaugeColumn] = cCom_Dimension[i].instrument; workRange[sRowColumn.ToolNoControlRow, sRowColumn.ToolNoControlColumn] = cCom_Dimension[i].toolNoControl; workRange[sRowColumn.FrequencyRow, sRowColumn.FrequencyColumn] = cCom_Dimension[i].frequency; workRange[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = partNo; workRange[sRowColumn.OISRow, sRowColumn.OISColumn] = op1; workRange[sRowColumn.OISRevRow, sRowColumn.OISRevColumn] = cusVer; workRange[sRowColumn.DateRow, sRowColumn.DateColumn] = DateTime.Now.ToShortDateString(); #endregion } if (File.Exists(OutputPath)) { File.Delete(OutputPath); } workBook.SaveAs(OutputPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing , XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); } catch (System.Exception ex) { if (File.Exists(OutputPath)) { File.Delete(OutputPath); } workBook.SaveAs(OutputPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); File.Delete(OutputPath); return(false); } finally { Dispose(excelApp, workBook, workSheet, workRange); } return(true); }
public static bool CreateIQCExcel_XinWu(string cusName, string partNo, string cusVer, string opVer, string op1, DB_MEMain sDB_MEMain, IList <Com_Dimension> cCom_Dimension) { //判斷Server的Template是否存在 if (!File.Exists(sDB_MEMain.excelTemplateFilePath)) { return(false); } ApplicationClass excelApp = new ApplicationClass(); Workbook workBook = null; Worksheet workSheet = null; Range workRange = null; try { //設定輸出路徑 OutputPath = string.Format(@"{0}\{1}_{2}_{3}\{4}_{5}_{6}_{7}" , Environment.GetFolderPath(Environment.SpecialFolder.Desktop) , partNo , cusVer , opVer , partNo , cusVer , opVer , op1 + "_" + sDB_MEMain.factory + ".xls"); //1.開啟Excel //2.將Excel設為不顯示 //3.取得第一頁Sheet workBook = (Workbook)excelApp.Workbooks.Open(sDB_MEMain.excelTemplateFilePath); excelApp.Visible = false; workSheet = (Worksheet)workBook.Sheets[1]; //建立Sheet頁數符合所有的Dimension int Dicount = 0; foreach (Com_Dimension i in cCom_Dimension) { if (i.balloonCount != null) { Dicount = Convert.ToInt32(i.balloonCount) + Dicount; } else { Dicount++; } } status = Excel_CommonFun.AddNewSheet(Dicount, 8, excelApp, workSheet); if (!status) { MessageBox.Show("建立Sheet頁失敗,請聯繫開發工程師"); return(false); } //修改每一個Sheet名字和頁數 status = Excel_CommonFun.ModifySheet(partNo, "IQC", workBook, workSheet, workRange, sDB_MEMain.factory); if (!status) { MessageBox.Show("修改Sheet名字失敗,請聯繫開發工程師"); return(false); } RowColumn sRowColumn = new RowColumn(); int currentSheet_Value; int count = -1; foreach (Com_Dimension i in cCom_Dimension) { if (i.balloonCount == null) { count++; GetExcelRowColumn(count, out sRowColumn); currentSheet_Value = (count / 8); if (currentSheet_Value == 0) { workSheet = (Worksheet)workBook.Sheets[1]; } else { workSheet = (Worksheet)workBook.Sheets[currentSheet_Value + 1]; } workRange = (Range)workSheet.Cells; status = Excel_CommonFun.MappingDimenData(i, workSheet, sRowColumn.DimensionRow, sRowColumn.DimensionColumn); //status = Excel_CommonFun.MappingDimenData(cCom_Dimension[i], workRange, sRowColumn.DimensionRow, sRowColumn.DimensionColumn); if (!status) { MessageBox.Show("MappingDimenData時發生錯誤,請聯繫開發工程師"); return(false); } #region 檢具、頻率、Max、Min、泡泡、泡泡位置、料號、日期 workRange[sRowColumn.GaugeRow, sRowColumn.GaugeColumn] = "=" + "\"" + i.instrument.Split(',')[0] + "\"" + "&char(10)&" + "\"" + i.instrument.Split(',')[1] + "\""; workRange[sRowColumn.BallonRow, sRowColumn.BallonColumn] = i.ballon; workRange[sRowColumn.LocationRow, sRowColumn.LocationColumn] = i.location; workRange[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = partNo + string.Format("({0})", cusVer); workRange[sRowColumn.PartDescRow, sRowColumn.PartDescColumn] = sDB_MEMain.comMEMain.partDescription; workRange[sRowColumn.MaterialRow, sRowColumn.MaterialColumn] = sDB_MEMain.comMEMain.material; workRange[sRowColumn.OISRow, sRowColumn.OISColumn] = op1; workRange[sRowColumn.OISRevRow, sRowColumn.OISRevColumn] = sDB_MEMain.comMEMain.draftingVer; #endregion } else { for (int j = 0; j < Convert.ToInt32(i.balloonCount); j++) { count++; GetExcelRowColumn(count, out sRowColumn); currentSheet_Value = (count / 8); if (currentSheet_Value == 0) { workSheet = (Worksheet)workBook.Sheets[1]; } else { workSheet = (Worksheet)workBook.Sheets[currentSheet_Value + 1]; } workRange = (Range)workSheet.Cells; status = Excel_CommonFun.MappingDimenData(i, workSheet, sRowColumn.DimensionRow, sRowColumn.DimensionColumn); //status = Excel_CommonFun.MappingDimenData(cCom_Dimension[i], workRange, sRowColumn.DimensionRow, sRowColumn.DimensionColumn); if (!status) { MessageBox.Show("MappingDimenData時發生錯誤,請聯繫開發工程師"); return(false); } #region 檢具、頻率、Max、Min、泡泡、泡泡位置、料號、日期 workRange[sRowColumn.GaugeRow, sRowColumn.GaugeColumn] = "=" + "\"" + i.instrument.Split(',')[0] + "\"" + "&char(10)&" + "\"" + i.instrument.Split(',')[1] + "\""; if (i.balloonCount != null && Convert.ToInt32(i.balloonCount) > 1) { workRange[sRowColumn.BallonRow, sRowColumn.BallonColumn] = i.ballon.ToString() + "." + Convert.ToChar(65 + j).ToString().ToLower(); } else { workRange[sRowColumn.BallonRow, sRowColumn.BallonColumn] = i.ballon.ToString(); } workRange[sRowColumn.LocationRow, sRowColumn.LocationColumn] = i.location; workRange[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = partNo + string.Format("({0})", cusVer); workRange[sRowColumn.PartDescRow, sRowColumn.PartDescColumn] = sDB_MEMain.comMEMain.partDescription; workRange[sRowColumn.MaterialRow, sRowColumn.MaterialColumn] = sDB_MEMain.comMEMain.material; workRange[sRowColumn.OISRow, sRowColumn.OISColumn] = op1; workRange[sRowColumn.OISRevRow, sRowColumn.OISRevColumn] = sDB_MEMain.comMEMain.draftingVer; #endregion } } } //for (int i = 0; i < cCom_Dimension.Count; i++) //{ // GetExcelRowColumn(i, out sRowColumn); // currentSheet_Value = (i / 8); // if (currentSheet_Value == 0) // { // workSheet = (Worksheet)workBook.Sheets[1]; // } // else // { // workSheet = (Worksheet)workBook.Sheets[currentSheet_Value + 1]; // } // workRange = (Range)workSheet.Cells; // status = Excel_CommonFun.MappingDimenData(cCom_Dimension[i], workSheet, sRowColumn.DimensionRow, sRowColumn.DimensionColumn); // //status = Excel_CommonFun.MappingDimenData(cCom_Dimension[i], workRange, sRowColumn.DimensionRow, sRowColumn.DimensionColumn); // if (!status) // { // MessageBox.Show("MappingDimenData時發生錯誤,請聯繫開發工程師"); // return false; // } // #region 檢具、頻率、Max、Min、泡泡、泡泡位置、料號、日期 // workRange[sRowColumn.GaugeRow, sRowColumn.GaugeColumn] = cCom_Dimension[i].instrument; // workRange[sRowColumn.BallonRow, sRowColumn.BallonColumn] = cCom_Dimension[i].ballon; // workRange[sRowColumn.LocationRow, sRowColumn.LocationColumn] = cCom_Dimension[i].location; // workRange[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = partNo + string.Format("({0})", cusVer); // workRange[sRowColumn.PartDescRow, sRowColumn.PartDescColumn] = sDB_MEMain.comMEMain.partDescription; // workRange[sRowColumn.MaterialRow, sRowColumn.MaterialColumn] = sDB_MEMain.comMEMain.material; // workRange[sRowColumn.OISRow, sRowColumn.OISColumn] = op1; // workRange[sRowColumn.OISRevRow, sRowColumn.OISRevColumn] = sDB_MEMain.comMEMain.draftingVer; // #endregion //} if (File.Exists(OutputPath)) { File.Delete(OutputPath); } workBook.SaveAs(OutputPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing , XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); } catch (System.Exception ex) { if (File.Exists(OutputPath)) { File.Delete(OutputPath); } workBook.SaveAs(OutputPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); File.Delete(OutputPath); return(false); } finally { Dispose(excelApp, workBook, workSheet, workRange); } return(true); }
public static bool CreateShopDocExcel_XinWu(string cusName, string partNo, string cusVer, string opVer, string op1, DB_TEMain sDB_TEMain, IList <Com_ShopDoc> cCom_ShopDoc) { //判斷Server的Template是否存在 if (!File.Exists(sDB_TEMain.excelTemplateFilePath)) { return(false); } ApplicationClass excelApp = new ApplicationClass(); Workbook workBook = null; Worksheet workSheet = null; Range workRange = null; try { //設定輸出路徑 OutputPath = string.Format(@"{0}\{1}_{2}_{3}\{4}_{5}_{6}_{7}" , Environment.GetFolderPath(Environment.SpecialFolder.Desktop) , partNo , cusVer , opVer , partNo , cusVer , opVer , sDB_TEMain.comTEMain.ncGroupName + "_" + "ShopDoc" + ".xls"); //MessageBox.Show("0"); //1.開啟Excel //2.將Excel設為不顯示 //3.取得第一頁Sheet workBook = (Workbook)excelApp.Workbooks.Open(sDB_TEMain.excelTemplateFilePath); //MessageBox.Show("1"); excelApp.Visible = false; //MessageBox.Show("2"); workSheet = (Worksheet)workBook.Sheets[1]; //MessageBox.Show("3"); //建立Sheet頁數符合所有的Operation status = Excel_CommonFun.AddNewSheet(cCom_ShopDoc.Count, 8, excelApp, workSheet); if (!status) { MessageBox.Show("建立Sheet頁失敗,請聯繫開發工程師"); return(false); } //修改每一個Sheet名字和頁數 status = Excel_CommonFun.ModifySheet(sDB_TEMain.ncGroupName, "ShopDoc", workBook, workSheet, workRange, sDB_TEMain.factory); if (!status) { MessageBox.Show("修改Sheet名字和頁數失敗,請聯繫開發工程師"); return(false); } //計算欄位的初始TOP double de = 0; for (int i = 1; i < 23; i++) { workRange = (Range)workSheet.Cells[i, 1]; de = de + Convert.ToDouble(workRange.Height); //CaxLog.ShowListingWindow(oRng.Height.ToString()); } //CaxLog.ShowListingWindow(de.ToString()); //計算欄位的初始LEFT double abc = 0; for (int i = 1; i < 9; i++) { workRange = (Range)workSheet.Cells[23, i]; abc = abc + Convert.ToDouble(workRange.Width.ToString()); } //開始填表 RowColumn sRowColumn; for (int i = 0; i < cCom_ShopDoc.Count; i++) { GetExcelRowColumn(i, out sRowColumn); //取得當前Operation該放置的Sheet int currentSheet_Value = (i / 8); //int currentSheet_Reserve = (i % 8); if (currentSheet_Value == 0) { workSheet = (Worksheet)workBook.Sheets[1]; } else { workSheet = (Worksheet)workBook.Sheets[currentSheet_Value + 1]; } workRange = (Range)workSheet.Cells; workRange[sRowColumn.OperImgToolRow, sRowColumn.OperImgToolColumn] = cCom_ShopDoc[i].toolNo + "_" + cCom_ShopDoc[i].operationName; //workRange[sRowColumn.ToolNumberRow, sRowColumn.ToolNumberColumn] = cCom_ShopDoc[i].toolNo; workRange[sRowColumn.ToolNameRow, sRowColumn.ToolNameColumn] = cCom_ShopDoc[i].toolID; workRange[sRowColumn.OperNameRow, sRowColumn.OperNameColumn] = cCom_ShopDoc[i].operationName; workRange[sRowColumn.HolderRow, sRowColumn.HolderColumn] = cCom_ShopDoc[i].holderID; workRange[sRowColumn.ToolFeedRow, sRowColumn.ToolFeedColumn] = "F:" + cCom_ShopDoc[i].feed; workRange[sRowColumn.ToolSpeedRow, sRowColumn.ToolSpeedColumn] = cCom_ShopDoc[i].speed; workRange[sRowColumn.PartStockRow, sRowColumn.PartStockColumn] = cCom_ShopDoc[i].partStock; workRange[sRowColumn.CutterLifeRow, sRowColumn.CutterLifeColumn] = cCom_ShopDoc[i].cutterLife; workRange[sRowColumn.ExtensionRow, sRowColumn.ExtensionColumn] = cCom_ShopDoc[i].extension; workRange[sRowColumn.CuttingTimeRow, sRowColumn.CuttingTimeColumn] = cCom_ShopDoc[i].machiningtime; workRange[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = partNo; workRange[sRowColumn.TotalCuttingTimeRow, sRowColumn.TotalCuttingTimeColumn] = sDB_TEMain.comTEMain.totalCuttingTime; workRange[sRowColumn.PartDescRow, sRowColumn.PartDescColumn] = "OIS-" + sDB_TEMain.ncGroupName.Split('P')[1]; //加入 機台型號.設計.審核.批准 workRange[sRowColumn.MachineNoRow, sRowColumn.MachineNoColumn] = sDB_TEMain.comTEMain.machineNo; workRange[sRowColumn.DesignedRow, sRowColumn.DesignedColumn] = sDB_TEMain.comTEMain.designed; workRange[sRowColumn.ReviewedRow, sRowColumn.ReviewedColumn] = sDB_TEMain.comTEMain.reviewed; workRange[sRowColumn.ApprovedRow, sRowColumn.ApprovedColumn] = sDB_TEMain.comTEMain.approved; OperImgPosiSize sImgPosiSize = new OperImgPosiSize(); GetOperImgPosiAndSize(i, out sImgPosiSize); if (File.Exists(cCom_ShopDoc[i].opImagePath)) { workSheet.Shapes.AddPicture(cCom_ShopDoc[i].opImagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, sImgPosiSize.OperPosiLeft, sImgPosiSize.OperPosiTop, sImgPosiSize.OperImgWidth, sImgPosiSize.OperImgHeight); } } //加入控制尺寸資訊(未開發) ISession session = MyHibernateHelper.SessionFactory.OpenSession(); IList <Com_ControlDimen> ListComControlDimen = session.QueryOver <Com_ControlDimen>() .Where(x => x.comTEMain == sDB_TEMain.comTEMain).List(); int j = 0, initialControlDimenRow = 39, ControlDimenToolNoColumn = 9, ControlDimenBalloonColumn = 10, ControlDimenColumn = 11; string toolNo = ""; foreach (Com_ControlDimen i in ListComControlDimen) { workSheet = (Worksheet)workBook.Sheets[1 + j]; workRange = (Range)workSheet.Cells; if (toolNo == "" || toolNo != i.toolNo) { workRange[initialControlDimenRow, ControlDimenToolNoColumn] = i.toolNo; toolNo = i.toolNo; } workRange[initialControlDimenRow, ControlDimenBalloonColumn] = i.controlBallon; workRange[initialControlDimenRow, ControlDimenColumn] = i.controlDimen; initialControlDimenRow++; if (initialControlDimenRow == 47) { j++; } } //加入治具圖片 if (sDB_TEMain.comTEMain.fixtureImgPath != "") { FixImgPosiSize sFixImgPosiSize = new FixImgPosiSize(); GetFixImgPosiAndSize(out sFixImgPosiSize); for (int i = 0; i < workBook.Sheets.Count; i++) { workSheet = (Worksheet)workBook.Sheets[i + 1]; if (File.Exists(sDB_TEMain.comTEMain.fixtureImgPath)) { workSheet.Shapes.AddPicture(sDB_TEMain.comTEMain.fixtureImgPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, (float)(abc + 3), (float)(de + 5), sFixImgPosiSize.FixImgWidth, sFixImgPosiSize.FixImgHeight); } } } if (File.Exists(OutputPath)) { File.Delete(OutputPath); } workBook.SaveAs(OutputPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); if (File.Exists(OutputPath)) { File.Delete(OutputPath); } workBook.SaveAs(OutputPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workBook.Close(Type.Missing, Type.Missing, Type.Missing); excelApp.Quit(); File.Delete(OutputPath); return(false); } finally { Dispose(excelApp, workBook, workSheet, workRange); } return(true); }