1818import jxl .format .Alignment ;
1919import org .apache .commons .lang3 .StringUtils ;
2020import org .apache .poi .ss .usermodel .BorderStyle ;
21+ import org .apache .poi .ss .usermodel .CellPropertyType ;
2122import org .apache .poi .ss .usermodel .CellStyle ;
2223import org .apache .poi .ss .usermodel .Color ;
2324import org .apache .poi .ss .usermodel .FillPatternType ;
2425import org .apache .poi .ss .usermodel .Font ;
2526import org .apache .poi .ss .usermodel .HorizontalAlignment ;
2627import org .apache .poi .ss .usermodel .VerticalAlignment ;
2728
29+ import java .util .EnumMap ;
2830import java .util .HashMap ;
2931import java .util .Map ;
3032
31- /**
32- * User: klum
33- * Date: May 20, 2011
34- * Time: 1:45:20 PM
35- */
3633public class JxlCellStyle implements CellStyle
3734{
3835 private static final String DEFAULT_FORMAT = "General" ;
@@ -109,19 +106,14 @@ public boolean getLocked()
109106 return _format != null && _format .isLocked ();
110107 }
111108
112- private static final Map <Alignment , HorizontalAlignment > HORIZONTAL_ALIGNMENT_MAP = new HashMap <>();
113-
114- static
115- {
116- HORIZONTAL_ALIGNMENT_MAP .put (Alignment .GENERAL , HorizontalAlignment .GENERAL );
117- HORIZONTAL_ALIGNMENT_MAP .put (Alignment .LEFT , HorizontalAlignment .LEFT );
118- HORIZONTAL_ALIGNMENT_MAP .put (Alignment .CENTRE , HorizontalAlignment .CENTER );
119- HORIZONTAL_ALIGNMENT_MAP .put (Alignment .RIGHT , HorizontalAlignment .RIGHT );
120- HORIZONTAL_ALIGNMENT_MAP .put (Alignment .FILL , HorizontalAlignment .FILL );
121- HORIZONTAL_ALIGNMENT_MAP .put (Alignment .JUSTIFY , HorizontalAlignment .JUSTIFY );
122-
109+ private static final Map <Alignment , HorizontalAlignment > HORIZONTAL_ALIGNMENT_MAP = Map .of (
110+ Alignment .GENERAL , HorizontalAlignment .GENERAL ,
111+ Alignment .LEFT , HorizontalAlignment .LEFT ,
112+ Alignment .CENTRE , HorizontalAlignment .CENTER ,
113+ Alignment .RIGHT , HorizontalAlignment .RIGHT ,
114+ Alignment .FILL , HorizontalAlignment .FILL ,
115+ Alignment .JUSTIFY , HorizontalAlignment .JUSTIFY );
123116 // Note: No JXL options for CENTER_SELECTION or DISTRIBUTED
124- }
125117
126118 @ Override
127119 public HorizontalAlignment getAlignment ()
@@ -385,7 +377,7 @@ public boolean getQuotePrefixed()
385377 @ Override
386378 public int getFontIndexAsInt ()
387379 {
388- throw new UnsupportedOperationException ( "method not yet supported" );
380+ return getFontIndex ( );
389381 }
390382
391383 @ Override
@@ -399,4 +391,47 @@ public void setFillForegroundColor(Color color)
399391 {
400392 throw new UnsupportedOperationException ("method not yet supported" );
401393 }
394+
395+ /**
396+ * A pared down version of {@link org.apache.poi.ss.util.CellUtil#getFormatProperties(org.apache.poi.ss.usermodel.CellStyle)}
397+ * that only includes properties supported by this implementation.
398+ */
399+ @ Override
400+ public EnumMap <CellPropertyType , Object > getFormatProperties ()
401+ {
402+ EnumMap <CellPropertyType , Object > properties = new EnumMap <>(CellPropertyType .class );
403+ properties .put (CellPropertyType .ALIGNMENT , getAlignment ());
404+ properties .put (CellPropertyType .VERTICAL_ALIGNMENT , getVerticalAlignment ());
405+ //properties.put(CellPropertyType.BORDER_BOTTOM, getBorderBottom());
406+ //properties.put(CellPropertyType.BORDER_LEFT, getBorderLeft());
407+ //properties.put(CellPropertyType.BORDER_RIGHT, getBorderRight());
408+ //properties.put(CellPropertyType.BORDER_TOP, getBorderTop());
409+ properties .put (CellPropertyType .BOTTOM_BORDER_COLOR , getBottomBorderColor ());
410+ properties .put (CellPropertyType .DATA_FORMAT , getDataFormat ());
411+ properties .put (CellPropertyType .FILL_PATTERN , getFillPattern ());
412+
413+ //properties.put(CellPropertyType.FILL_FOREGROUND_COLOR, getFillForegroundColor());
414+ //properties.put(CellPropertyType.FILL_BACKGROUND_COLOR, getFillBackgroundColor());
415+ //properties.put(CellPropertyType.FILL_FOREGROUND_COLOR_COLOR, getFillForegroundColorColor());
416+ //properties.put(CellPropertyType.FILL_BACKGROUND_COLOR_COLOR, getFillBackgroundColorColor());
417+
418+ properties .put (CellPropertyType .FONT , getFontIndex ());
419+ properties .put (CellPropertyType .HIDDEN , getHidden ());
420+ properties .put (CellPropertyType .INDENTION , getIndention ());
421+ properties .put (CellPropertyType .LEFT_BORDER_COLOR , getLeftBorderColor ());
422+ properties .put (CellPropertyType .LOCKED , getLocked ());
423+ properties .put (CellPropertyType .RIGHT_BORDER_COLOR , getRightBorderColor ());
424+ //properties.put(CellPropertyType.ROTATION, getRotation());
425+ properties .put (CellPropertyType .TOP_BORDER_COLOR , getTopBorderColor ());
426+ properties .put (CellPropertyType .WRAP_TEXT , getWrapText ());
427+ //properties.put(CellPropertyType.SHRINK_TO_FIT, getShrinkToFit());
428+ //properties.put(CellPropertyType.QUOTE_PREFIXED, getQuotePrefixed());
429+ return properties ;
430+ }
431+
432+ @ Override
433+ public void invalidateCachedProperties ()
434+ {
435+ // Properties can't change in this implementation, nothing to invalidate
436+ }
402437}
0 commit comments