Class JxlsSheet
×News: XavaPro 7.7 released - March 11 · Read more
java.lang.Object
org.openxava.util.jxls.JxlsSheet
- All Implemented Interfaces:
JxlsConstants
JxlsSheet: a class to wrap and simplify the use of Apache POI Sheet in the context of OpenXava
Principle:
As per Excel, the rows and colums start at 1
Types of cells:
Date, Number, Formulas and Text
Formulas can be encoded as
Excel: A1, $A1, A$1, $A$1, R1C1 (R[-1]C1 is not implemented)
Jxls: R1C1, $R1C1, R1$C1, $R1$C1
and they can start with =
Usage:
JxlsWorkbook wb = new JxlsWorkbook("Test");
JxlsSheet sheet = wb.addSheet("Test");
sheet.setValue(3, 4, "Pi", wb.addStyle(TEXT).setAlign(CENTER).setBold());
sheet.setValue(4, 4, 3.141592654, wb.addStyle(FLOAT).setAllBorders(THIN_BORDER));
sheet.setFormula(4, 5, "=2*$R4$C4", wb.addStyle("##0.0000"));
sheet.setFormula(4, 6, "=2*R4C4", wb.addStyle("##0.000"));
- Author:
- Laurent Wibaux
-
Field Summary
Fields inherited from interface JxlsConstants
ALL, AUTO_SIZE, BLACK, BLUE, BOLD, BORDER_NONE, BORDER_THICK, BORDER_THIN, BOTTOM, CENTER, DATE, EMPTY, FLOAT, GREEN, INTEGER, LEFT, LEFT_RIGHT, LIGHT_GREEN, LIGHT_GREY, LIGHT_YELLOW, NONE, PLAIN, RED, RIGHT, TEXT, TOP, TOP_BOTTOM, WHITE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJxlsSheet(JxlsWorkbook workbook, String name) protectedJxlsSheet(JxlsWorkbook workbook, String name, int index) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcreatePOISheet(JxlsWorkbook workbook, org.apache.poi.ss.usermodel.Workbook wb) getCell(int column, int row) Gets the JxlsCell contained in the cell at position column,rowintGets the row number of the bottom most celldoublegetNumericValue(int column, int row) Gets the numeric value contained in the cell at position column,rowgetStringValue(int column, int row) Gets the string value contained in the cell at position column,rowgetValue(int column, int row) Gets the object value contained in the cell at position column,rowprotected JxlsCellsetColumnStyles(int column, JxlsStyle... styles) Sets the width of one or more columnssetColumnWidths(int column, int... widths) Sets the width of one or more columnssetFormula(int column, int row, String formula) Sets the formula at column,rowsheet.setFormula(1, 1, "=A1+$A2+$R1C3+R1$C4");setFormula(int column, int row, String formula, JxlsStyle style) Sets the formula at column,rowsheet.setFormula(1, 1, "=A1+$A2+$R1C3+R1$C4");setFreezePane(int columnSplit, int rowSplit) Sets the freeze pane of the sheetvoidsetHeaders(int startColumn, int row, JxlsStyle style, String... headers) Sets column headers Usage:// set the first column header as "Invoice" with style // do not set any header for the second column // set the third column as "Customer" with style and a width of 20 // set the fourth column as "Customer" with style, right alignment and a width of 10 setHeaders(1, 1, style, "Invoice", null, "Customer|20", "Cost|r", "Margin|r|10");Sets the value at column,rowSets the value at column,rowvoidSets multiple values in one rowsetZoom(int zoom) Sets the zoom percentage used to display the sheet
-
Constructor Details
-
JxlsSheet
-
JxlsSheet
-
-
Method Details
-
setColumnWidths
Sets the width of one or more columns- Parameters:
column- the index of the first column width to set (1 based)widths- the widths of the columns to set- Returns:
- the JxlsSheet to chain other settings
-
setColumnStyles
-
setFreezePane
Sets the freeze pane of the sheet- Parameters:
columnSplit- the column at which right the pane will freezerowSplit- the row under which the pane will freeze- Returns:
- the JxlsSheet to chain other settings
-
setZoom
Sets the zoom percentage used to display the sheet- Parameters:
zoom- the percentage (1 to 100)- Returns:
- the JxlsSheet to chain other settings
-
setHeaders
Sets column headers Usage:// set the first column header as "Invoice" with style // do not set any header for the second column // set the third column as "Customer" with style and a width of 20 // set the fourth column as "Customer" with style, right alignment and a width of 10 setHeaders(1, 1, style, "Invoice", null, "Customer|20", "Cost|r", "Margin|r|10");- Parameters:
startColumn- the column at which to start setting the headersrow- the row containing the headersstyle- the style to use for the headersheaders- a list of headers. The format for the headers is name[|align][|columnWidth]
-
setCell
-
setValues
Sets multiple values in one row- Parameters:
startColumn- the column at which to start setting the valuesrow- the row at which the values are setvalues- the values
-
setValue
-
setValue
Sets the value at column,row- Parameters:
column- the column of the cell to setrow- the column of the cell to setvalue- the value of the cell to setstyle- the style of the cell to set- Returns:
- the cell which as been set
-
setFormula
Sets the formula at column,rowsheet.setFormula(1, 1, "=A1+$A2+$R1C3+R1$C4");- Parameters:
column- the column of the cell to setrow- the column of the cell to setformula- the formula of the cell to set- Returns:
- the cell which as been set
-
setFormula
Sets the formula at column,rowsheet.setFormula(1, 1, "=A1+$A2+$R1C3+R1$C4");- Parameters:
column- the column of the cell to setrow- the column of the cell to setformula- the formula of the cell to setstyle- the style of the cell to set- Returns:
- the cell which as been set
-
getValue
Gets the object value contained in the cell at position column,row- Parameters:
column- the column of the cell to retrieverow- the row of the cell to retrieve- Returns:
- the value of the cell
-
getNumericValue
public double getNumericValue(int column, int row) Gets the numeric value contained in the cell at position column,row- Parameters:
column- the column of the cell to retrieverow- the row of the cell to retrieve- Returns:
- the value of the cell if a number, the time in ms for a date, 0 in other cases
-
getStringValue
Gets the string value contained in the cell at position column,row- Parameters:
column- the column of the cell to retrieverow- the row of the cell to retrieve- Returns:
- the value of the cell converted as a text
-
getCell
Gets the JxlsCell contained in the cell at position column,row- Parameters:
column- the column of the cell to retrieverow- the row of the cell to retrieve- Returns:
- the cell
-
getLastRowNumber
public int getLastRowNumber()Gets the row number of the bottom most cell- Returns:
- the row number
-
createPOISheet
-