Exemplo n.º 1
0
        void BuildStyle_Font(HSSFWorkbook workbook, StringBuilder style,
                             HSSFFont font)
        {
            switch (font.Boldweight)
            {
            case (short)FontBoldWeight.BOLD:
                style.Append("font-weight: bold; ");
                break;

            case (short)FontBoldWeight.NORMAL:
                // by default, not not increase HTML size
                // style.Append( "font-weight: normal; " );
                break;
            }

            HSSFColor fontColor = workbook.GetCustomPalette().GetColor(font.Color);

            if (fontColor != null)
            {
                style.Append("color: " + ExcelToHtmlUtils.GetColor(fontColor) + "; ");
            }

            if (font.FontHeightInPoints != 0)
            {
                style.Append("font-size: " + font.FontHeightInPoints + "pt; ");
            }

            if (font.IsItalic)
            {
                style.Append("font-style: italic; ");
            }
        }
Exemplo n.º 2
0
        protected String BuildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle)
        {
            StringBuilder style   = new StringBuilder();
            HSSFPalette   palette = workbook.GetCustomPalette();

            style.Append("white-space: pre-wrap; ");
            ExcelToHtmlUtils.AppendAlign(style, cellStyle.Alignment);

            if (cellStyle.FillPattern == FillPatternType.NO_FILL)
            {
                // no fill
            }
            else if (cellStyle.FillPattern == FillPatternType.SOLID_FOREGROUND)
            {
                //cellStyle.
                //HSSFColor.
                HSSFColor foregroundColor = palette.GetColor(cellStyle.FillForegroundColor);
                if (foregroundColor != null)
                {
                    style.Append("background-color: " + ExcelToHtmlUtils.GetColor(foregroundColor) + "; ");
                }
            }
            else
            {
                HSSFColor backgroundColor = palette.GetColor(cellStyle.FillBackgroundColor);
                if (backgroundColor != null)
                {
                    style.Append("background-color: " + ExcelToHtmlUtils.GetColor(backgroundColor) + "; ");
                }
            }

            BuildStyle_Border(workbook, style, "top", cellStyle.BorderTop, cellStyle.TopBorderColor);
            BuildStyle_Border(workbook, style, "right", cellStyle.BorderRight, cellStyle.RightBorderColor);
            BuildStyle_Border(workbook, style, "bottom", cellStyle.BorderBottom, cellStyle.BottomBorderColor);
            BuildStyle_Border(workbook, style, "left", cellStyle.BorderLeft, cellStyle.LeftBorderColor);

            HSSFFont font = cellStyle.GetFont(workbook) as HSSFFont;

            BuildStyle_Font(workbook, style, font);

            return(style.ToString());
        }
Exemplo n.º 3
0
        private void BuildStyle_Border(HSSFWorkbook workbook, StringBuilder style,
                                       String type, BorderStyle xlsBorder, short borderColor)
        {
            if (xlsBorder == BorderStyle.NONE)
            {
                return;
            }

            StringBuilder borderStyle = new StringBuilder();

            borderStyle.Append(ExcelToHtmlUtils.GetBorderWidth(xlsBorder));
            borderStyle.Append(' ');
            borderStyle.Append(ExcelToHtmlUtils.GetBorderStyle(xlsBorder));

            HSSFColor color = workbook.GetCustomPalette().GetColor(borderColor);

            if (color != null)
            {
                borderStyle.Append(' ');
                borderStyle.Append(ExcelToHtmlUtils.GetColor(color));
            }

            style.Append("border-" + type + ": " + borderStyle + "; ");
        }