タグ別アーカイブ: 罫線を引く

C#でEXCEL操作する 罫線を引くには

//罫線を引くための型を宣言
Excel.Borders borders;
Excel.Border border;

//セルの範囲設定
range1 = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[10 1];
range2 = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[10 14];
range = xlSheet.get_Range(range1, range2);

//罫線設定
borders = range.Borders;

//左に罫線を引く
border = borders[Excel.XlBordersIndex.xlEdgeLeft];
border.LineStyle = Excel.XlLineStyle.xlContinuous;

//右に罫線を引く
border = borders[Excel.XlBordersIndex.xlEdgeRight];
border.LineStyle = Excel.XlLineStyle.xlContinuous;

//上に罫線を引く
border = borders[Excel.XlBordersIndex.xlEdgeTop];
border.LineStyle = Excel.XlLineStyle.xlContinuous;

//下に罫線を引く
border = borders[Excel.XlBordersIndex.xlEdgeBottom];
border.LineStyle = Excel.XlLineStyle.xlContinuous;