예제 #1
0
파일: HSSFFont.cs 프로젝트: hemingfei/npoi
        /// <summary>
        /// get the color value for the font
        /// </summary>
        /// <param name="wb">HSSFWorkbook</param>
        /// <returns></returns>
        public HSSFColor GetHSSFColor(HSSFWorkbook wb)
        {
            HSSFPalette pallette = wb.GetCustomPalette();

            return(pallette.GetColor(Color));
        }
예제 #2
0
 public void SetUp()
 {
     palette = new PaletteRecord();
     hssfPalette = new HSSFPalette(palette);
 }
예제 #3
0
        private Int16 GetColorIndex(String htmlColor)
        {
            Int16 colorId = 0;

            try
            {
                if (htmlColor.Length > 0)
                {
                    // Instantiate _customColors if required
                    if (_customColors == null)
                    {
                        _customColors = new Dictionary<String, Int16>();
                        colorId = (Int16)((Workbook.Excel.IsOldExcel(Workbook.Excel.FileName)) ? 17 : 65);
                    }

                    // Get existing color index
                    if (_customColors.ContainsKey(htmlColor))
                    {
                        _customColors.TryGetValue(htmlColor, out colorId);
                    }
                    else
                    {
                        if (_customColors.Values.Count > 0)
                        {
                            Int16 maxId = _customColors.Values.Max();
                            colorId = (maxId += 1);
                        }

                        if (Workbook.Excel.IsOldExcel(Workbook.Excel.FileName))
                        {
                            // Assign Color to OLD Excel palette     

                            if (_customPalette == null)
                            {
                                _customPalette = ((HSSFWorkbook)_wb).GetCustomPalette();
                            }

                            Color color = ColorTranslator.FromHtml(htmlColor);
                            _customPalette.SetColorAtIndex(colorId, (byte)color.R, (byte)color.G, (byte)color.B);
                        }
                        else
                        {
                            colorId = 0;
                        }

                        _customColors.Add(htmlColor, colorId);
                    }
                }
            }
            catch (Exception xcp)
            {
                Logger.Log(xcp, EventLogEntryType.Error);
                throw new ExcelException("NPOIWorksheet GetColorIndex Exception", xcp);
            }

            return colorId;
        }