private _Workbook _workBook = null;
private Worksheet _workSheet = null;
private Worksheet _workSheet2 = null;
private Excel.Application _ExcelApplicatin = null;
private Excel.Chart _ExcelChart = null;
_excelApplicatin = new Excel.Application();
_ExcelApplicatin.Visible = true;
_ExcelApplicatin.DisplayAlerts = true;
_workBook = _ExcelApplicatin.Workbooks.Add(XlSheetType.xlWorksheet);
_workSheet = (Worksheet)_workBook.ActiveSheet;
_workSheet.Name = "多數邊框線為實線";
Excel.Range ExcelRange = _workSheet.get_Range(_workSheet.Cells[2, 2], _workSheet.Cells[6, 6]);
ExcelBorderLineStlye(ExcelRange,"Up","Bottom"," Left" "Right");
//excelRange :Excel選中范圍的邊框線型設置 因為多數邊框線為實線
//NO :表示邊框沒有; "Up Bottom Left Right":表示線型為粗線 ;" "" "表示線型細線
private void ExcelBorderLineStlye(Range ExcelRange, string Up, string Bottom, string Left, string Right)
{
List<string> borderWeightDivision = new List<string>();
borderWeightDivision.Add(Up);
borderWeightDivision.Add(Bottom);
borderWeightDivision.Add(Left);
borderWeightDivision.Add(Right);
for (int i = 0; i < borderWeightDivision.Count; i++)
{
if (borderWeightDivision[i].Length > 0)
{
if (!borderWeightDivision[i].Equals("NO"))
{
&nb
sp; switch (i)
{
//Top
case 0:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeTop).Weight = XlBorderWeight.xlMedium;
break;
//Bottom
case 1:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeBottom).Weight = XlBorderWeight.xlMedium;
break;
//"Left"
case 2:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeLeft).Weight = XlBorderWeight.xlMedium;
break;
//"Right"
case 3:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeRight).Weight = XlBorderWeight.xlMedium;
break;
}
}
else
{
switch (i)
{
//Top
case 0:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeTop).LineStyle = XlLineStyle.xlLineStyleNone;
break;
//Bottom
case 1:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeBottom).LineStyle = XlLineStyle.xlLineStyleNone;
; break;
//"Left"
case 2:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeLeft).LineStyle = XlLineStyle.xlLineStyleNone;
break;
//"Right"
case 3:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeRight).LineStyle = XlLineStyle .xlLineStyleNone;
break;
}
}
}
else
{
switch (i)
{
//Top
case 0:
ExcelRange.Borders.get_Item(XlBordersI
ndex.xlEdgeTop).Weight = XlBorderWeight.xlThin;
break;
//Bottom
case 1:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeBottom).Weight = XlBorderWeight.xlThin;
break;
//"Left"
case 2:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeLeft).Weight = XlBorderWeight.xlThin;
break;
//"Right"
case 3:
ExcelRange.Borders.get_Item(XlBordersIndex.xlEdgeRight).Weight = XlBorderWeight.xlThin;
break;
}
}
}
}