Пример #1
0
        //[Obsolete]
        //public static void SetBorderLeft(NPOI.SS.UserModel.CellBorderType border, Region region, HSSFSheet sheet,
        //        HSSFWorkbook workbook)
        //{
        //    SetBorderLeft(border, toCRA(region), sheet, workbook);
        //}
        /// <summary>
        /// Sets the left border for a region of cells by manipulating the cell style
        /// of the individual cells on the left
        /// </summary>
        /// <param name="border">The new border</param>
        /// <param name="region">The region that should have the border</param>
        /// <param name="sheet">The sheet that the region is on.</param>
        /// <param name="workbook">The workbook that the region is on.</param>
        public static void SetBorderLeft(NPOI.SS.UserModel.BorderStyle border, CellRangeAddress region, HSSFSheet sheet,
                                         HSSFWorkbook workbook)
        {
            int rowStart = region.FirstRow;
            int rowEnd   = region.LastRow;
            int column   = region.FirstColumn;

            CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.BORDER_LEFT, (int)border);

            for (int i = rowStart; i <= rowEnd; i++)
            {
                cps.SetProperty(HSSFCellUtil.GetRow(i, sheet), column);
            }
        }
Пример #2
0
        //[Obsolete]
        //public static void SetBorderTop(NPOI.SS.UserModel.CellBorderType border, Region region, HSSFSheet sheet,
        //        HSSFWorkbook workbook)
        //{
        //    SetBorderTop(border, toCRA(region), sheet, workbook);
        //}
        /// <summary>
        /// Sets the borderBottom attribute of the HSSFRegionUtil object
        /// </summary>
        /// <param name="border">The new border</param>
        /// <param name="region">The region that should have the border</param>
        /// <param name="sheet">The sheet that the region is on.</param>
        /// <param name="workbook">The workbook that the region is on.</param>
        public static void SetBorderTop(NPOI.SS.UserModel.BorderStyle border, CellRangeAddress region, HSSFSheet sheet,
                                        HSSFWorkbook workbook)
        {
            int colStart           = region.FirstColumn;
            int colEnd             = region.LastColumn;
            int rowIndex           = region.FirstRow;
            CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.BORDER_TOP, (int)border);

            NPOI.SS.UserModel.IRow row = HSSFCellUtil.GetRow(rowIndex, sheet);
            for (int i = colStart; i <= colEnd; i++)
            {
                cps.SetProperty(row, i);
            }
        }
Пример #3
0
 public static NPOI.SS.UserModel.ICellStyle GetCellStyle(this NPOI.SS.UserModel.IWorkbook workbook, short backColorIndex, short fontColorIndex, System.Drawing.Font font, NPOI.SS.UserModel.HorizontalAlignment horizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment.General, NPOI.SS.UserModel.VerticalAlignment verticalAlignment = NPOI.SS.UserModel.VerticalAlignment.None, NPOI.SS.UserModel.BorderStyle borderLeft = NPOI.SS.UserModel.BorderStyle.None, NPOI.SS.UserModel.BorderStyle borderTop = NPOI.SS.UserModel.BorderStyle.None, NPOI.SS.UserModel.BorderStyle borderRight = NPOI.SS.UserModel.BorderStyle.None, NPOI.SS.UserModel.BorderStyle borderBottom = NPOI.SS.UserModel.BorderStyle.None)
 {
     NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
     if (backColorIndex >= 8 && backColorIndex <= 63)
     {
         cellStyle.FillPattern         = NPOI.SS.UserModel.FillPattern.SolidForeground;
         cellStyle.FillForegroundColor = backColorIndex;
     }
     cellStyle.Alignment         = horizontalAlignment;
     cellStyle.VerticalAlignment = verticalAlignment;
     cellStyle.BorderLeft        = borderLeft;
     cellStyle.BorderTop         = borderTop;
     cellStyle.BorderRight       = borderRight;
     cellStyle.BorderBottom      = borderBottom;
     if (font != null)
     {
         NPOI.SS.UserModel.IFont cellFont = workbook.CreateFont();
         if (fontColorIndex >= 8 && fontColorIndex <= 63)
         {
             cellFont.Color = fontColorIndex;
         }
         cellFont.FontName   = font.Name;
         cellFont.FontHeight = font.Size;
         cellFont.Boldweight = (short)(font.Bold ? NPOI.SS.UserModel.FontBoldWeight.Bold : NPOI.SS.UserModel.FontBoldWeight.Normal);
         cellStyle.SetFont(cellFont);
     }
     return(cellStyle);
 }