public abstract class BaseCellConverter<T> extends Object implements CellConverter<T>, FieldFormatter<T>
CellConverterを実装するときのベースとなる抽象クラス。
通常は、このクラスを継承してCellConverterを実装します。| 修飾子とタイプ | フィールドと説明 |
|---|---|
protected Configuration |
configuration
システム設定
|
protected OptionalProcessCase<T> |
defaultValue
初期値 - 初期値を持たない場合は空
|
protected FieldAccessor |
field
フィールド情報
|
protected Optional<CellFormulaHandler> |
formulaHandler
書き込み時の数式を設定する
|
protected Optional<org.apache.poi.ss.usermodel.HorizontalAlignment> |
horizontalAlignment
セルの設定 - 横位置
|
protected short |
indent
セルの設定 - インデント
|
protected boolean |
shrinktToFit
セルの設定 - セルを縮小して表示するかどうか
|
protected TextFormatter<T> |
textFormatter
文字列とオブジェクトを相互変換するフォーマッタ
|
protected boolean |
trimmed
値をトリムするかどうか
|
protected Optional<org.apache.poi.ss.usermodel.VerticalAlignment> |
verticalAlignment
セルの設定 - 縦位置
|
protected boolean |
wrapText
セルの設定 - 折り返して全体を表示するかどうか
|
| コンストラクタと説明 |
|---|
BaseCellConverter(FieldAccessor field,
Configuration config) |
| 修飾子とタイプ | メソッドと説明 |
|---|---|
String |
format(T value)
値をフォーマットする。
|
Configuration |
getConfiguration()
システム情報を取得します。
|
OptionalProcessCase<T> |
getDefaultValue()
初期値を取得します。
|
FieldAccessor |
getField()
フィールド情報を取得します。
|
Optional<org.apache.poi.ss.usermodel.HorizontalAlignment> |
getHorizontalAlignment()
セルの設定 - 横位置
|
short |
getIndent()
セルの設定 - インデント
|
TextFormatter<T> |
getTextFormatter()
文字列とオブジェクトを相互変換するフォーマッタを取得します。
|
Optional<org.apache.poi.ss.usermodel.VerticalAlignment> |
getVerticalAlignment()
セルの設定 - 縦位置
|
protected boolean |
isEmptyCell(String formattedValue,
org.apache.poi.ss.usermodel.Cell cell)
セルの値が空かどうか判定します。
|
protected boolean |
isEmptyValue(T obj,
Configuration config)
オブジェクトの値を空と判定する
|
boolean |
isShrinktToFit()
セルの設定 - セルを縮小して表示するかどうか。
|
boolean |
isTrimmed()
値をトリミングするかどうか。
|
boolean |
isWrapText()
セルの設定 - 折り返して全体を表示するかどうか。
|
TypeBindException |
newTypeBindExceptionOnParse(org.apache.poi.ss.usermodel.Cell cell,
Object cellValue)
セルの値をパースしセルの値をJavaオブジェクトに型変換するとに失敗したときの例外
TypeBindExceptionを作成します。 |
TypeBindException |
newTypeBindExceptionOnParse(Exception error,
org.apache.poi.ss.usermodel.Cell cell,
Object cellValue)
セルの値をパースしJavaオブジェクトに型変換するとこに失敗したときの例外
TypeBindExceptionを作成します。 |
protected abstract T |
parseCell(org.apache.poi.ss.usermodel.Cell evaluatedCell,
String formattedValue)
セルをJavaのオブジェクト型に変換します。
|
void |
setDefaultValue(T defaultValue,
ProcessCase[] cases)
初期値を設定します。
|
void |
setFormulaHandler(CellFormulaHandler formulaHandler)
数式を処理するハンドラを設定する
|
void |
setHorizontalAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment horizontalAlignment)
セルの設定 - 横位置
|
void |
setIndent(short indent)
セルの設定 - インデント
|
void |
setShrinktToFit(boolean shrinktToFit)
セルの設定 - セルを縮小して表示するかどうか設定します。
|
void |
setTextFormatter(TextFormatter<T> textFormatter)
文字列とオブジェクトを相互変換するフォーマッタを取得します。
|
void |
setTrimmed(boolean trimmed)
値をトリミングするかどうか設定する
|
protected abstract void |
setupCell(org.apache.poi.ss.usermodel.Cell cell,
Optional<T> cellValue)
書き込み時のセルに値と書式を設定します。
|
void |
setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment verticalAlignment)
セルの設定 - 縦位置
|
void |
setWrapText(boolean wrapText)
セルの設定 - 折り返して全体を表示するかどうか設定します。
|
org.apache.poi.ss.usermodel.Cell |
toCell(T targetValue,
Object targetBean,
org.apache.poi.ss.usermodel.Sheet sheet,
CellPosition address)
シート書き込み時のJavaオブジェクト => Excel Cellに変換する。
|
T |
toObject(org.apache.poi.ss.usermodel.Cell cell)
シート読み込み時のExcel Cell => Javaオブジェクトに変換する。
|
protected final FieldAccessor field
protected final Configuration configuration
protected boolean trimmed
protected OptionalProcessCase<T> defaultValue
protected boolean shrinktToFit
protected boolean wrapText
protected short indent
protected Optional<org.apache.poi.ss.usermodel.HorizontalAlignment> horizontalAlignment
protected Optional<org.apache.poi.ss.usermodel.VerticalAlignment> verticalAlignment
protected Optional<CellFormulaHandler> formulaHandler
protected TextFormatter<T> textFormatter
public BaseCellConverter(FieldAccessor field, Configuration config)
public T toObject(org.apache.poi.ss.usermodel.Cell cell) throws XlsMapperException
CellConvertertoObject インタフェース内 CellConverter<T>cell - 読み込み対象のセルXlsMapperException - 変換に失敗した場合protected abstract T parseCell(org.apache.poi.ss.usermodel.Cell evaluatedCell, String formattedValue) throws TypeBindException
evaluatedCell - 数式を評価済みのセルformattedValue - フォーマット済みのセルの値。トリミングなど適用済み。TypeBindException - 変換に失敗した場合public TypeBindException newTypeBindExceptionOnParse(Exception error, org.apache.poi.ss.usermodel.Cell cell, Object cellValue)
TypeBindExceptionを作成します。error - 例外情報cell - パースに失敗したセルcellValue - パースに失敗した値public TypeBindException newTypeBindExceptionOnParse(org.apache.poi.ss.usermodel.Cell cell, Object cellValue)
TypeBindExceptionを作成します。cell - パースに失敗したセルcellValue - パースに失敗した値protected boolean isEmptyCell(String formattedValue, org.apache.poi.ss.usermodel.Cell cell)
読み込み時のセルの値をJavaオブジェクトにマッピングする際に呼ばれます。
通常は、formattedValue.isEmpty() で判定しますが、
ハイパーリンクのようにマッピング対象の値がセルの値だけではない場合は、
オーバライドして判定方法を変更します。
formattedValue - フォーマットしたセルの値cell - 評価対象のセルpublic org.apache.poi.ss.usermodel.Cell toCell(T targetValue, Object targetBean, org.apache.poi.ss.usermodel.Sheet sheet, CellPosition address) throws XlsMapperException
CellConvertertoCell インタフェース内 CellConverter<T>targetValue - 書き込み対象のオブジェクト。targetBean - 書き込み対象のフィールドが設定されているJavaBeanオブジェクト。sheet - 書き込み先のシートaddress - 書き込み先のセルのアドレスXlsMapperException - 変換に失敗した場合protected boolean isEmptyValue(T obj, Configuration config)
obj - 判定対象の値config - システム情報protected abstract void setupCell(org.apache.poi.ss.usermodel.Cell cell,
Optional<T> cellValue)
throws TypeBindException
cell - 設定対象のセルcellValue - 設定対象の値。TypeBindException - 変換に失敗した場合public FieldAccessor getField()
public Configuration getConfiguration()
public String format(T value)
FieldFormatterformat インタフェース内 FieldFormatter<T>value - フォーマット対象の値。nullが渡ってくることもある。public void setTrimmed(boolean trimmed)
trimmed - trueの場合、トリムする。public boolean isTrimmed()
public void setDefaultValue(T defaultValue, ProcessCase[] cases)
defaultValue - 初期値となるオブジェクト。cases - 該当する処理ケースpublic OptionalProcessCase<T> getDefaultValue()
public void setShrinktToFit(boolean shrinktToFit)
shrinktToFit - trueの場合、セルを縮小して表示します。public boolean isShrinktToFit()
public void setWrapText(boolean wrapText)
wrapText - trueの場合、折り返して全体を表示します。public boolean isWrapText()
public short getIndent()
public void setIndent(short indent)
indent - 0以上の場合、有効。public Optional<org.apache.poi.ss.usermodel.HorizontalAlignment> getHorizontalAlignment()
public void setHorizontalAlignment(org.apache.poi.ss.usermodel.HorizontalAlignment horizontalAlignment)
horizontalAlignment - 横位置public Optional<org.apache.poi.ss.usermodel.VerticalAlignment> getVerticalAlignment()
public void setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment verticalAlignment)
verticalAlignment - 縦位置public void setFormulaHandler(CellFormulaHandler formulaHandler)
formulaHandler - 数式を処理するハンドラをpublic void setTextFormatter(TextFormatter<T> textFormatter)
textFormatter - フォーマッタpublic TextFormatter<T> getTextFormatter()
Copyright © 2025 mygreen. All rights reserved.