public class NumFmt extends Object implements Cloneable, Comparable<NumFmt>
A number format can have up to four sections of code, separated by semicolons. These code sections define the format for positive numbers, negative numbers, zero values, and text, in that order.
<POSITIVE>;<NEGATIVE>;<ZERO>;<TEXT>
For example, you can use these code sections to create the following custom format:
[Blue]#,##0.00_);[Red](#,##0.00);0.00;"sales "@
You do not have to include all code sections in your custom number format. If you specify only two code sections for your custom number format, the first section is used for positive numbers and zeros, and the second section is used for negative numbers. If you specify only one code section, it is used for all numbers. If you want to skip a code section and include a code section that follows it, you must include the ending semicolon for the section that you skip.
| 限定符和类型 | 字段和说明 |
|---|---|
protected String |
code |
protected Map<String,Integer> |
codeWidthCache
缓存code的宽度
key: 字号+字体
value: 预计算的结果
|
static NumFmt |
DATE_FORMAT
Format as
yyyy-mm-dd hh:mm:ss |
static NumFmt |
DATETIME_FORMAT
Format as
yyyy-mm-dd hh:mm:ss |
protected int |
id |
static NumFmt |
TIME_FORMAT
Format as
yyyy-mm-dd hh:mm:ss |
| 限定符和类型 | 方法和说明 |
|---|---|
double |
calcNumWidth(double base,
Font font)
粗略计算单元格长度,优先从缓存中获取预处理结果,缓存key由字号+字体名组成这样就保存能计算出相近的宽度,
未命中缓存则从先预处理再丢入缓存以便下次使用
|
NumFmt |
clone() |
int |
compareTo(NumFmt o) |
static List<NumFmt> |
domToNumFmt(org.dom4j.Element root) |
boolean |
equals(Object o) |
String |
getCode() |
protected int |
getCodeWidthFromCache(Font font)
计算并缓存格式化串的长度,以此长度为基础计算文本长度
|
int |
getId() |
int |
hashCode() |
static NumFmt |
of(String code)
Create a NumFmt
|
void |
setCode(String code) |
org.dom4j.Element |
toDom(org.dom4j.Element root) |
String |
toString() |
static NumFmt |
valueOf(int id)
Built-In number format
|
public static final NumFmt DATETIME_FORMAT
yyyy-mm-dd hh:mm:sspublic static final NumFmt DATE_FORMAT
yyyy-mm-dd hh:mm:sspublic static final NumFmt TIME_FORMAT
yyyy-mm-dd hh:mm:ssprotected String code
protected int id
public NumFmt()
public NumFmt(String code)
public String getCode()
public void setCode(String code)
public int getId()
public static NumFmt valueOf(int id)
id - the built-in idNumFmtpublic static NumFmt of(String code)
code - the numFmt code stringpublic double calcNumWidth(double base,
Font font)
base - the cell value lengthfont - fontprotected int getCodeWidthFromCache(Font font)
font - 字体public org.dom4j.Element toDom(org.dom4j.Element root)
public int compareTo(NumFmt o)
compareTo 在接口中 Comparable<NumFmt>Copyright © 2025. All rights reserved.