示例#1
0
 public IFont GetFont(CellStyle cellStyle)
 {
     return GetFont(
       cellStyle.Bold,
       cellStyle.Italic,
       cellStyle.Underlined,
       cellStyle.FontColor,
       cellStyle.FontSize,
       cellStyle.FontName.ToString()
       );
 }
示例#2
0
        public void ApplyStyle(int col, CellStyle cellStyle)
        {
            ICell xlCell = xlRow.GetCell(col, MissingCellPolicy.CREATE_NULL_AS_BLANK);
              ICellStyle xlStyle = styleCache.GetGeneralStyle();

              string customFormatting = cellStyle.CustomFormatting;
              if (customFormatting != null) {
            // check if this is a built-in format
            short builtinFormatId = HSSFDataFormat.GetBuiltinFormat(customFormatting);

            if (builtinFormatId != -1) {
              xlStyle.DataFormat = builtinFormatId;
            } else {
              // not a built-in format, so create a new one
              IDataFormat newDataFormat = xlWorkbook.CreateDataFormat();
              xlStyle.DataFormat = newDataFormat.GetFormat(cellStyle.CustomFormatting);
            }
              }

              IFont font = fontCache.GetFont(cellStyle);

              if (cellStyle.BackgroundColor != Color.Empty) {
            xlStyle.FillForegroundColor = Util.GetXLColor((HSSFWorkbook)xlWorkbook, cellStyle.BackgroundColor);
            xlStyle.FillPattern = FillPatternType.SOLID_FOREGROUND;
              }

              switch (cellStyle.Alignment) {
            case CellStyle.Alignments.LEFT: xlStyle.Alignment = HorizontalAlignment.LEFT; break;
            case CellStyle.Alignments.CENTER: xlStyle.Alignment = HorizontalAlignment.CENTER; break;
            case CellStyle.Alignments.RIGHT: xlStyle.Alignment = HorizontalAlignment.RIGHT; break;
            case CellStyle.Alignments.JUSTIFY: xlStyle.Alignment = HorizontalAlignment.JUSTIFY; break;
              }

              xlStyle.SetFont(font);
              styleCache.SetCellStyle(xlCell, xlStyle);
        }
示例#3
0
 public void ApplyFormatting(int col, CellStyle cellStyle)
 {
     wrapper.ApplyStyle(col - 1, cellStyle);
 }
示例#4
0
 /// <summary>
 /// Write the percentage value into the cell at the given column and current row.
 /// The previous value is overwritten. The cell if formatted as Percentage
 /// </summary>
 /// <param name="col">The column of the cell to write the value in. 1 based index.</param>
 /// <param name="value">The percentage value to write into this cell</param>
 public void WritePercentage(int col, double value)
 {
     wrapper.WriteNumber(col - 1, (double)value / 100);
       CellStyle cellStyle = new CellStyle();
       cellStyle.CustomFormatting = "0%";
       wrapper.ApplyStyle(col - 1, cellStyle);
 }