T - 子类public abstract class WriteExcelTempletFile<T extends WriteExcelTempletFile<T>> extends WriteMultipleTempletFile<T> implements MarkComment<T>, MarkFieldBackground<T>, MarkTextColor<T>, MarkTextFont<T>, MarkFieldLink<T>
文件名:WriteExcelTempletFile.java
用途: 提供用于对excel数据型的内容进行编写的方法
编码时间:2021年5月27日上午8:09:29
修改时间:2022年10月19日 上午8:13:53
| Modifier and Type | Class and Description |
|---|---|
static class |
WriteExcelTempletFile.AlignmentType
文件名:WriteExcelTempletFile.java
|
| Modifier and Type | Field and Description |
|---|---|
protected String |
COLUMN_SPLIT_SIGN
单元格坐标分隔符
|
static String |
DATA_SHEET_NAME
指定excel中,读取数据有效性的sheet页名称
|
static String |
DATA_TITLE_FORMAT
指定数据有效性标题的格式
|
static String |
KEY_LINK_CONTENT
标记json中的linkContent字段
|
static String |
KEY_WORK
标记json中的work字段
|
static String |
KEY_WRAP_TEXT
标记json中的wrapText字段
|
protected HashMap<com.alibaba.fastjson.JSONObject,org.apache.poi.xssf.usermodel.XSSFCellStyle> |
styleMap
用于存储样式(key使用样式的json来编写)
|
dataMap, DEFAULT_NAMEcaseIndex, data, endField, KEY_CASE, KEY_CONTENT, KEY_DATA, KEY_DEFAULT, KEY_TEMPLET, KEY_TEXT, placeholder, WORD_SIGN, writeRowNumKEY_COMMENTKEY_COLORKEY_BOLD, KEY_FONT_NAME, KEY_FONT_SIZE, KEY_ITALIC, KEY_UNDERLINEKEY_LINKKEY_NAME| Constructor and Description |
|---|
WriteExcelTempletFile(org.dom4j.Document templetXml,
File saveFile)
通过模板配置xml文件对文件写入类进行构造
|
WriteExcelTempletFile(String templetName,
FileTemplet templet)
构造Excel写入类,并设置一个Sheet页的模板及相应的名称
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addComment(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
org.apache.poi.xssf.usermodel.XSSFSheet sheet,
org.apache.poi.xssf.usermodel.XSSFCell cell,
String commentContent)
用于向单元格上添加Comment标注
|
T |
addContent(String field,
int index,
Placeholder placeholder,
String... contents)
根据传入的字段信息,将指定的内容插入到用例相应字段的指定下标下,并且可传入临时的占位符类对象,对文本中的占位符进行替换,且不影响已添加的替换词语
|
protected void |
addDataOption(org.apache.poi.xssf.usermodel.XSSFSheet sheet,
com.alibaba.fastjson.JSONObject templetJson,
List<String> dataTitleList,
int rowIndex)
用于在单元格上附加数据有效性下拉选项
|
protected void |
addLink(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
org.apache.poi.xssf.usermodel.XSSFCell cell,
com.alibaba.fastjson.JSONObject linkJson)
用于向单元格上添加超链接
|
protected org.apache.poi.xssf.usermodel.XSSFRichTextString |
appendContent(org.apache.poi.xssf.usermodel.XSSFRichTextString content,
org.apache.poi.xssf.usermodel.XSSFCellStyle style,
String text,
com.alibaba.fastjson.JSONObject fieldTempletJson,
int textIndex)
用于对需要写入单元格的文本进行拼接
|
T |
bold(String field,
int... textIndexs)
用于对指定文本内容的字体进行加粗
|
T |
border(org.apache.poi.ss.usermodel.BorderStyle borderStyle,
OrientationType[] orientationTypes,
String... fields)
该方法用于在当前行的指定字段的单元格上添加指定边界的边框
|
T |
border(org.apache.poi.ss.usermodel.BorderStyle borderStyle,
String... fields)
该方法用于在当前行的指定字段的单元格上添加所有边界的边框
|
T |
changeCaseBackground(org.apache.poi.ss.usermodel.IndexedColors indexedColors)
用于标记当前内容的所有字段背景颜色
|
T |
changeFieldBackground(String field,
org.apache.poi.ss.usermodel.IndexedColors indexedColors)
用于标记当前内容指定字段的背景颜色
|
T |
changeTextColor(org.apache.poi.ss.usermodel.IndexedColors indexedColors,
String field,
int... textIndexs)
用于对指定文本内容的字体颜色进行更改
|
protected void |
contentWriteTemplet(FileTemplet templet,
int caseStartIndex,
int caseEndIndex)
用于将缓存的数据内容,写入到模板中
|
protected void |
createTempletFile(FileTemplet templet)
用于创建模板文件
|
T |
fieldComment(String field,
String commentText)
用于在字段上添加注解
|
protected com.alibaba.fastjson.JSONObject |
fieldJson2StyleJson(String templetName,
com.alibaba.fastjson.JSONObject templetFieldJson,
com.alibaba.fastjson.JSONObject textJson,
com.alibaba.fastjson.JSONObject fieldContentJson,
com.alibaba.fastjson.JSONObject contentJson)
该方法用于将字段的json转换为字段样式json
|
protected org.apache.poi.xssf.usermodel.XSSFCell |
getCell(org.apache.poi.xssf.usermodel.XSSFSheet sheet,
int rowIndex,
int columnIndex)
用于获取指定的单元格对象,若对象不存在,则创建单元格
|
protected org.apache.poi.xssf.usermodel.XSSFCellStyle |
getStyle(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
com.alibaba.fastjson.JSONObject styleJson)
用于获取指定的单元格样式
|
protected boolean |
isExistTemplet(File templetFile,
FileTemplet templet)
用于判断当前模板是否存在于模板文件中
|
T |
italic(String field,
int... textIndexs)
用于倾斜指定文本内容的字体
|
T |
linkEmail(String field,
String email)
用于在字段上添加Email超链接
|
T |
linkField(String field,
String linkField,
int index)
用于在字段上添加文本内超链
|
T |
linkFile(String field,
File file)
用于在字段上添加外部文件超链接
|
T |
linkUrl(String field,
URL url)
用于在字段上添加url超链接
|
protected List<String> |
readDataOptionTitle(org.apache.poi.xssf.usermodel.XSSFWorkbook excel)
用于读取数据有效性sheet页中所有数据有效性列的标题
|
protected org.apache.poi.xssf.usermodel.XSSFCell |
setCellContent(org.apache.poi.xssf.usermodel.XSSFCell cell,
org.apache.poi.xssf.usermodel.XSSFRichTextString content,
org.apache.poi.xssf.usermodel.XSSFCellStyle style)
用于在单元格设置样式,并写入内容
|
protected org.apache.poi.xssf.usermodel.XSSFRichTextString |
setContent(org.apache.poi.xssf.usermodel.XSSFRichTextString content,
String text,
org.apache.poi.xssf.usermodel.XSSFCellStyle style)
用于拼接一个单元格中带样式的内容
|
T |
underline(String field,
int... textIndexs)
用于对指定文本内容的字体加上下划线
|
protected org.apache.poi.xssf.usermodel.XSSFCell |
writeMultipleCellContent(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
org.apache.poi.xssf.usermodel.XSSFSheet templetSheet,
com.alibaba.fastjson.JSONObject fieldContentJson,
com.alibaba.fastjson.JSONObject fieldTempletJson,
com.alibaba.fastjson.JSONObject contentJson,
int lastRowIndex)
用于写入多个单元格内容
|
protected org.apache.poi.xssf.usermodel.XSSFCell |
writeSingleCellContent(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
org.apache.poi.xssf.usermodel.XSSFSheet templetSheet,
com.alibaba.fastjson.JSONObject fieldContentJson,
com.alibaba.fastjson.JSONObject fieldTempletJson,
com.alibaba.fastjson.JSONObject contentJson,
int lastRowIndex)
用于写入单个单元格内容
|
addTemplet, end, getAllTempletJson, getDataMap, getTemplet, getWriteFileData, setWriteData, switchPage, write, writeaddContent, addContent, addContent, addReplaceFunction, addReplaceWord, analysisIndex, clearCase, clearContent, clearFieldValue, disposeWriteFieldsContent, end, getCase, getPlaceholder, getTextJson, getWriteData, replenishDefaultContent, setContentJson, setEndField, setFieldValue, setFileTemplet, setPlaceholder, setWriteRowNum, toTempletJson, toWriteFileJsonpublic static final String KEY_WRAP_TEXT
public static final String KEY_WORK
public static final String KEY_LINK_CONTENT
protected final String COLUMN_SPLIT_SIGN
public static final String DATA_SHEET_NAME
public static final String DATA_TITLE_FORMAT
protected HashMap<com.alibaba.fastjson.JSONObject,org.apache.poi.xssf.usermodel.XSSFCellStyle> styleMap
public WriteExcelTempletFile(String templetName, FileTemplet templet)
templetName - 模板名称templet - 模板类public WriteExcelTempletFile(org.dom4j.Document templetXml,
File saveFile)
通过该方法构造的写入类为包含模板的写入类,可直接按照字段编写文件内容
templetXml - 模板配置文件saveFile - 文件保存路径public T linkField(String field, String linkField, int index)
若超链接的字段在当前指向的模板中,则只需要传入字段名称;反之,则需要传入“模板名称|字段名称”。 例如,类中存在“测试用例”、“测试数据”两个模板,当前正在向“测试用例”模板写入内容,则:
linkField("步骤", "标题", 2)linkField("步骤", "测试数据|数据", 2)注意:
linkField in interface MarkFieldLink<T extends WriteExcelTempletFile<T>>field - 字段linkField - 需要链接的字段index - 字段指定的下标public T linkUrl(String field, URL url)
MarkFieldLinklinkUrl in interface MarkFieldLink<T extends WriteExcelTempletFile<T>>field - 字段url - 站点urlpublic T linkEmail(String field, String email)
MarkFieldLinklinkEmail in interface MarkFieldLink<T extends WriteExcelTempletFile<T>>field - 字段email - Email地址public T linkFile(String field, File file)
MarkFieldLinklinkFile in interface MarkFieldLink<T extends WriteExcelTempletFile<T>>field - 字段file - 外部文件类对象public T border(org.apache.poi.ss.usermodel.BorderStyle borderStyle, String... fields)
注意:若不传入字段组或字段组为空时,则默认对所有的字段设置边框
borderStyle - 边框样式枚举fields - 字段组public T border(org.apache.poi.ss.usermodel.BorderStyle borderStyle, OrientationType[] orientationTypes, String... fields)
注意:若不传入字段组或字段组为空时,则默认对所有的字段设置边框
borderStyle - 边框样式枚举fields - 字段组orientationTypes - 边框朝向枚举public T bold(String field, int... textIndexs)
MarkTextFontbold in interface MarkTextFont<T extends WriteExcelTempletFile<T>>field - 字段textIndexs - 字段中文本的下标public T italic(String field, int... textIndexs)
MarkTextFontitalic in interface MarkTextFont<T extends WriteExcelTempletFile<T>>field - 字段textIndexs - 字段中文本的下标public T underline(String field, int... textIndexs)
MarkTextFontunderline in interface MarkTextFont<T extends WriteExcelTempletFile<T>>field - 字段textIndexs - 字段中文本的下标public T changeTextColor(org.apache.poi.ss.usermodel.IndexedColors indexedColors, String field, int... textIndexs)
MarkTextColorchangeTextColor in interface MarkTextColor<T extends WriteExcelTempletFile<T>>indexedColors - 颜色枚举field - 字段textIndexs - 字段中文本的下标public T changeCaseBackground(org.apache.poi.ss.usermodel.IndexedColors indexedColors)
MarkFieldBackgroundchangeCaseBackground in interface MarkFieldBackground<T extends WriteExcelTempletFile<T>>indexedColors - 颜色枚举public T changeFieldBackground(String field, org.apache.poi.ss.usermodel.IndexedColors indexedColors)
MarkFieldBackgroundchangeFieldBackground in interface MarkFieldBackground<T extends WriteExcelTempletFile<T>>field - 字段名称indexedColors - 颜色枚举public T fieldComment(String field, String commentText)
MarkCommentfieldComment in interface MarkComment<T extends WriteExcelTempletFile<T>>field - 字段commentText - 注解文本public T addContent(String field, int index, Placeholder placeholder, String... contents)
WriteTempletFile方法允许传入多条内容,每条内容在写入到文件时,均以换行符隔开。若指定的下标小于0或大于当前内容的最大个数时,则将内容写入到集合最后
注意:
WriteTempletFile.setEndField(String)的设置方法addContent in class WriteTempletFile<T extends WriteExcelTempletFile<T>>field - 字段idindex - 指定插入的位置placeholder - 占位符类contents - 相应字段的内容protected void createTempletFile(FileTemplet templet)
WriteTempletFilecreateTempletFile in class WriteTempletFile<T extends WriteExcelTempletFile<T>>templet - 模板文件对象protected void contentWriteTemplet(FileTemplet templet, int caseStartIndex, int caseEndIndex)
WriteTempletFilecontentWriteTemplet in class WriteTempletFile<T extends WriteExcelTempletFile<T>>templet - 模板类caseStartIndex - 用例起始行caseEndIndex - 用例结束行protected org.apache.poi.xssf.usermodel.XSSFCell writeSingleCellContent(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
org.apache.poi.xssf.usermodel.XSSFSheet templetSheet,
com.alibaba.fastjson.JSONObject fieldContentJson,
com.alibaba.fastjson.JSONObject fieldTempletJson,
com.alibaba.fastjson.JSONObject contentJson,
int lastRowIndex)
excel - excel文件对象templetSheet - 工作页fieldContentJson - 字段内容jsonfieldTempletJson - 字段模板jsoncontentJson - lastRowIndex - 需要写入的行号protected org.apache.poi.xssf.usermodel.XSSFCell writeMultipleCellContent(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
org.apache.poi.xssf.usermodel.XSSFSheet templetSheet,
com.alibaba.fastjson.JSONObject fieldContentJson,
com.alibaba.fastjson.JSONObject fieldTempletJson,
com.alibaba.fastjson.JSONObject contentJson,
int lastRowIndex)
excel - excel文件对象templetSheet - 工作页fieldContentJson - 字段内容jsonfieldTempletJson - 字段模板jsoncontentJson - lastRowIndex - 需要写入的行号protected org.apache.poi.xssf.usermodel.XSSFRichTextString appendContent(org.apache.poi.xssf.usermodel.XSSFRichTextString content,
org.apache.poi.xssf.usermodel.XSSFCellStyle style,
String text,
com.alibaba.fastjson.JSONObject fieldTempletJson,
int textIndex)
content - 需要拼接的富文本内容style - 样式text - 文本内容fieldTempletJson - 模板jsontextIndex - 文本下标protected org.apache.poi.xssf.usermodel.XSSFCell getCell(org.apache.poi.xssf.usermodel.XSSFSheet sheet,
int rowIndex,
int columnIndex)
sheet - 工作页rowIndex - 单元格所在下标columnIndex - 单元格所在列下标protected org.apache.poi.xssf.usermodel.XSSFCell setCellContent(org.apache.poi.xssf.usermodel.XSSFCell cell,
org.apache.poi.xssf.usermodel.XSSFRichTextString content,
org.apache.poi.xssf.usermodel.XSSFCellStyle style)
cell - 单元格类content - 需要写入单元格的内容style - 需要写入单元格的样式,为空则不设置样式protected org.apache.poi.xssf.usermodel.XSSFRichTextString setContent(org.apache.poi.xssf.usermodel.XSSFRichTextString content,
String text,
org.apache.poi.xssf.usermodel.XSSFCellStyle style)
content - 富文本text - 文本内容style - 样式protected com.alibaba.fastjson.JSONObject fieldJson2StyleJson(String templetName, com.alibaba.fastjson.JSONObject templetFieldJson, com.alibaba.fastjson.JSONObject textJson, com.alibaba.fastjson.JSONObject fieldContentJson, com.alibaba.fastjson.JSONObject contentJson)
templetName - 模板名称templetFieldJson - 模板字段jsontextJson - 文本jsonfieldContentJson - 字段内容JsoncontentJson - 整体内容jsonprotected org.apache.poi.xssf.usermodel.XSSFCellStyle getStyle(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
com.alibaba.fastjson.JSONObject styleJson)
根据样式json,来判断该样式是否存在,若不存在,则创建样式;若存在,则获取该样式
styleJson - 样式jsonprotected boolean isExistTemplet(File templetFile, FileTemplet templet)
WriteMultipleTempletFile该方法用于作为是否需要创建模板文件的依据
isExistTemplet in class WriteMultipleTempletFile<T extends WriteExcelTempletFile<T>>templetFile - 模板文件对象templet - 模板对象protected List<String> readDataOptionTitle(org.apache.poi.xssf.usermodel.XSSFWorkbook excel)
excel - 模板类对象protected void addComment(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
org.apache.poi.xssf.usermodel.XSSFSheet sheet,
org.apache.poi.xssf.usermodel.XSSFCell cell,
String commentContent)
excel - excel对象sheet - sheet对象cell - 相应单元格对象commentContent - 字段元素protected void addLink(org.apache.poi.xssf.usermodel.XSSFWorkbook excel,
org.apache.poi.xssf.usermodel.XSSFCell cell,
com.alibaba.fastjson.JSONObject linkJson)
excel - excel对象cell - 相应单元格对象linkJson - 链接内容jsonCopyright © 2024. All rights reserved.