@TopNS(prefix={"","r"}, value="worksheet", uri={"http://schemas.openxmlformats.org/spreadsheetml/2006/main","http://schemas.openxmlformats.org/officeDocument/2006/relationships"}) public class XMLWorksheetWriter extends Object implements IWorksheetWriter
| 限定符和类型 | 字段和说明 |
|---|---|
protected ExtBufferedWriter |
bw |
protected Column[] |
columns |
protected double[] |
columnWidths |
protected Comments |
comments |
protected IDrawingsWriter |
drawingsWriter
Picture and Chart Support
|
protected Font[] |
fs
按cellXfs下标缓存字体
|
protected boolean |
includeAutoWidth
If there are any auto-width columns
|
protected org.slf4j.Logger |
LOGGER
LOGGER
|
protected Path |
mediaPath |
protected BiConsumer<Sheet,Integer> |
progressConsumer
A progress window
|
protected Sheet |
sheet |
protected int |
sheetDataReady |
protected SharedStrings |
sst |
protected int |
startHeaderRow |
protected int |
startRow |
protected Styles |
styles
全局样式,为工作表的一个指针
|
protected int |
totalRows |
protected Path |
workSheetPath |
| 构造器和说明 |
|---|
XMLWorksheetWriter() |
XMLWorksheetWriter(Sheet sheet) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
afterSheetData()
Append others customize info
|
protected void |
beforeSheetData(boolean nonHeader)
Begin to write the Sheet data and the header row.
|
IWorksheetWriter |
clone()
复制工作表输出协议
|
void |
close()
Release resources
|
protected void |
collectHeaderColumns()
收集表头信息,如果有共享字符串标记则初始化SharedStringsTable
|
IDrawingsWriter |
createDrawingsWriter()
Create drawing writer and add relationship
|
protected Picture |
createPicture(int column,
int row)
Picture constructor
You can use this method to add general effects
|
void |
downloadCompleted(Picture picture,
byte[] body)
Complete downloading, check the file signatures and set the subscript
Picture.idx to idle |
void |
downloadRemoteResource(Picture picture,
String url)
Download remote resources
By default, only HTTP or HTTPS protocols are supported.
|
protected Column |
getColumn(int index)
获取列属性
|
int |
getColumnLimit()
The Worksheet column limit
|
String |
getFileSuffix()
Returns the worksheet name
|
protected Font |
getFont(int xf)
通过单元格样式索引获取
FontMetrics用以计算文本宽度 |
double |
getHeaderHeight(Column[][] columnsArray,
int row)
Returns the maximum cell height
|
int |
getRowLimit()
Override this method to modify the maximum number
of rows per page, this value contains the header
row and data rows
eq: limit is 100 means data has 99 rows
|
protected boolean |
hasMedia()
Check if images are output
|
protected void |
initDrawingsWriter()
Initialization DrawingsWriter
|
protected Path |
initWriter(Path root) |
static boolean |
isFirstMergedCell(List<Dimension> mergeCells,
int row,
int col)
Test whether the coordinate is the first cell of the merged cell,
and use
Grid.test(int, int) to determine yes before calling this method |
protected void |
resizeColumnWidth(File path,
int rows)
Resize column width
|
IWorksheetWriter |
setWorksheet(Sheet sheet)
Rest worksheet
|
protected int |
startRow(int rows,
int columns,
Double rowHeight)
Write begin of row
|
protected double |
stringWidth(String s,
int xf)
计算文本在单元格的宽度,参考
SwingUtilities2.stringWidth(javax.swing.JComponent, java.awt.FontMetrics, java.lang.String)
Java的FontMetrics计算中文字符有个问题,对于绝大多数英文字体计算出来的中文字符宽度都不准,
在英文字体中显示的中文字体可能会默认显示"宋体",默认字体与地区和操作系统相关这里只取简体中文的临近值约为字体大小,
英文字符计算比较复杂每种字体显示的宽度差异很大,有较窄的字符'i','l',':'也有较宽的字符'X','E','G',’%',‘@’,
对于英文字符统一使用FontMetrics计算。 |
protected void |
writeAfter(int total)
Write at after worksheet body
|
protected void |
writeBefore()
Write worksheet header data
|
protected void |
writeBinary(byte[] bytes,
int row,
int column,
int xf)
Write binary file
|
protected void |
writeBinary(ByteBuffer byteBuffer,
int row,
int column,
int xf)
Write binary file
|
protected void |
writeBool(boolean bool,
int row,
int column,
int xf)
Write boolean value
|
protected void |
writeChar(char c,
int row,
int column,
int xf)
Write char value
|
protected void |
writeCols(int fillSpace,
String defaultWidth)
Write the default column info, The specified column width will be overwritten in these method.
|
protected void |
writeDecimal(BigDecimal bd,
int row,
int column,
int xf)
Write decimal value
|
protected void |
writeDimension()
Write the dimension of sheet, default value is
A1 |
protected void |
writeDouble(double d,
int row,
int column,
int xf)
Write double value
|
protected void |
writeFile(Path path,
int row,
int column,
int xf)
Write file value
|
protected int |
writeHeaderRow()
Write the header row
|
protected void |
writeMergeCells()
Append merged cells if exists
|
protected void |
writeNull(int row,
int column,
int xf)
Write blank value
|
protected void |
writeNumeric(long l,
int row,
int column,
int xf)
Write numeric value
|
protected void |
writePictureDirect(int id,
String name,
int column,
int row,
FileSignatures.Signature signature) |
protected void |
writeRemoteMedia(String url,
int row,
int column,
int xf)
Write remote media value
|
protected void |
writeRootNode()
Write the <worksheet> node
|
protected void |
writeRow(Row row)
Write a row data
|
protected void |
writeRowBlock(RowBlock rowBlock)
Write a row-block
|
protected void |
writeRowBlockFireProgress(RowBlock rowBlock)
Write a row-block and fire progress event
|
protected void |
writeSheetFormat(int fillSpace,
String defaultWidth)
Write the sheet format
|
protected void |
writeSheetViews()
Write the sheet views such as FreezeEnum, Default selection cell.
|
protected void |
writeStream(InputStream stream,
int row,
int column,
int xf)
Write stream value
|
protected void |
writeString(String s,
int row,
int column,
int xf)
Write string value
|
void |
writeTo(Path path)
Write a row block
|
void |
writeTo(Path path,
Supplier<RowBlock> supplier)
Write a row block
|
protected void |
writeWaterMark()
添加水印
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisBigDecimal, isBool, isChar, isDate, isDateTime, isDouble, isFloat, isInt, isLocalDate, isLocalDateTime, isLocalTime, isLong, isOutOfSheet, isShort, isString, isTime, writeEmptySheetprotected final org.slf4j.Logger LOGGER
protected Path workSheetPath
protected Path mediaPath
protected ExtBufferedWriter bw
protected Sheet sheet
protected Column[] columns
protected SharedStrings sst
protected Styles styles
protected Comments comments
protected int startRow
protected int startHeaderRow
protected int totalRows
protected int sheetDataReady
protected boolean includeAutoWidth
protected IDrawingsWriter drawingsWriter
protected BiConsumer<Sheet,Integer> progressConsumer
protected double[] columnWidths
protected Font[] fs
public XMLWorksheetWriter()
public XMLWorksheetWriter(Sheet sheet)
public void writeTo(Path path, Supplier<RowBlock> supplier) throws IOException
writeTo 在接口中 IWorksheetWritersupplier - a row-block supplierpath - 保存位置IOException - if I/O error occurpublic void writeTo(Path path) throws IOException
writeTo 在接口中 Storablepath - the storage pathIOException - if I/O error occurprotected Path initWriter(Path root) throws IOException
IOExceptionpublic IWorksheetWriter setWorksheet(Sheet sheet)
setWorksheet 在接口中 IWorksheetWritersheet - the worksheetpublic IWorksheetWriter clone()
IWorksheetWriterclone 在接口中 IWorksheetWriterclone 在类中 Objectpublic String getFileSuffix()
getFileSuffix 在接口中 IWorksheetWriterpublic int getRowLimit()
eq: limit is 100 means data has 99 rows
getRowLimit 在接口中 IWorksheetWriterpublic int getColumnLimit()
getColumnLimit 在接口中 IWorksheetWriterprotected void writeBefore()
throws IOException
IOException - if I/O error occurprotected int writeHeaderRow()
throws IOException
IOException - if I/O error occurprotected void writeAfter(int total)
throws IOException
total - the total of rowsIOException - if I/O error occurprotected void writeRowBlock(RowBlock rowBlock) throws IOException
rowBlock - the row-blockIOException - if I/O error occur.protected void writeRowBlockFireProgress(RowBlock rowBlock) throws IOException
rowBlock - the row-blockIOException - if I/O error occur.protected int startRow(int rows,
int columns,
Double rowHeight)
throws IOException
rows - the row index (zero base)columns - the column lengthrowHeight - the row heightIOException - if I/O error occurprotected void writeRow(Row row) throws IOException
row - a row dataIOException - if I/O error occurprotected void writeString(String s, int row, int column, int xf) throws IOException
s - the string valuerow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeDouble(double d,
int row,
int column,
int xf)
throws IOException
d - the double valuerow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeDecimal(BigDecimal bd, int row, int column, int xf) throws IOException
bd - the decimal valuerow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeChar(char c,
int row,
int column,
int xf)
throws IOException
c - the character valuerow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeNumeric(long l,
int row,
int column,
int xf)
throws IOException
l - the numeric valuerow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeBool(boolean bool,
int row,
int column,
int xf)
throws IOException
bool - the boolean valuerow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeNull(int row,
int column,
int xf)
throws IOException
row - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeBinary(byte[] bytes,
int row,
int column,
int xf)
throws IOException
bytes - the binary datarow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeBinary(ByteBuffer byteBuffer, int row, int column, int xf) throws IOException
byteBuffer - the binary datarow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeFile(Path path, int row, int column, int xf) throws IOException
path - the picture filerow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeStream(InputStream stream, int row, int column, int xf) throws IOException
stream - the picture input-streamrow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void writeRemoteMedia(String url, int row, int column, int xf) throws IOException
url - remote urlrow - the row indexcolumn - the column indexxf - the style indexIOException - if I/O error occurprotected void resizeColumnWidth(File path, int rows) throws IOException
path - the sheet temp pathrows - total of rowsIOException - if I/O error occurpublic void close()
close 在接口中 Closeableclose 在接口中 AutoCloseableprotected void writeRootNode()
throws IOException
IOException - if I/O error occur.protected void writeDimension()
throws IOException
A1IOException - if I/O error occur.protected void writeSheetViews()
throws IOException
IOException - if I/O error occur.protected void writeSheetFormat(int fillSpace,
String defaultWidth)
throws IOException
fillSpace - The number of characters to pad when recalculating the width.defaultWidth - The default cell width, 8.38 will be use if it not be setting.IOException - if I/O error occur.protected void writeCols(int fillSpace,
String defaultWidth)
throws IOException
fillSpace - The number of characters to pad when recalculating the width.defaultWidth - The default cell width, 8.38 will be use if it not be setting.IOException - if I/O error occur.protected void beforeSheetData(boolean nonHeader)
throws IOException
nonHeader - mark none headerIOException - if I/O error occur.protected void afterSheetData()
throws IOException
IOException - if I/O error occur.protected void writeWaterMark()
throws IOException
IOException - 无权限或磁盘空间不足protected void writeMergeCells()
throws IOException
IOException - if I/O error occur.protected double stringWidth(String s, int xf)
SwingUtilities2.stringWidth(javax.swing.JComponent, java.awt.FontMetrics, java.lang.String)
Java的FontMetrics计算中文字符有个问题,对于绝大多数英文字体计算出来的中文字符宽度都不准,
在英文字体中显示的中文字体可能会默认显示"宋体",默认字体与地区和操作系统相关这里只取简体中文的临近值约为字体大小,
英文字符计算比较复杂每种字体显示的宽度差异很大,有较窄的字符'i','l',':'也有较宽的字符'X','E','G',’%',‘@’,
对于英文字符统一使用FontMetrics计算。
对于自动折行且自适应列宽的单元格则分别计算每一段文本宽度取最大值,这也是为什么不直接调用FontMetrics.stringWidth(java.lang.String)
的原因因为它并不会分段计算
本方法计算的宽度在某些字体下计算出来的结果与实际显示效果可能有很大偏差,此时可以覆写本方法并进行特殊计算
s - 文本xf - 单元格样式索引public static boolean isFirstMergedCell(List<Dimension> mergeCells, int row, int col)
Grid.test(int, int) to determine yes before calling this methodmergeCells - all merged cellsrow - the cell rowcol - the cell columnpublic double getHeaderHeight(Column[][] columnsArray, int row)
columnsArray - the header column arrayrow - actual rows in Excelprotected boolean hasMedia()
protected void initDrawingsWriter()
throws IOException
IOException - if I/O error occurpublic IDrawingsWriter createDrawingsWriter()
IDrawingsWriterpublic void downloadRemoteResource(Picture picture, String url) throws IOException
HttpURLConnection to synchronously download remote resources.
For more complex scenarios (asynchronous download, Connection pool, authentication, FTP, etc.), please override this methodpicture - Picture infourl - remote urlIOException - if I/O error occur.public void downloadCompleted(Picture picture, byte[] body) throws IOException
Picture.idx to idlepicture - Picture infobody - thr resource dataIOException - if I/O error occur.protected void writePictureDirect(int id,
String name,
int column,
int row,
FileSignatures.Signature signature)
throws IOException
IOExceptionprotected Picture createPicture(int column, int row)
column - cell columnrow - cell rowPictureprotected void collectHeaderColumns()
protected Font getFont(int xf)
FontMetrics用以计算文本宽度xf - 单元格样式索引protected Column getColumn(int index)
index - 列下标(从0开始)null)Copyright © 2024. All rights reserved.