2012-12-11 23 views
7

Öncelikle, sayfamın renk sınırlarını beyaz olarak değiştirdim, çünkü beyaz bir sayfa oluşturmak istiyorum. Sonra bazı başlıklar yaptım ve etrafta sınır yapmak istiyorum. Sorun, başlıktaki değerler arasında üst sınırlar oluşturuyor, ancak yukarıdan aşağıya doğru görülmemektedir.Excel'de Kenarlık Değiştirme sol, sağ, alt ve üst

Kodum:

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

kullanımı 'BorderAround' olan Bx gelen Mx için Hücreler sürekli bir hat oluşturmak için

Örnek? –

+0

@K_B: Ben denedim ama sonuç aynıdır –

+0

Kodun ilk satırında, hücrelerin rengini beyaza çevirmiyorsun, ama sınırların ... –

cevap

10

Tamam

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

Bu da kullanılarak yapılabilir tek bir satır xlWorkSheet5.Cells [7,1] .Borders.Weight = 1d; – Wayne

4

sonra çizgisinde bir şey kullanın Sınırlar [index] özelliğini kullanmak istiyorsanız:

Burada, bunu yapmak için bir çözüm buldu
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 mülkiyet

: my kodudur

XlBorderWeight bu XlBorderWeight sabitlerinden biri olabilir: xlHairline xlThin xlMedium xlThick. X hattı sayısı 'BorderAround2` bölgesinin yerine

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; 
İlgili konular