Exemplo n.º 1
0
        /*private void DrawBorders(TableCellBorder borders)
         * {
         *  var style = Style;
         *  style.Borders = borders;
         *  SetStyle(style);
         * }*/

        public void AddCell(int colSpan = 0, int rowSpan = 0)
        {
            if (CurrentRow == null)
            {
                AddRow();                     //CurrentRow = Sheet.CreateRow(CurrentRowIndex);
            }
            CurrentColIndex = NextColIndex++;
            CurrentCell     = CurrentRow.GetCell(CurrentColIndex) ?? CurrentRow.CreateCell(CurrentColIndex);
            var regionColIndex = CurrentColIndex + (colSpan > 1 ? colSpan - 1 : 0);
            var regionRowIndex = CurrentRowIndex + (rowSpan > 1 ? rowSpan - 1 : 0);

            CellRangeAddress region = null;

            if (colSpan > 1 || rowSpan > 1)
            {
                region = new CellRangeAddress(CurrentRowIndex, regionRowIndex, CurrentColIndex, regionColIndex);
                Sheet.AddMergedRegion(region);

                if (colSpan > 1)
                {
                    NextColIndex += colSpan - 1;
                }
                if (rowSpan > 1)
                {
                    NextRowIndex = Math.Max(NextRowIndex, regionRowIndex + 1);
                }
            }
            // Style the cell with borders all around.
//            if (Style.HasValues()/* || ((int)Borders) != 0*/)
//                (BorderTop ?? false) || (BorderLeft ?? false) || (BorderRight ?? false) || (BorderBottom ?? false))
            {
                //var style = Workbook.CreateCellStyle();
                var style = GetStyle(Style);

                if (style == null)
                {
                    style = region == null?CreateCellStyle(CurrentCell) : CreateCellStyle(region);

                    SetStyle(style, Style);
                }

                if (region == null)
                {
                    SetCellStyle(CurrentCell, style);
                }
                else
                {
                    SetCellStyle(region, style);
                }

/*
 *              if (Borders.HasFlag(TableCellBorder.Top)/* ?? false♥1♥)
 *              {
 *                  style.BorderTop = CellBorderType.THIN;
 *                  style.TopBorderColor = HSSFColor.BLACK.index;
 *              }
 *              if (Borders.HasFlag(TableCellBorder.Left))
 *              {
 *                  style.BorderLeft = CellBorderType.THIN;
 *                  style.LeftBorderColor = HSSFColor.BLACK.index;
 *              }
 *              if (Borders.HasFlag(TableCellBorder.Right))
 *              {
 *                  style.BorderRight = CellBorderType.THIN;
 *                  style.RightBorderColor = HSSFColor.BLACK.index;
 *              }
 *              if (Borders.HasFlag(TableCellBorder.Bottom))
 *              {
 *                  style.BorderBottom = CellBorderType.THIN;
 *                  style.BottomBorderColor = HSSFColor.BLACK.index;
 *              }
 */
//                style.WrapText = WrapText;
//                style.ShrinkToFit = ShrinkToFit;

                /*if (region == null)
                 *  CurrentCell.CellStyle = style;
                 * else
                 * {
                 *  for (int iRow = region.FirstRow; iRow <= region.LastRow; iRow++)
                 *  {
                 *      var row = Sheet.GetRow(iRow) ?? Sheet.CreateRow(iRow);
                 *      for (int iCol = region.FirstColumn; iCol <= region.LastColumn; iCol++)
                 *      {
                 *          var cell = row.GetCell(iCol) ?? row.CreateCell(iCol);
                 *          if (cell != null) cell.CellStyle = style;
                 *      }
                 *  }
                 * }*/
            }
        }