2012-12-11 20 views
7

まず、シートの色の境界を白に変更しました。白いシートが必要です。それから私はいくつかのヘッダーを作って、その周りに境界線を作りたいと思っています。問題は、ヘッダーの値の間に境界が作られますが、上、下は見えません。Excelの枠線を左右、上下に変更する

マイコード:

xlWorkSheet5.Columns.Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White); // Color Sheet5 to white, BusLoad 
xlWorkSheet5.Columns.NumberFormat = "@"; 
Excel.Range rng = (Excel.Range)xlWorkSheet5.get_Range("A7","J7"); 
rng.RowHeight = 25.5; 
rng.BorderAround2(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic); 
rng.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; 
rng.Borders.Weight = 1d; 
rng.Font.Bold = true; 
rng.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; 
rng.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGray); 
+0

の数であるBxをからのMxに対する細胞上の連続線を作成するための

例、BorderAround2' 'の代わりに' BorderAround'を使用しますか? –

+0

@ K_B:私は試しましたが、結果は同じです –

+0

最初のコード行では、セルの色を白に変更するのではなく、境界線の色を変更しません。 –

答えて

10

OKを私はここに、それを行うための解決策を見つけました私のコードは次のとおりです。

xlWorkSheet5.Cells[7,1].Borders[Excel.XlBordersIndex.xlEdgeLeft].Weight = 1d; 
xlWorkSheet5.Cells[7, 1].Borders[Excel.XlBordersIndex.xlEdgeRight].Weight = 1d; 
xlWorkSheet5.Cells[7,1].Borders[Excel.XlBordersIndex.xlEdgeTop].Weight = 1d; 
xlWorkSheet5.Cells[7,1].Borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = 1d; 
+2

これは1行のコード 'xlWorkSheet5.Cells [7,1] .Borders.Weight = 1d;' – Wayne

4

あなたが国境[インデックス]プロパティを使用したい場合は、その後の線に沿って何かを使用します。

rng.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = XlLineStyle.xlContinuous; 
rng.Borders[XlBordersIndex.xlEdgeLeft].ColorIndex = <COLOR THAT YOU WANT> 

rng.Borders[XlBordersIndex.xlEdgeTop]... 
rng.Borders[XlBordersIndex.xlEdgeBottom]... 
rng.Borders[XlBordersIndex.xlEdgeRight]... 
1

Border.Weightプロパティ

XlBorderWeightは、次のXlBorderWeight定数のいずれかです。xlHairline xlThin xlMedium xlThick。 xがライン

using Excel = Microsoft.Office.Interop.Excel; 

Excel.Range line = (Excel.Range)excelWorksheet.Rows[1]; 
line.Insert(); 

excelWorksheet.Range[$"B{1}:M{1}"].Cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous; 
excelWorksheet.Range[$"B{1}:M{1}"].Cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlThin; 
関連する問題