Example #1
0
        /// <summary>
        ///设置单元格背景色及填充方式
        /// </summary>
        /// <param name="startRow">开始行</param>
        /// <param name="startColumn">开始列</param>
        /// <param name="endRow">结束行</param>
        /// <param name="endColumn">结束列</param>
        /// <param name="color">颜色索引</param>
        /// <param name="pattern">填充方式</param>
        public void CellsBackColor(int startRow, int startColumn, int endRow, int endColumn, ExcelStyle.ColorIndex color, ExcelStyle.Pattern pattern)
        {
            Range range = MyExcel.get_Range(MyExcel.Cells[startRow, startColumn], MyExcel.Cells[endRow, endColumn]);

            range.Interior.ColorIndex = color;
            range.Interior.Pattern    = pattern;
        }
Example #2
0
        /// <summary>
        /// 设置字体颜色
        /// </summary>
        /// <param name="startRow">起始行</param>
        /// <param name="startColumn">起始列</param>
        /// <param name="endRow">结束行</param>
        /// <param name="endColumn">结束列</param>
        /// <param name="color">颜色索引</param>
        public void SetFontColor(int startRow, int startColumn, int endRow, int endColumn, ExcelStyle.ColorIndex color)
        {
            Range range = MyExcel.get_Range(MyExcel.Cells[startRow, startColumn], MyExcel.Cells[endRow, endColumn]);

            range.Font.ColorIndex = color;
        }
Example #3
0
        /// <summary>
        /// 绘制指定单元格的边框
        /// </summary>
        /// <param name="startRow">起始行</param>
        /// <param name="startColumn">起始列</param>
        /// <param name="endRow">结束行</param>
        /// <param name="endColumn">结束列</param>
        /// <param name="isDrawTop">是否画上外框</param>
        /// <param name="isDrawBottom">是否画下外框</param>
        /// <param name="isDrawLeft">是否画左外框</param>
        /// <param name="isDrawRight">是否画右外框</param>
        /// <param name="isDrawHInside">是否画水平内框</param>
        /// <param name="isDrawVInside">是否画垂直内框</param>
        /// <param name="isDrawDown">是否画斜向下线</param>
        /// <param name="isDrawUp">是否画斜向上线</param>
        /// <param name="lineStyle">线类型</param>
        /// <param name="borderWeight">线粗细</param>
        /// <param name="color">线颜色</param>

        public void DrawCellsFrame(int startRow, int startColumn, int endRow, int endColumn,
                                   bool isDrawTop, bool isDrawBottom, bool isDrawLeft, bool isDrawRight,
                                   bool isDrawHInside, bool isDrawVInside, bool isDrawDiagonalDown, bool isDrawDiagonalUp,
                                   ExcelStyle.LineStyle lineStyle, ExcelStyle.BorderWeight borderWeight, ExcelStyle.ColorIndex color)
        {
            //获取画边框的单元格
            Range range = MyExcel.get_Range(MyExcel.Cells[startRow, startColumn], MyExcel.Cells[endRow, endColumn]);

            //清除所有边框
            range.Borders[XlBordersIndex.xlEdgeTop].LineStyle          = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlEdgeBottom].LineStyle       = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlEdgeLeft].LineStyle         = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlEdgeRight].LineStyle        = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlInsideVertical].LineStyle   = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlDiagonalDown].LineStyle     = ExcelStyle.LineStyle.无;
            range.Borders[XlBordersIndex.xlDiagonalUp].LineStyle       = ExcelStyle.LineStyle.无;

            //以下是按参数画边框
            if (isDrawTop)
            {
                range.Borders[XlBordersIndex.xlEdgeTop].LineStyle  = lineStyle;
                range.Borders[XlBordersIndex.xlEdgeTop].Weight     = borderWeight;
                range.Borders[XlBordersIndex.xlEdgeTop].ColorIndex = color;
            }

            if (isDrawBottom)
            {
                range.Borders[XlBordersIndex.xlEdgeBottom].LineStyle  = lineStyle;
                range.Borders[XlBordersIndex.xlEdgeBottom].Weight     = borderWeight;
                range.Borders[XlBordersIndex.xlEdgeBottom].ColorIndex = color;
            }

            if (isDrawLeft)
            {
                range.Borders[XlBordersIndex.xlEdgeLeft].LineStyle  = lineStyle;
                range.Borders[XlBordersIndex.xlEdgeLeft].Weight     = borderWeight;
                range.Borders[XlBordersIndex.xlEdgeLeft].ColorIndex = color;
            }

            if (isDrawRight)
            {
                range.Borders[XlBordersIndex.xlEdgeRight].LineStyle  = lineStyle;
                range.Borders[XlBordersIndex.xlEdgeRight].Weight     = borderWeight;
                range.Borders[XlBordersIndex.xlEdgeRight].ColorIndex = color;
            }

            if (isDrawVInside)
            {
                range.Borders[XlBordersIndex.xlInsideVertical].LineStyle  = lineStyle;
                range.Borders[XlBordersIndex.xlInsideVertical].Weight     = borderWeight;
                range.Borders[XlBordersIndex.xlInsideVertical].ColorIndex = color;
            }

            if (isDrawHInside)
            {
                range.Borders[XlBordersIndex.xlInsideHorizontal].LineStyle  = lineStyle;
                range.Borders[XlBordersIndex.xlInsideHorizontal].Weight     = borderWeight;
                range.Borders[XlBordersIndex.xlInsideHorizontal].ColorIndex = color;
            }

            if (isDrawDiagonalDown)
            {
                range.Borders[XlBordersIndex.xlDiagonalDown].LineStyle  = lineStyle;
                range.Borders[XlBordersIndex.xlDiagonalDown].Weight     = borderWeight;
                range.Borders[XlBordersIndex.xlDiagonalDown].ColorIndex = color;
            }

            if (isDrawDiagonalUp)
            {
                range.Borders[XlBordersIndex.xlDiagonalUp].LineStyle  = lineStyle;
                range.Borders[XlBordersIndex.xlDiagonalUp].Weight     = borderWeight;
                range.Borders[XlBordersIndex.xlDiagonalUp].ColorIndex = color;
            }
        }