代码之家  ›  专栏  ›  技术社区  ›  A G

excel range.borderaround(),边框始终为黑色

  •  21
  • A G  · 技术社区  · 15 年前

    这是我使用的代码:

    rngData.BorderAround(Excel.XlLineStyle.xlContinuous,
            Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin,
            Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexNone,
            System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(178, 178, 178)));
    

    无论我提供什么RGB值,边框颜色始终为黑色。

    6 回复  |  直到 7 年前
        1
  •  56
  •   Wad    14 年前

        private void BorderAround(Excel.Range range, int colour)
        {
            Excel.Borders borders = range.Borders;
            borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous;
            borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous;
            borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous;
            borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;
            borders.Color = colour;
            borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlLineStyleNone;
            borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.XlLineStyle.xlLineStyleNone;
            borders[Excel.XlBordersIndex.xlDiagonalUp].LineStyle = Excel.XlLineStyle.xlLineStyleNone;
            borders[Excel.XlBordersIndex.xlDiagonalDown].LineStyle = Excel.XlLineStyle.xlLineStyleNone;
            borders = null;
        }
    

    BorderAround(Contents_Table.Cells, System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(79, 129, 189)));
    

        2
  •  8
  •   Barry Kaye    14 年前

    range.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
    range.Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(153, 153, 153));
    
        3
  •  5
  •   jamesmortensen Arjan    13 年前
    worksheet.Cells[8, i].Borders.Color = 
        System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); 
    
        4
  •  2
  •   JAIRO    13 年前
    .Range("H1:J1").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium, color:=RGB(130, 130, 130)
    
        5
  •  2
  •   Sharique Hussain Ansari    12 年前
    range.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
    
    range.Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Red);
    
        6
  •  0
  •   Sparrow    7 年前

    Color:=RGB(255, 0, 0)

    ColorIndex:=3

    [ColorIndex:=3] [Color:=RGB(255, 0, 0)] [colorindex:=xlColorIndeAutomatic] [xlColorIndexNone]