/// <summary> /// Draws shapefile category. /// </summary> private void DrawShapefileCategorySymbology(int hdcInt, int top, ShapeDrawingOptions options, int categoryIndex, bool hasCheckbox) { var categoryHeight = _layer.GetCategoryHeight(options); var categoryWidth = _layer.GetCategoryWidth(options); var backColor = Convert.ToUInt32(ColorTranslator.ToOle(Legend.BackColor)); var left = _bounds.Left + Constants.TextLeftPad; if (hasCheckbox) { left += Constants.CategoryCheckboxWidthWithPadding(); } if (categoryWidth != Constants.IconWidth) { left -= (categoryWidth - Constants.IconWidth) / 2; } switch (_layer.LegendLayerType) { case LegendLayerType.PointShapefile: options.DrawPoint(hdcInt, left, top, categoryWidth + 1, categoryHeight + 1, backColor); break; case LegendLayerType.LineShapefile: options.DrawLine( hdcInt, left, top, categoryWidth - 1, Constants.IconHeight - 1, false, categoryWidth, categoryHeight, backColor); break; case LegendLayerType.PolygonShapefile: options.DrawRectangle( hdcInt, left, top, categoryWidth - 1, Constants.IconHeight - 1, false, categoryWidth, categoryHeight, backColor); break; } _layer.Elements.Add(LayerElementType.ColorBox, new Rectangle(left, top, categoryWidth, categoryHeight), categoryIndex); }
/// <summary> /// Formats shape to default style. /// </summary> public static void FormatCalloutToDefaultStyle(Shape calloutBox) { calloutBox.TextFrame.WordWrap = MsoTriState.msoTrue; calloutBox.TextFrame.TextRange.Font.Size = DefaultFontSize; calloutBox.Fill.ForeColor.RGB = 0; calloutBox.Fill.Transparency = DefaultCalloutFillTransparency; calloutBox.Shadow.Type = MsoShadowType.msoShadow25; calloutBox.Line.ForeColor.RGB = ColorTranslator.ToOle(Color.Yellow); calloutBox.Line.Weight = DefaultLineWeight; calloutBox.TextFrame.TextRange.Font.Color.RGB = ColorTranslator.ToOle(Color.White); }
private void butColorChooser_Click(object sender, EventArgs e) { ColorDialog colDialog = new ColorDialog(); colDialog.Color = ((Button)sender).BackColor; colDialog.CustomColors = new int[] { ColorTranslator.ToOle(colDialog.Color) }; if (colDialog.ShowDialog() == DialogResult.OK) { ((Button)sender).BackColor = colDialog.Color; } }
private void PutCellBorder(string cell, string val) { PutCell(cell, val); _range.Interior.Color = ColorTranslator.ToOle(_color); _range.Columns.AutoFit(); _range.BorderAround( Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, Type.Missing ); }
public uint Color2Uint32(Color clr) { int t; byte[] a; t = ColorTranslator.ToOle(clr); a = BitConverter.GetBytes(t); return(BitConverter.ToUInt32(a, 0)); }
/// <summary> /// ColorMergedRow /// </summary> /// <param name="row"></param> /// <param name="height"></param> /// <param name="start_col"></param> /// <param name="end_col"></param> /// <param name="color"></param> /// <param name="border"></param> public void ColorMergedRow(int row, double height = 15, string start_col = "A", string end_col = "K", Color?color = null, bool border = true) { Color rgb = color ?? Color.FromArgb(192, 192, 192); sheet1.Range[start_col + row, end_col + row].Merge(); if (border == true) { sheet1.Range[start_col + row, end_col + row].Cells.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; } sheet1.Cells[row, start_col].Interior.Color = ColorTranslator.ToOle(rgb); sheet1.Cells[row, start_col].RowHeight = height; }
/// <summary> /// Sets back color of specified text part. Doesn't return cursor to original position! /// </summary> /// <param name="startIndex">First colored character.</param> /// <param name="length">Colored text length.</param> /// <param name="color">New text color.</param> public void SetBackColor(int startIndex, int length, System.Drawing.Color color) { SelectionStart = startIndex; SelectionLength = length; Native.CharFormat2 format = new Native.CharFormat2(); format.cbSize = Marshal.SizeOf(format); format.dwMask = Native.CFM_BACKCOLOR; format.crTextColor = ColorTranslator.ToOle(color); Native.SendMessage(Handle, Native.EM_SETCHARFORMAT, Native.SCF_SELECTION, ref format); }
void AddHorizontalLine(Document d) { object missing = Missing.Value; var line = d.Paragraphs.Last.Range.InlineShapes.AddHorizontalLineStandard(ref missing); line.Height = 1; line.Fill.Solid(); line.HorizontalLineFormat.NoShade = true; line.Fill.ForeColor.RGB = ColorTranslator.ToOle(Color.Black); line.HorizontalLineFormat.PercentWidth = 100; line.HorizontalLineFormat.Alignment = WdHorizontalLineAlignment.wdHorizontalLineAlignCenter; }
public void SetHorizontalBorderColor(Color color) { Excel.Range _range = _GetRange(); Excel.Borders _borders = _range.Borders; Excel.Border _border = _borders[Excel.XlBordersIndex.xlInsideHorizontal]; var oleColor = ColorTranslator.ToOle(color); _border.Color = oleColor; Marshal.ReleaseComObject(_border); Marshal.ReleaseComObject(_borders); Marshal.ReleaseComObject(_range); }
private void excelBtn_Click(object sender, EventArgs e) { Excel.Application excelApp = new Excel.Application(); Excel.Workbook workBook; Excel.Worksheet workSheet; workBook = excelApp.Workbooks.Add(); workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(1); workSheet.Name = "Список клиентов"; workSheet.Cells[1, 1] = "ФИО"; workSheet.Cells[1, 2] = "Серия паспорта"; workSheet.Cells[1, 3] = "Номер паспорта"; workSheet.Cells[1, 4] = "День рождения"; workSheet.Cells[1, 5] = "Номер телефона"; workSheet.Cells[1, 6] = "Эл. почта"; Excel.Range title = workSheet.Range["A1:F1"]; title.Cells.Font.Name = "Tahoma"; title.Font.Size = "16"; title.Cells.Font.Color = ColorTranslator.ToOle(Color.Green); title.Interior.Color = ColorTranslator.ToOle(Color.FromArgb(0xFF, 0xFF, 0xCC)); title.Borders.get_Item(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous; title.Borders.get_Item(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous; title.Borders.get_Item(Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlContinuous; title.Borders.get_Item(Excel.XlBordersIndex.xlInsideVertical).LineStyle = Excel.XlLineStyle.xlContinuous; title.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous; title.EntireColumn.AutoFit(); title.EntireRow.AutoFit(); title.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; title.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; for (int i = 0; i < dgvClients.ColumnCount - 2; i++) { for (int j = 0; j < dgvClients.RowCount; j++) { if (i > 0) { workSheet.Cells[j + 2, i] = dgvClients.Rows[j].Cells[i + 1].Value.ToString(); workSheet.Cells[j + 2, i].Font.Name = "Tahoma"; workSheet.Cells[j + 2, i].Font.Size = "14"; workSheet.Cells[j + 2, i].EntireColumn.AutoFit(); workSheet.Cells[j + 2, i].EntireRow.AutoFit(); workSheet.Cells[j + 2, i].VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; workSheet.Cells[j + 2, i].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; } else { break; } } } // Открываем созданный excel-файл excelApp.Visible = true; excelApp.UserControl = true; }
public void Render(ReportProgressUpdate updateFunc, ReportStatusUpdate doneFunc) { ArrayList rows = cacheObj.GetChildArray("ROWS"); int rowCnt = rows.Count; int r = 0; foreach (CTable row in rows) { r++; String rowType = row.GetFieldValue("ROW_TYPE"); ArrayList columns = row.GetChildArray("COLUMNS"); updateFunc(r, rowCnt); foreach (CTable column in columns) { int fromCell = CUtil.StringToInt(column.GetFieldValue("FROM_CELL")); int toCell = CUtil.StringToInt(column.GetFieldValue("TO_CELL")); Boolean isMerged = column.GetFieldValue("IS_MERGED").Equals("True"); Range r1 = xlWorkSheet.Cells[r, fromCell]; Range rowRange = null; if (isMerged) { Range r2 = xlWorkSheet.Cells[r, toCell]; Range newRange = xlWorkSheet.Range[r1, r2]; newRange.Merge(); rowRange = newRange; applyCellStyle(column, newRange); } else { rowRange = r1; applyCellStyle(column, r1); } if (rowType.Contains("HEADER")) { rowRange.Interior.Color = ColorTranslator.ToOle(Color.Orange); } else if (rowType.Contains("FOOTER")) { rowRange.Interior.Color = ColorTranslator.ToOle(Color.Tan); } } } doneFunc(true, false); }
private void DrawColomn(string table, Excel.Worksheet sheet, int line, int column, Question q) { sheet.Cells[line, column] = q.Label; sheet.Cells[line, column].Interior.Color = ColorTranslator.ToOle(Color.LightGreen); var ds = DataExtractionUtils.GetAnswersByColumn(table, q.Column); var tmp = line + 1; for (var j = 0; j < ds.Tables[0].Rows.Count; j++) { sheet.Cells[tmp, column] = ds.Tables[0].Rows[j][q.Column]; tmp++; } }
/// <summary> /// 给单元格赋值3 /// </summary> /// <param name="x">列号</param> /// <param name="y">行号</param> /// <param name="text">值</param> /// <param name="font">字符格式</param> /// <param name="color">颜色</param> public void setValue(int x, int y, string text, System.Drawing.Font font, int color) { this.SetValue(x, y, text); Range range = sheet.get_Range(this.GetAix(x, y), miss); range.Font.Size = font.Size; range.Font.Bold = font.Bold; //这里是int型的颜色 range.Font.Color = ColorTranslator.ToOle(ColorTranslator.FromWin32(color)); range.Font.Name = font.Name; range.Font.Italic = font.Italic; range.Font.Underline = font.Underline; }
private ICellStyle getStyleFromColor(Color color, XSSFWorkbook wb) { short col = (short)ColorTranslator.ToOle(color); if (!colorMap.ContainsKey(col)) { ICellStyle s = wb.CreateCellStyle(); s.FillForegroundColor = col; s.FillPattern = FillPattern.SolidForeground; colorMap.Add(col, s); } return(colorMap[col]); }
public void FillColor(int row, int column, Color color, int width = 1, int height = 1) { if (row < 0 || column < 0 || width < 1 || height < 1) { throw new Exception("Неккоректные значения входных параметров!"); } //workSheet.get_Range(GetCellName(column, row + 1), Missing.Value).Interior.ColorIndex = color; String a = GetCellName(column, row + 1); String b = GetCellName(column + width - 1, row + height); workSheet.get_Range(a, b).Interior.Color = ColorTranslator.ToOle(color); }
public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet) { cancelSet = false; if (managedValue == null) { managedValue = Color.Black; } if (managedValue is Color) { return(ColorTranslator.ToOle((Color)managedValue)); } return(0); }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; base.OnPaint(e); IntPtr hrgn = Region.GetHrgn(e.Graphics); IntPtr hdc = e.Graphics.GetHdc(); IntPtr hBrush = CreateSolidBrush(ColorTranslator.ToOle(Color.Silver)); FrameRgn(hdc, hrgn, hBrush, 1, 1); Region.ReleaseHrgn(hrgn); DeleteObject(hBrush); e.Graphics.ReleaseHdc(hdc); }
private void addExpression(Shapefile sf, string name, string expression, string rgb) { // rgb example: rgb(37, 49, 232) rgb = rgb.Replace("rgb(", "").Replace(" ", "").Replace(")", ""); string[] rgbv = rgb.Split(','); ShapefileCategory ct = sf.Categories.Add(name); ct.Expression = expression; System.Drawing.Color co = Color.FromArgb(50, Int32.Parse(rgbv[0]), Int32.Parse(rgbv[1]), Int32.Parse(rgbv[2])); ct.DrawingOptions.FillColor = Convert.ToUInt32(ColorTranslator.ToOle(co)); ct.DrawingOptions.LineColor = Convert.ToUInt32(ColorTranslator.ToOle(co)); }
private void RenderChartPreview(ref int top) { var hdc = _graphics.GetHdc(); var backColor = Convert.ToUInt32(ColorTranslator.ToOle(Legend.BackColor)); var left = _bounds.Left + Constants.TextLeftPad; _sf.Charts.DrawChart(hdc, left, top, true, backColor); _layer.Elements.Add(LayerElementType.Charts, new Rectangle(left, top, _sf.Charts.IconWidth, _sf.Charts.IconHeight)); top += _sf.Charts.IconHeight + Constants.VerticalPad; _graphics.ReleaseHdc(hdc); }
public static int[] GetOLEColors() { return(new[] { ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_MILITARY_GRAY)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_DEFAULT_WHITE2)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_NAVY_BLUE)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_MILITARY_SAND)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_AIRCRAFT_YELLOW)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_WARNING_RED)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_INSIGNIA_BLUE)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_INSTRUMENT_BLACK)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_INTERIOR_GREEN)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_GUNSHIP_GREEN)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_CAMO_EARTH)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_DRAB_CAMO)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_CAMO_GRAY)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_SKY)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_MI8_BLUE)), ColorTranslator.ToOle(ColorTranslator.FromHtml(COLOR_MILITARY_LIGHT_GREEN)), }); }
public static object DWHS颜色Html转Ole( [ExcelArgument(Description = "输入网页Html格式颜色值,由#开头")] string inputHtmlColor ) { try { Color color = ColorTranslator.FromHtml(inputHtmlColor); return(ColorTranslator.ToOle(color)); } catch (Exception) { return(ExcelError.ExcelErrorNA); } }
private static Excel._Worksheet SetFirstWorkSheet(Excel._Workbook workbook, Excel.Application excelApp) { var firstWorkSheet = (Excel._Worksheet)workbook.Worksheets[1]; firstWorkSheet.Name = "商品資料"; firstWorkSheet.Activate(); InitialExcelTitles(excelApp); var range = firstWorkSheet.Range[firstWorkSheet.Cells[1, 1], firstWorkSheet.Cells[1, 41]]; range.Select(); range.Font.Color = ColorTranslator.ToOle(Color.White); range.Interior.Color = ColorTranslator.ToOle(Color.DimGray); return(firstWorkSheet); }
private void selectColor(int numColor) { using (ColorDialog colorForm = new ColorDialog()) { colorForm.CustomColors = new int[] { ColorTranslator.ToOle(Color.FromArgb(int.Parse("FFFF4500", System.Globalization.NumberStyles.HexNumber))), ColorTranslator.ToOle(Color.FromArgb(int.Parse("FFFFFF00", System.Globalization.NumberStyles.HexNumber))), ColorTranslator.ToOle(Color.FromArgb(int.Parse("FF90EE90", System.Globalization.NumberStyles.HexNumber))) }; if (colorForm.ShowDialog() == DialogResult.OK) { if (numColor == 0) { Properties.Settings.Default.twoColor = colorForm.Color.A.ToString("X2") + colorForm.Color.R.ToString("X2") + colorForm.Color.G.ToString("X2") + colorForm.Color.B.ToString("X2"); } else if (numColor == 1) { Properties.Settings.Default.threeColor = colorForm.Color.A.ToString("X2") + colorForm.Color.R.ToString("X2") + colorForm.Color.G.ToString("X2") + colorForm.Color.B.ToString("X2"); } else if (numColor == 2) { Properties.Settings.Default.fourColor = colorForm.Color.A.ToString("X2") + colorForm.Color.R.ToString("X2") + colorForm.Color.G.ToString("X2") + colorForm.Color.B.ToString("X2"); } else if (numColor == 3) { Properties.Settings.Default.fiveColor = colorForm.Color.A.ToString("X2") + colorForm.Color.R.ToString("X2") + colorForm.Color.G.ToString("X2") + colorForm.Color.B.ToString("X2"); } Properties.Settings.Default.Save(); if (numColor == 0) { twoStepColor.BackColor = Color.FromArgb(int.Parse(Properties.Settings.Default.twoColor, System.Globalization.NumberStyles.HexNumber)); } else if (numColor == 1) { threeStepColor.BackColor = Color.FromArgb(int.Parse(Properties.Settings.Default.threeColor, System.Globalization.NumberStyles.HexNumber)); } else if (numColor == 2) { fourStepColor.BackColor = Color.FromArgb(int.Parse(Properties.Settings.Default.fourColor, System.Globalization.NumberStyles.HexNumber)); } else if (numColor == 3) { fiveStepColor.BackColor = Color.FromArgb(int.Parse(Properties.Settings.Default.fiveColor, System.Globalization.NumberStyles.HexNumber)); } } } }
private int[] GetCustomColors() { var colors = new List <int>(); foreach (Map.Polygon p in subjMap.Polygons) { int color = ColorTranslator.ToOle(p.AmbientLightColor); if (!colors.Contains(color)) { colors.Add(color); } } return(colors.ToArray()); }
private void picBx_Colour_Click(object sender, EventArgs e) { using (ColorDialog cd = new ColorDialog()) { cd.CustomColors = new int[2] { ColorTranslator.ToOle(Color.FromArgb(39, 40, 34)), ColorTranslator.ToOle(picBx_Colour.BackColor) }; cd.Color = picBx_Colour.BackColor; if (cd.ShowDialog() == DialogResult.OK) { picBx_Colour.BackColor = cd.Color; SettingsChanged(stCurrent.BackColourChanged(cd.Color)); } } }
//色ボタン private void BtnColor_Click(object sender, EventArgs e) { using (var dialog = new ColorDialog() { Color = btnColor.BackColor, AllowFullOpen = true, CustomColors = FolderButton.SampleColors.Select(i => ColorTranslator.ToOle(i)).ToArray() }) { if (dialog.ShowDialog() == DialogResult.OK) { btnColor.BackColor = dialog.Color; } } }
static void Main() { string path = @"C:\My Documents\My Projects\Test\Excel\App_Data\W.xlsm"; var excel = (Application)Marshal.GetActiveObject("Excel.Application"); excel.Visible = false; Workbook workbook = excel.Workbooks.Open(path, Missing.Value, false, Missing.Value, Missing.Value, Missing.Value, true, Missing.Value, Missing.Value, true, Missing.Value, Missing.Value, Missing.Value); workbook.RefreshAll(); workbook.Worksheets["Legal Obligation Register"].Range("E11", "W171").Cells.Borders.Color = ColorTranslator.ToOle(Color.Black); workbook.Worksheets["Tools"].Range("A6", "F581").Cells.Borders.Color = ColorTranslator.ToOle(Color.Black); workbook.Save(); workbook.Close(true); excel.Quit(); }
public static int writeDataToExcel(Dictionary <String, Beam> data, Excel.Worksheet sheet, int startRow) { int rowindex = startRow; foreach (string key in data.Keys) { Excel.Range formatRange = sheet.Range["a" + rowindex.ToString(), "c" + rowindex.ToString()]; formatRange.Interior.Color = ColorTranslator.ToOle(Color.YellowGreen); sheet.Cells[rowindex, 1] = data[key].name; sheet.Cells[rowindex, 2] = "Quantity"; sheet.Cells[rowindex, 3] = "Unit"; rowindex++; sheet.Cells[rowindex, 1] = "Material"; sheet.Cells[rowindex, 2] = data[key].material; sheet.Cells[rowindex, 3] = "Concrete"; rowindex++; sheet.Cells[rowindex, 1] = "Gross Volume"; sheet.Cells[rowindex, 2] = data[key].volumeGross; sheet.Cells[rowindex, 3] = "Cubic Yard"; rowindex++; sheet.Cells[rowindex, 1] = "Length"; sheet.Cells[rowindex, 2] = data[key].length; sheet.Cells[rowindex, 3] = "Foot"; rowindex++; sheet.Cells[rowindex, 1] = "Bottom Area"; sheet.Cells[rowindex, 2] = data[key].areaBott; sheet.Cells[rowindex, 3] = "Square Foot"; rowindex++; sheet.Cells[rowindex, 1] = "Side Area"; sheet.Cells[rowindex, 2] = data[key].areaSide; sheet.Cells[rowindex, 3] = "Square Foot"; rowindex++; sheet.Cells[rowindex, 1] = "Quantity"; sheet.Cells[rowindex, 2] = data[key].quantity; sheet.Cells[rowindex, 3] = ""; rowindex++; } startRow = rowindex; return(startRow); }
private void btnColourPicker_Click(object sender, EventArgs e) { clrDialog.CustomColors = new[] { ColorTranslator.ToOle(ColorUtils.HexToColor(ShortcutConstantsAndEnums.DefaultAccentColor)) }; clrDialog.Color = cmbColour.Text.ToLower() == @"custom" ? ColorUtils.HexToColor(txtBGColour.Text) : Color.FromName(cmbColour.Text); if (clrDialog.ShowDialog(this) == DialogResult.OK) { txtBGColour.Text = ColorUtils.ColorToHex(clrDialog.Color); } }
private void ShowDTWInExcel(float[,] table, List <int[]> path) { Microsoft.Office.Interop.Excel.Application app; Microsoft.Office.Interop.Excel._Workbook wb; Microsoft.Office.Interop.Excel._Worksheet ws; Microsoft.Office.Interop.Excel.Range wr; app = new Microsoft.Office.Interop.Excel.Application(); app.Visible = true; app.DisplayAlerts = false; app.Workbooks.Add(Type.Missing); wb = app.Workbooks[1]; wb.Activate(); try { // 引用第一個工作表 ws = (Microsoft.Office.Interop.Excel._Worksheet)wb.Worksheets[1]; // 命名工作表的名稱 ws.Name = "工作表測試"; // 設定工作表焦點 ws.Activate(); for (int i = 0; i < table.GetLength(0); i++) { for (int j = 0; j < table.GetLength(1); j++) { if (table[i, j] == float.PositiveInfinity) { app.Cells[i + 2, j + 2] = "PositiveInfinity"; } else { app.Cells[i + 2, j + 2] = table[i, j]; } } } foreach (int[] p in path) { wr = ws.Range[ws.Cells[p[0] + 2, p[1] + 2], ws.Cells[p[0] + 2, p[1] + 2]]; wr.Select(); wr.Interior.Color = ColorTranslator.ToOle(Color.GreenYellow); } } catch (Exception ex) { Console.WriteLine("產生報表時出錯!" + Environment.NewLine + ex.Message); } }