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"))
{
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(XlBordersIndex.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;
}
}
}
}
新闻热点
疑难解答