code: public static synchronized short getNearestColor(
              final Color awtColor) {
          if (triplets == null) {
              triplets = HSSFColor.getTripletHash();
          }
  
          if (triplets == null || triplets.isEmpty()) {
              System.out.println("Unable to get triplet hashtable");
              return HSSFColor.BLACK.index;
          }
  
          short color = HSSFColor.BLACK.index;
          double minDiff = Double.MAX_VALUE;
  
          // get the color without the alpha chanel
          final float[] hsb = Color.RGBtoHSB(awtColor.getRed(), awtColor
                  .getGreen(), awtColor.getBlue(), null);
  
          float[] excelHsb = null;
          final Iterator elements = triplets.values().iterator();
          while (elements.hasNext()) {
              final HSSFColor crtColor = (HSSFColor) elements.next();
              final short[] rgb = crtColor.getTriplet();
              excelHsb = Color.RGBtoHSB(rgb[0], rgb[1], rgb[2], excelHsb);
  
              final double weight = 3.0d * Math.abs(excelHsb[0] - hsb[0])
                      + Math.abs(excelHsb[1] - hsb[1])
                      + Math.abs(excelHsb[2] - hsb[2]);
  
              if (weight < minDiff) {
                  minDiff = weight;
                  if (minDiff == 0) {
                      // we found the color ...
                      return crtColor.getIndex();
                  }
                  color = crtColor.getIndex();
              }
          }
          return color;
      }
docs: Find a suitable color for the cell.
  <p/>
  The algorithm searches all available triplets, weighted by tripletvalue and
  tripletdifference to the other triplets. The color wins, which has the
  smallest triplet difference and where all triplets are nearest to the
  requested color.
  
  @param awtColor the awt color that should be transformed into an Excel color.
  @return the excel color index that is nearest to the supplied color.