23

これは私が使用しているコードです:

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値に関係なく、境界線の色は常に黒です。

4

6 に答える 6

58

私は同じ問題を抱えていましたが、ウェブ上で解決策を見つけることができませんでした。VSTOでこのメソッドを使用するためのMSドキュメントは少し貧弱です。

とにかく、数か月前に投稿したので、おそらく少し遅れますが、私の回避策は、Range.BorderAroundメソッドを使用せず、独自のメソッドを作成することでした。

    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;
    }

以下の例のように呼び出すことができます(Contents_Tableは私のワークシートのNamedRangeです):

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

これが他の誰かが自分の髪を引き裂くのに役立つことを願っています。

于 2010-06-23T10:37:13.310 に答える
8

または、内側の線と対角線を確実に削除する必要がない場合は、次のように使用しました。

range.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
range.Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(153, 153, 153));
于 2011-01-04T17:21:36.197 に答える
5
worksheet.Cells[8, i].Borders.Color = 
    System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); 
于 2012-04-07T19:12:25.293 に答える
3
.Range("H1:J1").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium, color:=RGB(130, 130, 130)
于 2010-08-19T16:52:41.747 に答える
1
range.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;

range.Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Red);
于 2013-01-11T10:42:18.327 に答える
-1

境界線の色を変更するには、次のいずれかを使用する必要があります

Color:=RGB(255, 0, 0)

興味のあるRGBコードを使用するか ColorIndex:=3、たとえば、赤色を取得します。

両方を使用する場合は、[ColorIndex:=3]オーバーライドします[Color:=RGB(255, 0, 0)]-それぞれに異なる色を設定しようとしたときに表示されるアクション、またはを使用し たり、を使用し[colorindex:=xlColorIndeAutomatic]たりし[xlColorIndexNone]ます。

Excelの数式とは異なり、VBAでは、VBAのインテリセンスによって提案されているため、パラメーターをスキップできます。

于 2018-01-25T22:02:49.050 に答える