private void add_item(string itemDescription, string idType, bool hasCheckboxes) { int rowOffset = currentRow * 30 - 102; oRng = oSheet.Cells[currentRow, 1]; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; oRng.Value = " " + itemDescription; oRng = oSheet.Cells[currentRow, 9]; oRng.Value = idType; if (hasCheckboxes) { //add check boxes obj = objs.Add("Forms.Checkbox.1", Missing.Value, Missing.Value, false, false, Missing.Value, Missing.Value, 240, rowOffset, 120, 16); obj.Object.Caption = "SPECIAL M'TL REQUIREMENTS"; obj.Object.Value = false; obj.Object.Font.Size = 6.5; obj = objs.Add("Forms.Checkbox.1", Missing.Value, Missing.Value, false, false, Missing.Value, Missing.Value, 240, rowOffset + 12, 120, 16); obj.Object.Caption = "NORMALIZED M'TL"; obj.Object.Value = false; obj.Object.Font.Size = 6.5; } currentRow++; }
public ExcelCheckBox(ExcelInterop.Range range, ExcelCheckBoxDefinition definition) { OwnerRange = range; OwnerRange.Value2 = null; ExcelInterop.Worksheet worksheet = null; ExcelInterop.OLEObjects oleObjects = null; ExcelInterop.OLEObject oleObject = null; try { worksheet = OwnerRange.Worksheet; Name = $"ExcelCB{Interlocked.Increment(ref cpt)}"; oleObjects = worksheet.OLEObjects(); oleObject = oleObjects.Add("Forms.CheckBox.1", Type.Missing, true, false, Type.Missing, Type.Missing, Type.Missing, OwnerRange.Left + 3, OwnerRange.Top + 1, 12, 12); oleObject.Name = Name; oleObject.Placement = ExcelInterop.XlPlacement.xlMove; CheckBox = worksheet.GetType().InvokeMember(Name, BindingFlags.Default | BindingFlags.GetProperty, null, worksheet, null) as ExcelForms.CheckBox; CheckBox.SpecialEffect = ExcelForms.fmButtonEffect.fmButtonEffectSunken; CheckBox.TripleState = false; CheckBox.Caption = string.Empty; CheckBox.BackColor = (int)OwnerRange.Interior.Color; CheckBox.BackStyle = ExcelForms.fmBackStyle.fmBackStyleTransparent; oleObject.Interior.ColorIndex = -4142; CheckBox.AutoSize = false; oleObject = null; } finally { if (oleObject != null) { ExcelApplication.ReleaseComObject(oleObject); } if (oleObjects != null) { ExcelApplication.ReleaseComObject(oleObjects); } if (worksheet != null) { ExcelApplication.ReleaseComObject(worksheet); } oleObject = null; oleObjects = null; worksheet = null; } }
public ExcelButton(ExcelInterop.Range range, ExcelButtonDefinition definition) { OwnerRange = range; OwnerRange.Value2 = null; ExcelInterop.Worksheet worksheet = null; ExcelInterop.OLEObjects oleObjects = null; ExcelInterop.OLEObject obj = null; try { worksheet = OwnerRange.Worksheet; Name = $"ExcelBtn{Interlocked.Increment(ref cpt)}"; oleObjects = worksheet.OLEObjects(); obj = oleObjects.Add("Forms.CommandButton.1", Type.Missing, false, false, Type.Missing, Type.Missing, Type.Missing, OwnerRange.Left + definition.X, OwnerRange.Top + definition.Y, definition.W == 0 ? OwnerRange.Width : definition.W, definition.H == 0 ? OwnerRange.Height : definition.H); obj.Name = Name; object s = worksheet.GetType().InvokeMember(Name, BindingFlags.Default | BindingFlags.GetProperty, null, worksheet, null); commandButton = s as ExcelForms.CommandButton; commandButton.FontName = "Arial"; commandButton.Font.Size = 8; commandButton.Caption = definition.Label; //if (excelTemplateDefinition.W == 0 && excelTemplateDefinition.H == 0) // commandButton.AutoSize = true; obj.Placement = ExcelInterop.XlPlacement.xlMove; } finally { if (obj != null) { ExcelApplication.ReleaseComObject(obj); } if (oleObjects != null) { ExcelApplication.ReleaseComObject(oleObjects); } if (worksheet != null) { ExcelApplication.ReleaseComObject(worksheet); } obj = null; oleObjects = null; worksheet = null; } }
private void title_block1() { //LINE 1 oRng = oSheet.Range[oSheet.Cells[currentRow, 1], oSheet.Cells[currentRow, 8]]; oRng.Merge(); oRng.Font.Bold = true; oRng.Font.Size = 14; oRng.Value = "REFRIGERATION VALVES AND SYSTEMS VESSEL TRAVELER"; oRng = oSheet.Cells[currentRow, 9]; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight; oRng.Value = "SHT"; oRng = oSheet.Cells[currentRow, 10]; oRng.Value = 1; oRng = oSheet.Range[oSheet.Cells[currentRow, 11], oSheet.Cells[currentRow, 12]]; oRng.Merge(); oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; oRng.Value = "OF"; oRng = oSheet.Cells[currentRow, 13]; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; oRng.Value = sheet_count; currentRow++; //LINE 2 oRng = oSheet.Range[oSheet.Cells[currentRow, 1], oSheet.Cells[currentRow, 2]]; oRng.Merge(); oRng.Font.Bold = true; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight; oRng.Value = "DRAWING #"; oRng = oSheet.Range[oSheet.Cells[currentRow, 3], oSheet.Cells[currentRow, 4]]; oRng.Merge(); oRng.Font.Bold = true; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; oRng.Value = drawing_number; oRng = oSheet.Range[oSheet.Cells[currentRow, 5], oSheet.Cells[currentRow, 6]]; oRng.Merge(); oRng.Font.Bold = true; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight; oRng.Value = "REV."; oRng = oSheet.Range[oSheet.Cells[currentRow, 7], oSheet.Cells[currentRow, 8]]; oRng.Merge(); oRng.Font.Bold = true; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; oRng.Value = revision_number; oRng = oSheet.Range[oSheet.Cells[currentRow, 9], oSheet.Cells[currentRow, 10]]; oRng.Merge(); oRng.Font.Bold = true; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight; oRng.Value = "SERIAL #"; oRng = oSheet.Range[oSheet.Cells[currentRow, 11], oSheet.Cells[currentRow, 13]]; oRng.Merge(); oRng.Font.Bold = true; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; oRng.Value = serial_number; currentRow++; //LINE 3 oRng = oSheet.Range[oSheet.Cells[currentRow, 1], oSheet.Cells[currentRow, 6]]; oRng.Merge(); obj = objs.Add("Forms.Checkbox.1", Missing.Value, Missing.Value, false, false, Missing.Value, Missing.Value, 5, 41, 120, 16); obj.Object.Caption = "SPECIAL M'TL REQUIREMENTS"; obj.Object.Value = false; obj.Object.Font.Size = 8; obj = objs.Add("Forms.Checkbox.1", Missing.Value, Missing.Value, false, false, Missing.Value, Missing.Value, 160, 41, 90, 16); obj.Object.Caption = "NORMALIZED M'TL"; obj.Object.Value = false; obj.Object.Font.Size = 8; obj = objs.Add("Forms.Checkbox.1", Missing.Value, Missing.Value, false, false, Missing.Value, Missing.Value, 262, 41, 15, 16); obj.Object.Caption = ""; obj.Object.Value = true; obj.Object.Font.Size = 8; oRng = oSheet.Range[oSheet.Cells[currentRow, 7], oSheet.Cells[currentRow, 13]]; oRng.Merge(); oRng.Font.Size = 8; oRng.WrapText = true; oRng.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; oRng.Value = special_note; currentRow++; //LINE 4 oRng = oSheet.Cells[currentRow, 1]; oRng.Value = "DESCRIBE SPECIFIC ITEMS TO BE INSPECTED"; oRng.Font.Bold = true; oRng = oSheet.Cells[currentRow, 9]; oRng.Value = "X"; oRng = oSheet.Cells[currentRow, 10]; oRng.Font.Size = 10; oRng.Value = "QC HOLD"; oRng = oSheet.Cells[currentRow, 12]; oRng.Value = "X"; oRng = oSheet.Cells[currentRow, 13]; oRng.Font.Size = 10; oRng.Value = "A/I HOLD"; currentRow++; }