zhuangjiaju
5 years ago
16 changed files with 659 additions and 379 deletions
@ -1,31 +0,0 @@
|
||||
package com.alibaba.excel.annotation.write.style; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Inherited; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
import org.apache.poi.ss.usermodel.IndexedColors; |
||||
|
||||
/** |
||||
* Convert number format. |
||||
* |
||||
* <li>write: It can be used on classes that inherit {@link Number} |
||||
* <li>read: It can be used on classes {@link String} |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
@Target({ElementType.FIELD, ElementType.TYPE}) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Inherited |
||||
public @interface ContentStyle { |
||||
|
||||
String fontName() default "宋体"; |
||||
|
||||
short fontHeightInPoints() default (short)14; |
||||
|
||||
boolean bold() default true; |
||||
|
||||
IndexedColors indexedColors() default IndexedColors.WHITE1; |
||||
} |
@ -1,27 +0,0 @@
|
||||
package com.alibaba.excel.annotation.write.style; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Inherited; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
import org.apache.poi.ss.usermodel.IndexedColors; |
||||
|
||||
/** |
||||
* 配置 |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
@Target({ElementType.FIELD, ElementType.TYPE}) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Inherited |
||||
public @interface HeadStyle { |
||||
String fontName() default "宋体"; |
||||
|
||||
short fontHeightInPoints() default (short)14; |
||||
|
||||
boolean bold() default true; |
||||
|
||||
IndexedColors indexedColors() default IndexedColors.GREY_25_PERCENT; |
||||
} |
@ -1,48 +0,0 @@
|
||||
package com.alibaba.excel.metadata; |
||||
|
||||
import org.apache.poi.ss.usermodel.IndexedColors; |
||||
|
||||
/** |
||||
* Simple cell style |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class CellStyle { |
||||
/** |
||||
* 表头背景颜色 |
||||
*/ |
||||
private IndexedColors indexedColors; |
||||
/** |
||||
* 表头字体样式 |
||||
*/ |
||||
private Font font; |
||||
|
||||
public CellStyle() { |
||||
|
||||
} |
||||
|
||||
public CellStyle(String fontName, Short fontHeightInPoints, Boolean bold, IndexedColors indexedColors) { |
||||
Font font = new Font(); |
||||
font.setFontName(fontName); |
||||
font.setFontHeightInPoints(fontHeightInPoints); |
||||
font.setBold(bold); |
||||
this.font = font; |
||||
this.indexedColors = indexedColors; |
||||
} |
||||
|
||||
public IndexedColors getIndexedColors() { |
||||
return indexedColors; |
||||
} |
||||
|
||||
public void setIndexedColors(IndexedColors indexedColors) { |
||||
this.indexedColors = indexedColors; |
||||
} |
||||
|
||||
public Font getFont() { |
||||
return font; |
||||
} |
||||
|
||||
public void setFont(Font font) { |
||||
this.font = font; |
||||
} |
||||
} |
@ -1,84 +0,0 @@
|
||||
package com.alibaba.excel.metadata.property; |
||||
|
||||
import org.apache.poi.ss.usermodel.IndexedColors; |
||||
|
||||
import com.alibaba.excel.annotation.write.style.ContentStyle; |
||||
import com.alibaba.excel.annotation.write.style.HeadStyle; |
||||
|
||||
/** |
||||
* Configuration from annotations |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class CellStyleProperty { |
||||
private String fontName; |
||||
private Short fontHeightInPoints; |
||||
private Boolean bold; |
||||
private IndexedColors indexedColors; |
||||
|
||||
public CellStyleProperty(String fontName, Short fontHeightInPoints, Boolean bold, IndexedColors indexedColors) { |
||||
this.fontName = fontName; |
||||
this.fontHeightInPoints = fontHeightInPoints; |
||||
this.bold = bold; |
||||
this.indexedColors = indexedColors; |
||||
} |
||||
|
||||
public static CellStyleProperty build(HeadStyle headStyle) { |
||||
if (headStyle == null) { |
||||
return null; |
||||
} |
||||
boolean isDefault = "宋体".equals(headStyle.fontName()) && headStyle.fontHeightInPoints() == 14 |
||||
&& headStyle.bold() && IndexedColors.GREY_25_PERCENT.equals(headStyle.indexedColors()); |
||||
if (isDefault) { |
||||
return null; |
||||
} |
||||
return new CellStyleProperty(headStyle.fontName(), headStyle.fontHeightInPoints(), headStyle.bold(), |
||||
headStyle.indexedColors()); |
||||
} |
||||
|
||||
public static CellStyleProperty build(ContentStyle contentStyle) { |
||||
if (contentStyle == null) { |
||||
return null; |
||||
} |
||||
boolean isDefault = "宋体".equals(contentStyle.fontName()) && contentStyle.fontHeightInPoints() == 14 |
||||
&& contentStyle.bold() && IndexedColors.WHITE1.equals(contentStyle.indexedColors()); |
||||
if (isDefault) { |
||||
return null; |
||||
} |
||||
return new CellStyleProperty(contentStyle.fontName(), contentStyle.fontHeightInPoints(), contentStyle.bold(), |
||||
contentStyle.indexedColors()); |
||||
} |
||||
|
||||
public String getFontName() { |
||||
return fontName; |
||||
} |
||||
|
||||
public void setFontName(String fontName) { |
||||
this.fontName = fontName; |
||||
} |
||||
|
||||
public Short getFontHeightInPoints() { |
||||
return fontHeightInPoints; |
||||
} |
||||
|
||||
public void setFontHeightInPoints(Short fontHeightInPoints) { |
||||
this.fontHeightInPoints = fontHeightInPoints; |
||||
} |
||||
|
||||
public Boolean getBold() { |
||||
return bold; |
||||
} |
||||
|
||||
public void setBold(Boolean bold) { |
||||
this.bold = bold; |
||||
} |
||||
|
||||
public IndexedColors getIndexedColors() { |
||||
return indexedColors; |
||||
} |
||||
|
||||
public void setIndexedColors(IndexedColors indexedColors) { |
||||
this.indexedColors = indexedColors; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,315 @@
|
||||
package com.alibaba.excel.write.metadata.style; |
||||
|
||||
import org.apache.poi.ss.usermodel.BorderStyle; |
||||
import org.apache.poi.ss.usermodel.BuiltinFormats; |
||||
import org.apache.poi.ss.usermodel.FillPatternType; |
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment; |
||||
import org.apache.poi.ss.usermodel.IgnoredErrorType; |
||||
import org.apache.poi.ss.usermodel.IndexedColors; |
||||
import org.apache.poi.ss.usermodel.VerticalAlignment; |
||||
|
||||
/** |
||||
* Cell style when writing |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class WriteCellStyle { |
||||
/** |
||||
* Set the data format (must be a valid format). Built in formats are defined at {@link BuiltinFormats}. |
||||
*/ |
||||
private Short dataFormat; |
||||
/** |
||||
* Set the font for this style |
||||
*/ |
||||
private WriteFont writeFont; |
||||
/** |
||||
* Set the cell's using this style to be hidden |
||||
*/ |
||||
private Boolean hidden; |
||||
|
||||
/** |
||||
* Set the cell's using this style to be locked |
||||
*/ |
||||
private Boolean locked; |
||||
/** |
||||
* Turn on or off "Quote Prefix" or "123 Prefix" for the style, which is used to tell Excel that the thing which |
||||
* looks like a number or a formula shouldn't be treated as on. Turning this on is somewhat (but not completely, see |
||||
* {@link IgnoredErrorType}) like prefixing the cell value with a ' in Excel |
||||
*/ |
||||
private Boolean quotePrefix; |
||||
/** |
||||
* Set the type of horizontal alignment for the cell |
||||
*/ |
||||
private HorizontalAlignment horizontalAlignment; |
||||
/** |
||||
* Set whether the text should be wrapped. Setting this flag to <code>true</code> make all content visible within a |
||||
* cell by displaying it on multiple lines |
||||
* |
||||
*/ |
||||
private Boolean wrapped; |
||||
/** |
||||
* Set the type of vertical alignment for the cell |
||||
*/ |
||||
private VerticalAlignment verticalAlignment; |
||||
/** |
||||
* Set the degree of rotation for the text in the cell. |
||||
* |
||||
* Note: HSSF uses values from -90 to 90 degrees, whereas XSSF uses values from 0 to 180 degrees. The |
||||
* implementations of this method will map between these two value-ranges accordingly, however the corresponding |
||||
* getter is returning values in the range mandated by the current type of Excel file-format that this CellStyle is |
||||
* applied to. |
||||
*/ |
||||
private Short rotation; |
||||
/** |
||||
* Set the number of spaces to indent the text in the cell |
||||
*/ |
||||
private Short indent; |
||||
/** |
||||
* Set the type of border to use for the left border of the cell |
||||
*/ |
||||
private BorderStyle borderLeft; |
||||
/** |
||||
* Set the type of border to use for the right border of the cell |
||||
*/ |
||||
private BorderStyle borderRight; |
||||
/** |
||||
* Set the type of border to use for the top border of the cell |
||||
*/ |
||||
private BorderStyle borderTop; |
||||
|
||||
/** |
||||
* Set the type of border to use for the bottom border of the cell |
||||
*/ |
||||
private BorderStyle borderBottom; |
||||
/** |
||||
* Set the color to use for the left border |
||||
* |
||||
* @see IndexedColors |
||||
*/ |
||||
private Short leftBorderColor; |
||||
|
||||
/** |
||||
* Set the color to use for the right border |
||||
* |
||||
* @see IndexedColors |
||||
* |
||||
*/ |
||||
private Short rightBorderColor; |
||||
|
||||
/** |
||||
* Set the color to use for the top border |
||||
* |
||||
* @see IndexedColors |
||||
* |
||||
*/ |
||||
private Short topBorderColor; |
||||
/** |
||||
* Set the color to use for the bottom border |
||||
* |
||||
* @see IndexedColors |
||||
* |
||||
*/ |
||||
private Short bottomBorderColor; |
||||
/** |
||||
* Setting to one fills the cell with the foreground color... No idea about other values |
||||
* |
||||
* @see FillPatternType#SOLID_FOREGROUND |
||||
*/ |
||||
private FillPatternType fillPatternType; |
||||
|
||||
/** |
||||
* Set the background fill color. |
||||
* |
||||
* @see IndexedColors |
||||
* |
||||
*/ |
||||
private Short fillBackgroundColor; |
||||
|
||||
/** |
||||
* Set the foreground fill color <i>Note: Ensure Foreground color is set prior to background color.</i> |
||||
* |
||||
* @see IndexedColors |
||||
* |
||||
*/ |
||||
private Short fillForegroundColor; |
||||
/** |
||||
* Controls if the Cell should be auto-sized to shrink to fit if the text is too long |
||||
*/ |
||||
private Boolean shrinkToFit; |
||||
|
||||
public Short getDataFormat() { |
||||
return dataFormat; |
||||
} |
||||
|
||||
public void setDataFormat(Short dataFormat) { |
||||
this.dataFormat = dataFormat; |
||||
} |
||||
|
||||
public WriteFont getWriteFont() { |
||||
return writeFont; |
||||
} |
||||
|
||||
public void setWriteFont(WriteFont writeFont) { |
||||
this.writeFont = writeFont; |
||||
} |
||||
|
||||
public Boolean getHidden() { |
||||
return hidden; |
||||
} |
||||
|
||||
public void setHidden(Boolean hidden) { |
||||
this.hidden = hidden; |
||||
} |
||||
|
||||
public Boolean getLocked() { |
||||
return locked; |
||||
} |
||||
|
||||
public void setLocked(Boolean locked) { |
||||
this.locked = locked; |
||||
} |
||||
|
||||
public Boolean getQuotePrefix() { |
||||
return quotePrefix; |
||||
} |
||||
|
||||
public void setQuotePrefix(Boolean quotePrefix) { |
||||
this.quotePrefix = quotePrefix; |
||||
} |
||||
|
||||
public HorizontalAlignment getHorizontalAlignment() { |
||||
return horizontalAlignment; |
||||
} |
||||
|
||||
public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) { |
||||
this.horizontalAlignment = horizontalAlignment; |
||||
} |
||||
|
||||
public Boolean getWrapped() { |
||||
return wrapped; |
||||
} |
||||
|
||||
public void setWrapped(Boolean wrapped) { |
||||
this.wrapped = wrapped; |
||||
} |
||||
|
||||
public VerticalAlignment getVerticalAlignment() { |
||||
return verticalAlignment; |
||||
} |
||||
|
||||
public void setVerticalAlignment(VerticalAlignment verticalAlignment) { |
||||
this.verticalAlignment = verticalAlignment; |
||||
} |
||||
|
||||
public Short getRotation() { |
||||
return rotation; |
||||
} |
||||
|
||||
public void setRotation(Short rotation) { |
||||
this.rotation = rotation; |
||||
} |
||||
|
||||
public Short getIndent() { |
||||
return indent; |
||||
} |
||||
|
||||
public void setIndent(Short indent) { |
||||
this.indent = indent; |
||||
} |
||||
|
||||
public BorderStyle getBorderLeft() { |
||||
return borderLeft; |
||||
} |
||||
|
||||
public void setBorderLeft(BorderStyle borderLeft) { |
||||
this.borderLeft = borderLeft; |
||||
} |
||||
|
||||
public BorderStyle getBorderRight() { |
||||
return borderRight; |
||||
} |
||||
|
||||
public void setBorderRight(BorderStyle borderRight) { |
||||
this.borderRight = borderRight; |
||||
} |
||||
|
||||
public BorderStyle getBorderTop() { |
||||
return borderTop; |
||||
} |
||||
|
||||
public void setBorderTop(BorderStyle borderTop) { |
||||
this.borderTop = borderTop; |
||||
} |
||||
|
||||
public BorderStyle getBorderBottom() { |
||||
return borderBottom; |
||||
} |
||||
|
||||
public void setBorderBottom(BorderStyle borderBottom) { |
||||
this.borderBottom = borderBottom; |
||||
} |
||||
|
||||
public Short getLeftBorderColor() { |
||||
return leftBorderColor; |
||||
} |
||||
|
||||
public void setLeftBorderColor(Short leftBorderColor) { |
||||
this.leftBorderColor = leftBorderColor; |
||||
} |
||||
|
||||
public Short getRightBorderColor() { |
||||
return rightBorderColor; |
||||
} |
||||
|
||||
public void setRightBorderColor(Short rightBorderColor) { |
||||
this.rightBorderColor = rightBorderColor; |
||||
} |
||||
|
||||
public Short getTopBorderColor() { |
||||
return topBorderColor; |
||||
} |
||||
|
||||
public void setTopBorderColor(Short topBorderColor) { |
||||
this.topBorderColor = topBorderColor; |
||||
} |
||||
|
||||
public Short getBottomBorderColor() { |
||||
return bottomBorderColor; |
||||
} |
||||
|
||||
public void setBottomBorderColor(Short bottomBorderColor) { |
||||
this.bottomBorderColor = bottomBorderColor; |
||||
} |
||||
|
||||
public FillPatternType getFillPatternType() { |
||||
return fillPatternType; |
||||
} |
||||
|
||||
public void setFillPatternType(FillPatternType fillPatternType) { |
||||
this.fillPatternType = fillPatternType; |
||||
} |
||||
|
||||
public Short getFillBackgroundColor() { |
||||
return fillBackgroundColor; |
||||
} |
||||
|
||||
public void setFillBackgroundColor(Short fillBackgroundColor) { |
||||
this.fillBackgroundColor = fillBackgroundColor; |
||||
} |
||||
|
||||
public Short getFillForegroundColor() { |
||||
return fillForegroundColor; |
||||
} |
||||
|
||||
public void setFillForegroundColor(Short fillForegroundColor) { |
||||
this.fillForegroundColor = fillForegroundColor; |
||||
} |
||||
|
||||
public Boolean getShrinkToFit() { |
||||
return shrinkToFit; |
||||
} |
||||
|
||||
public void setShrinkToFit(Boolean shrinkToFit) { |
||||
this.shrinkToFit = shrinkToFit; |
||||
} |
||||
} |
@ -0,0 +1,143 @@
|
||||
package com.alibaba.excel.write.metadata.style; |
||||
|
||||
import org.apache.poi.common.usermodel.fonts.FontCharset; |
||||
import org.apache.poi.hssf.usermodel.HSSFPalette; |
||||
import org.apache.poi.ss.usermodel.Font; |
||||
import org.apache.poi.ss.usermodel.IndexedColors; |
||||
|
||||
/** |
||||
* Font when writing |
||||
* |
||||
* @author jipengfei |
||||
*/ |
||||
public class WriteFont { |
||||
/** |
||||
* The name for the font (i.e. Arial) |
||||
*/ |
||||
private String fontName; |
||||
/** |
||||
* Height in the familiar unit of measure - points |
||||
*/ |
||||
private Short fontHeightInPoints; |
||||
/** |
||||
* Whether to use italics or not |
||||
*/ |
||||
private Boolean italic; |
||||
/** |
||||
* Whether to use a strikeout horizontal line through the text or not |
||||
*/ |
||||
private Boolean strikeout; |
||||
/** |
||||
* The color for the font |
||||
* |
||||
* @see Font#COLOR_NORMAL |
||||
* @see Font#COLOR_RED |
||||
* @see HSSFPalette#getColor(short) |
||||
* @see IndexedColors |
||||
*/ |
||||
private Short color; |
||||
/** |
||||
* Set normal,super or subscript. |
||||
* |
||||
* @see Font#SS_NONE |
||||
* @see Font#SS_SUPER |
||||
* @see Font#SS_SUB |
||||
*/ |
||||
private Short typeOffset; |
||||
/** |
||||
* set type of text underlining to use |
||||
* |
||||
* @see Font#U_NONE |
||||
* @see Font#U_SINGLE |
||||
* @see Font#U_DOUBLE |
||||
* @see Font#U_SINGLE_ACCOUNTING |
||||
* @see Font#U_DOUBLE_ACCOUNTING |
||||
*/ |
||||
|
||||
private Byte underline; |
||||
/** |
||||
* Set character-set to use. |
||||
* |
||||
* @see FontCharset |
||||
* @see Font#ANSI_CHARSET |
||||
* @see Font#DEFAULT_CHARSET |
||||
* @see Font#SYMBOL_CHARSET |
||||
*/ |
||||
private Integer charset; |
||||
/** |
||||
* Bold |
||||
*/ |
||||
private Boolean bold; |
||||
|
||||
public String getFontName() { |
||||
return fontName; |
||||
} |
||||
|
||||
public void setFontName(String fontName) { |
||||
this.fontName = fontName; |
||||
} |
||||
|
||||
public Short getFontHeightInPoints() { |
||||
return fontHeightInPoints; |
||||
} |
||||
|
||||
public void setFontHeightInPoints(Short fontHeightInPoints) { |
||||
this.fontHeightInPoints = fontHeightInPoints; |
||||
} |
||||
|
||||
public Boolean getItalic() { |
||||
return italic; |
||||
} |
||||
|
||||
public void setItalic(Boolean italic) { |
||||
this.italic = italic; |
||||
} |
||||
|
||||
public Boolean getStrikeout() { |
||||
return strikeout; |
||||
} |
||||
|
||||
public void setStrikeout(Boolean strikeout) { |
||||
this.strikeout = strikeout; |
||||
} |
||||
|
||||
public Short getColor() { |
||||
return color; |
||||
} |
||||
|
||||
public void setColor(Short color) { |
||||
this.color = color; |
||||
} |
||||
|
||||
public Short getTypeOffset() { |
||||
return typeOffset; |
||||
} |
||||
|
||||
public void setTypeOffset(Short typeOffset) { |
||||
this.typeOffset = typeOffset; |
||||
} |
||||
|
||||
public Byte getUnderline() { |
||||
return underline; |
||||
} |
||||
|
||||
public void setUnderline(Byte underline) { |
||||
this.underline = underline; |
||||
} |
||||
|
||||
public Integer getCharset() { |
||||
return charset; |
||||
} |
||||
|
||||
public void setCharset(Integer charset) { |
||||
this.charset = charset; |
||||
} |
||||
|
||||
public Boolean getBold() { |
||||
return bold; |
||||
} |
||||
|
||||
public void setBold(Boolean bold) { |
||||
this.bold = bold; |
||||
} |
||||
} |
Loading…
Reference in new issue