Package org.jzy3d.io.xls
Class ExcelBuilder
- java.lang.Object
-
- org.jzy3d.io.xls.ExcelBuilder
-
- All Implemented Interfaces:
IExcelBuilder
- Direct Known Subclasses:
ExcelBuilderMultiSheet
public class ExcelBuilder extends Object implements IExcelBuilder
A utility wrapper around Apache POI Excel spreadsheet builder. Comments only supported on XLS type (no XLSX) To add new excel features, see
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExcelBuilder.Type
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.poi.ss.usermodel.FontboldFontstatic booleanCRASH_ON_CELL_OVERFLOWStates if the builder should throw an IllegalArgumentException or simply warn with a log once a cell index exceed max number of columns or row.protected org.apache.poi.ss.usermodel.CreationHelpercreateprotected intcurrentSheetIdprotected org.apache.poi.ss.usermodel.Drawingdrawingstatic intLAST_COLUMNstatic intLAST_ROWstatic intMAX_COLUMNThe max number of columns supported by an excel sheet (256="IV" column header)static intMAX_ROWThe max number of rows supported by an excel sheetprotected Map<Integer,org.apache.poi.ss.usermodel.Sheet>sheetsprotected ExcelBuilder.Typetypeprotected org.apache.poi.ss.usermodel.Workbookworkbook
-
Constructor Summary
Constructors Constructor Description ExcelBuilder()ExcelBuilder(String workbookFile)ExcelBuilder(org.apache.poi.ss.usermodel.Workbook workbook)ExcelBuilder(ExcelBuilder.Type type)ExcelBuilder(ExcelBuilder.Type type, String firstSheetName)ExcelBuilder(ExcelBuilder.Type type, String firstSheetName, org.apache.poi.ss.usermodel.Workbook workbook)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.poi.ss.usermodel.CommentaddComment(org.apache.poi.ss.usermodel.Cell cell, String text, int row, int col, int colWidth, int rowHeight)org.apache.poi.ss.usermodel.CommentbuildComment(String text, int row, int col, int colWidth, int rowHeight)Return a Comment.List<String>getAllSheetNames()Collection<org.apache.poi.ss.usermodel.Sheet>getAllSheets()org.apache.poi.ss.usermodel.FontgetBoldFont()org.apache.poi.ss.usermodel.CellgetCell(int i, int j)org.apache.poi.hssf.util.HSSFColorgetColor(byte r, byte g, byte b)org.apache.poi.hssf.util.HSSFColorgetColor(ByteColor color)org.apache.poi.ss.usermodel.CreationHelpergetCreationHelper()org.apache.poi.ss.usermodel.SheetgetCurrentSheet()intgetCurrentSheetId()org.apache.poi.hssf.usermodel.HSSFWorkbookgetHSSFWorkbook()org.apache.poi.ss.usermodel.CellgetOrCreateCell(int i, int j)protected org.apache.poi.ss.usermodel.RowgetOrCreateRow(int i)org.apache.poi.ss.usermodel.SheetgetSheet(String name)org.apache.poi.ss.usermodel.WorkbookgetWorkbook()org.apache.poi.xssf.usermodel.XSSFWorkbookgetXSSFWorkbook()static org.apache.poi.ss.usermodel.Workbookload(File file)static org.apache.poi.ss.usermodel.Workbookload(String file)intloadPicture(String image)CellStylesloadStyleSheet(String sheetName)voidmergeRange(int firstRow, int firstColumn, int lastRow, int lastColumn)org.apache.poi.ss.usermodel.CellStylenewCellStyle()Return a new cell style instance for the choosen workbookExcelBuilder.Type.org.apache.poi.ss.usermodel.CellStylenewColoredCellStyle(org.apache.poi.ss.usermodel.IndexedColors color)org.apache.poi.ss.usermodel.CellStylenewColoredCellStyle(ByteColor color)org.apache.poi.ss.usermodel.FontnewFont(int size)intnewSheet(int index, String name)org.apache.poi.ss.usermodel.SheetnewSheet(String name)voidsave(File file)voidsave(String file)voidsetActiveSheet(int order)Set currently displayed sheet (different fromsetCurrentSheet(java.lang.String)).org.apache.poi.ss.usermodel.CellsetCell(int row, int column, double value)org.apache.poi.ss.usermodel.CellsetCell(int row, int column, double value, org.apache.poi.ss.usermodel.CellStyle style)org.apache.poi.ss.usermodel.CellsetCell(int row, int column, String content)Set a cell text content with no styling information.org.apache.poi.ss.usermodel.CellsetCell(int row, int column, String content, org.apache.poi.ss.usermodel.CellStyle style)Set a cell content at the given indices, and apply the style if it is not null.org.apache.poi.ss.usermodel.CellsetCellFormula(int row, int column, String formula)voidsetColumnWidth(int column, int width)Set the width (in units of 1/256th of a character width)voidsetColumnWidthAuto(int column)org.apache.poi.ss.usermodel.SheetsetCurrentSheet(String name)voidsetCurrentSheet(org.apache.poi.ss.usermodel.Sheet s)Set current Sheet in which cell are set.voidsetCurrentSheetId(int s)voidsetFreezePane(int colSplit, int rowSplit)voidsetFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow)voidsetHyperlink(org.apache.poi.ss.usermodel.Cell cell, String link)voidsetPicture(int pictureIdx, int col1, int row1, boolean resize)voidsetRowHeight(int row, int height)voidsetSheetOrder(String name, int order)voidsetSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane)protected booleansheetInitialized(int index)protected booleanvalidateCellIndex(int row, int column, String content)Validate a cell index.
-
-
-
Field Detail
-
MAX_COLUMN
public static int MAX_COLUMN
The max number of columns supported by an excel sheet (256="IV" column header)
-
MAX_ROW
public static int MAX_ROW
The max number of rows supported by an excel sheet
-
LAST_COLUMN
public static int LAST_COLUMN
-
LAST_ROW
public static int LAST_ROW
-
CRASH_ON_CELL_OVERFLOW
public static boolean CRASH_ON_CELL_OVERFLOW
States if the builder should throw an IllegalArgumentException or simply warn with a log once a cell index exceed max number of columns or row.
-
type
protected ExcelBuilder.Type type
-
workbook
protected org.apache.poi.ss.usermodel.Workbook workbook
-
create
protected org.apache.poi.ss.usermodel.CreationHelper create
-
drawing
protected org.apache.poi.ss.usermodel.Drawing drawing
-
boldFont
protected org.apache.poi.ss.usermodel.Font boldFont
-
currentSheetId
protected int currentSheetId
-
-
Constructor Detail
-
ExcelBuilder
public ExcelBuilder()
-
ExcelBuilder
public ExcelBuilder(ExcelBuilder.Type type)
-
ExcelBuilder
public ExcelBuilder(ExcelBuilder.Type type, String firstSheetName)
-
ExcelBuilder
public ExcelBuilder(ExcelBuilder.Type type, String firstSheetName, org.apache.poi.ss.usermodel.Workbook workbook)
-
ExcelBuilder
public ExcelBuilder(String workbookFile) throws IOException
- Throws:
IOException
-
ExcelBuilder
public ExcelBuilder(org.apache.poi.ss.usermodel.Workbook workbook)
-
-
Method Detail
-
getWorkbook
public org.apache.poi.ss.usermodel.Workbook getWorkbook()
- Specified by:
getWorkbookin interfaceIExcelBuilder
-
getHSSFWorkbook
public org.apache.poi.hssf.usermodel.HSSFWorkbook getHSSFWorkbook()
-
getXSSFWorkbook
public org.apache.poi.xssf.usermodel.XSSFWorkbook getXSSFWorkbook()
-
setCell
public org.apache.poi.ss.usermodel.Cell setCell(int row, int column, String content, org.apache.poi.ss.usermodel.CellStyle style)Set a cell content at the given indices, and apply the style if it is not null. If row(i) does not exist yet, it is created, otherwise it is recycled. If cell(i,j) does not exist yet, it is created, otherwise it is recycled. Reminder: excel support a maximum of 65,536 rows and 256 columns per sheet- Specified by:
setCellin interfaceIExcelBuilder- Parameters:
row- row indexcolumn- column indexcontent- a string to display in the cellstyle- a style to apply to the cell- Returns:
- the created or retrieved cell in case additional stuff should be done on it.
-
validateCellIndex
protected boolean validateCellIndex(int row, int column, String content)Validate a cell index. If cell index is out of maximum number of rows/columns:- throws an
IllegalArgumentExceptionifCRASH_ON_CELL_OVERFLOWis set to true. - otherwise emit a log warning and return false to invalidate this cell.
- throws an
-
setCell
public org.apache.poi.ss.usermodel.Cell setCell(int row, int column, String content)Set a cell text content with no styling information.- Specified by:
setCellin interfaceIExcelBuilder
-
setCellFormula
public org.apache.poi.ss.usermodel.Cell setCellFormula(int row, int column, String formula)- Specified by:
setCellFormulain interfaceIExcelBuilder
-
setCell
public org.apache.poi.ss.usermodel.Cell setCell(int row, int column, double value)- Specified by:
setCellin interfaceIExcelBuilder
-
setCell
public org.apache.poi.ss.usermodel.Cell setCell(int row, int column, double value, org.apache.poi.ss.usermodel.CellStyle style)- Specified by:
setCellin interfaceIExcelBuilder
-
setHyperlink
public void setHyperlink(org.apache.poi.ss.usermodel.Cell cell, String link)
-
getSheet
public org.apache.poi.ss.usermodel.Sheet getSheet(String name)
-
setCurrentSheet
public org.apache.poi.ss.usermodel.Sheet setCurrentSheet(String name)
-
getCurrentSheet
public org.apache.poi.ss.usermodel.Sheet getCurrentSheet()
- Specified by:
getCurrentSheetin interfaceIExcelBuilder
-
getCurrentSheetId
public int getCurrentSheetId()
- Specified by:
getCurrentSheetIdin interfaceIExcelBuilder
-
setCurrentSheetId
public void setCurrentSheetId(int s)
- Specified by:
setCurrentSheetIdin interfaceIExcelBuilder
-
setCurrentSheet
public void setCurrentSheet(org.apache.poi.ss.usermodel.Sheet s)
Set current Sheet in which cell are set. Different fromsetActiveSheet(int).
-
setSheetOrder
public void setSheetOrder(String name, int order)
-
setActiveSheet
public void setActiveSheet(int order)
Set currently displayed sheet (different fromsetCurrentSheet(java.lang.String)).
-
newSheet
public int newSheet(int index, String name)- Specified by:
newSheetin interfaceIExcelBuilder
-
newSheet
public org.apache.poi.ss.usermodel.Sheet newSheet(String name)
-
getAllSheets
public Collection<org.apache.poi.ss.usermodel.Sheet> getAllSheets()
- Specified by:
getAllSheetsin interfaceIExcelBuilder
-
sheetInitialized
protected boolean sheetInitialized(int index)
-
setRowHeight
public void setRowHeight(int row, int height)- Specified by:
setRowHeightin interfaceIExcelBuilder
-
setColumnWidth
public void setColumnWidth(int column, int width)Set the width (in units of 1/256th of a character width)- Specified by:
setColumnWidthin interfaceIExcelBuilder
-
setColumnWidthAuto
public void setColumnWidthAuto(int column)
- Specified by:
setColumnWidthAutoin interfaceIExcelBuilder
-
setFreezePane
public void setFreezePane(int colSplit, int rowSplit)- Specified by:
setFreezePanein interfaceIExcelBuilder
-
setFreezePane
public void setFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow)- Specified by:
setFreezePanein interfaceIExcelBuilder
-
setSplitPane
public void setSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane)- Specified by:
setSplitPanein interfaceIExcelBuilder
-
mergeRange
public void mergeRange(int firstRow, int firstColumn, int lastRow, int lastColumn)- Specified by:
mergeRangein interfaceIExcelBuilder
-
newCellStyle
public org.apache.poi.ss.usermodel.CellStyle newCellStyle()
Return a new cell style instance for the choosen workbookExcelBuilder.Type.- Specified by:
newCellStylein interfaceIExcelBuilder
-
getOrCreateCell
public org.apache.poi.ss.usermodel.Cell getOrCreateCell(int i, int j)
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(int i, int j)
-
getOrCreateRow
protected org.apache.poi.ss.usermodel.Row getOrCreateRow(int i)
-
addComment
public org.apache.poi.ss.usermodel.Comment addComment(org.apache.poi.ss.usermodel.Cell cell, String text, int row, int col, int colWidth, int rowHeight)- Specified by:
addCommentin interfaceIExcelBuilder
-
buildComment
public org.apache.poi.ss.usermodel.Comment buildComment(String text, int row, int col, int colWidth, int rowHeight)
Return a Comment. Comments are supported only on XLS file (HSSF framework).- Parameters:
row-col-colWidth-rowHeight-- Returns:
-
newColoredCellStyle
public org.apache.poi.ss.usermodel.CellStyle newColoredCellStyle(ByteColor color)
- Specified by:
newColoredCellStylein interfaceIExcelBuilder
-
newColoredCellStyle
public org.apache.poi.ss.usermodel.CellStyle newColoredCellStyle(org.apache.poi.ss.usermodel.IndexedColors color)
- Specified by:
newColoredCellStylein interfaceIExcelBuilder
-
getColor
public org.apache.poi.hssf.util.HSSFColor getColor(ByteColor color)
- Specified by:
getColorin interfaceIExcelBuilder
-
getColor
public org.apache.poi.hssf.util.HSSFColor getColor(byte r, byte g, byte b)
-
loadPicture
public int loadPicture(String image) throws IOException
- Specified by:
loadPicturein interfaceIExcelBuilder- Throws:
IOException
-
setPicture
public void setPicture(int pictureIdx, int col1, int row1, boolean resize)- Specified by:
setPicturein interfaceIExcelBuilder
-
getBoldFont
public org.apache.poi.ss.usermodel.Font getBoldFont()
- Specified by:
getBoldFontin interfaceIExcelBuilder
-
newFont
public org.apache.poi.ss.usermodel.Font newFont(int size)
- Specified by:
newFontin interfaceIExcelBuilder
-
save
public void save(String file) throws IOException
- Specified by:
savein interfaceIExcelBuilder- Throws:
IOException
-
save
public void save(File file) throws IOException
- Specified by:
savein interfaceIExcelBuilder- Throws:
IOException
-
load
public static org.apache.poi.ss.usermodel.Workbook load(String file) throws IOException
- Throws:
IOException
-
load
public static org.apache.poi.ss.usermodel.Workbook load(File file) throws IOException
- Throws:
IOException
-
loadStyleSheet
public CellStyles loadStyleSheet(String sheetName)
-
getCreationHelper
public org.apache.poi.ss.usermodel.CreationHelper getCreationHelper()
-
-