Class Cell
(sheet, row, column) view, 0-based,
that holds no native resource. Get one with Sheet.cell(int, int).
Each accessor makes one or more engine calls; setDate(java.time.LocalDate) makes
several. For more than a few cells, use the bulk methods of Range:
Range.values(), Range.setValues(io.keikai.axyra.sheets.CellValue[][]), Range.setNumbers(double[])
and Range.setFormulas(java.lang.String[][]) make one engine call for the whole rectangle.
Cell c = sheet.cell(0, 0); // A1
c.setValue(CellValue.number(42));
sheet.cell(0, 1).setFormula("A1*2"); // B1
CellValue result = sheet.cell(0, 1).value(); // 84
String shown = c.formattedText(); // "42"
Creating a cell off the grid throws IndexOutOfBoundsException.
-
Method Summary
Modifier and TypeMethodDescriptionaddThreadedComment(String author, String text) Starts a new Excel 365 comment thread on this cell.addThreadedReply(String parentId, String author, String text) Reply to the thread containingparentId(a root or reply id; replies attach to the thread root, like Excel).voidclear()Clears this cell's value and formula.intcol()The 0-based column index.comment()Returns the cell's plain-text comment (Excel's note).Returns the rich-text runs of this cell's note.Returns the cell's value as a date and time, in the workbook's date system, with the day fraction rounded to the nearest second.Returns the cell's value as a date: the whole-day part of the serial, in the workbook's date system.The cell's display text: its value rendered through the cell style's number format under the workbook display locale (Workbook.setLocale(java.lang.String); default en-US).formula()Returns the cell's formula text, without the leading=.formulaLocalized(String locale) The cell's formula rendered inlocale's display form (translated function names +;separator), ornullfor a non-formula cell.Returns the cell's hyperlink.voidRemoves this cell's plain-text comment (note), if any.voidRemoves this cell's hyperlink, if any.booleanRemove the comment withid— a root id removes its whole thread, a reply id removes just that reply.intReturns the number of rich-text runs in this cell, or 0 when the cell is not rich text.richText()Returns the cell's rich text with per-run formatting.introw()The 0-based row index.voidsetComment(Comment comment) Attaches or replaces this cell's plain-text comment (note) with the author and text ofcomment.voidsetComment(String author, String text) Attaches a plain-text comment (Excel's note) to this cell, or replaces the existing one.booleansetCommentLayout(double widthPt, double heightPt, boolean visible) Sets the box of this cell's existing note: its size and whether it stays visible without hovering (Excel's "Show Comment").voidSets a date.voidsetDateTime(LocalDateTime dateTime) Sets a date and time.voidsetFormula(String formula) Sets this cell's formula.voidsetFormulaLocalized(String formula, String locale) Set the cell's formula written in a locale's display form — translated function names (e.g.voidsetHyperlink(Hyperlink link) Attaches a hyperlink to this cell, or replaces the existing one.voidsetHyperlink(String url) Attaches a hyperlink to this cell, or replaces the existing one.voidsetRichComment(String author, CommentRun... runs) Attaches a rich-text comment (note) to this cell, or replaces the existing one.voidsetRichText(RichText richText) Sets this cell to rich text: one string with per-run font overrides.voidReplaces this cell's style withstyle.booleansetThreadedCommentResolved(String id, boolean resolved) Resolves or reopens the thread containingid.voidSets this cell's value and drops any formula.style()Returns the cell's resolved style: the workbook default style for a cell that has none.Returns this cell's Excel 365 comment threads.value()Returns the cell's value.
-
Method Details
-
row
public int row()The 0-based row index. -
col
public int col()The 0-based column index. -
value
Returns the cell's value. A formula cell returns its current result; pending writes are recalculated first. For many cells, useRange.values().- Returns:
- the value;
CellValue.BLANKfor an empty cell, nevernull
-
formattedText
The cell's display text: its value rendered through the cell style's number format under the workbook display locale (Workbook.setLocale(java.lang.String); default en-US). Blank cells return an empty string.- Returns:
- the formatted text, never
null
-
setValue
Sets this cell's value and drops any formula. The cell keeps its style, comment and hyperlink.CellValue.BLANKornullclears the value. For many cells, useRange.setValues(io.keikai.axyra.sheets.CellValue[][]).- Parameters:
value- the new value, ornullfor blank- Throws:
IllegalArgumentException- ifvalueis aCellValue.Array
-
setDate
Sets a date. The value becomes the Excel serial fordatein the workbook's date system (1900 or 1904), and any formula is dropped. When the cell's number format isGeneral, it becomesyyyy-mm-dd; any other format is kept. In the 1900 system, a date before 1900-03-01 gets a serial one greater than Excel's, because Excel counts the non-existent 1900-02-29. Several engine calls: the value write, a style read and, when the format changes, a style write.- Parameters:
date- the date; must not benull
-
setDateTime
Sets a date and time. The serial counts days in the workbook's date system, plus the time of day as a fraction; seconds are kept and fractions of a second are dropped. Any formula is dropped. When the cell's number format isGeneral, it becomesyyyy-mm-dd hh:mm:ss; any other format is kept. Several engine calls, as forsetDate(java.time.LocalDate).- Parameters:
dateTime- the date and time, without a time zone; must not benull
-
dateValue
Returns the cell's value as a date: the whole-day part of the serial, in the workbook's date system. The number format is not checked, so any number converts.- Returns:
- the date, or
nullwhen the value is not a number
-
dateTimeValue
Returns the cell's value as a date and time, in the workbook's date system, with the day fraction rounded to the nearest second. The number format is not checked, so any number converts.- Returns:
- the date and time, or
nullwhen the value is not a number
-
formula
Returns the cell's formula text, without the leading=. It reads the same for a workbook built here and one opened from a file: without array-formula braces and without the_xlfn.prefixes the file format adds to newer functions. For many cells, useRange.formulas().- Returns:
- the formula, or
nullwhen the cell has no formula
-
setFormula
Sets this cell's formula. A leading=is optional; an empty string clears the formula and value. The cell keeps its style, comment and hyperlink. A formula that returns an array spills from this cell, as in Excel 365. For many cells, useRange.setFormulas(java.lang.String[][])orRange.setFormula(java.lang.String).- Parameters:
formula- the formula in en-US form; must not benull- Throws:
AxyraFormulaException- if the formula does not parse; the cell is not changedNullPointerException- ifformulaisnull
-
setFormulaLocalized
Set the cell's formula written in a locale's display form — translated function names (e.g. GermanSUMME, FrenchSOMME) and the;argument separator. It is translated to the en-US canonical form (English names,,separator) before storage.localeis a language tag such as"de"or"fr-FR"; an unknown locale stores the formula unchanged. Function names inside string literals are never translated. A leading=is optional.The language part of the tag picks the function names. German, French, Spanish, Italian, Portuguese and Dutch are translated, names with non-ASCII letters such as
ZÄHLENWENNincluded; any other language is stored unchanged. A number's decimal comma becomes a period (1,5is stored as1.5), except fores-MX,es-US,es-419,de-CH,de-LIandit-CH, which write a period. Every;outside a string literal or a quoted sheet name becomes,, including the row separator of an array constant.- Parameters:
formula- the formula in the locale's display formlocale- a language tag such as"de"or"fr-FR"- Throws:
AxyraFormulaException- if the translated formula does not parse
-
formulaLocalized
The cell's formula rendered inlocale's display form (translated function names +;separator), ornullfor a non-formula cell. The inverse ofsetFormulaLocalized(java.lang.String, java.lang.String), with the same languages; any other language returns the en-US form.- Parameters:
locale- a language tag such as"de"or"fr-FR"- Returns:
- the localized formula without a leading
=, ornullwhen the cell has no formula
-
clear
public void clear()Clears this cell's value and formula. The style, comment and hyperlink stay; seeremoveComment()andremoveHyperlink(). -
setRichText
Sets this cell to rich text: one string with per-run font overrides. Any formula is dropped; the cell keeps its style, comment and hyperlink. The plain value is the runs' text joined. Read it back withrichText().- Parameters:
richText- the text runs; must not benull
-
richText
Returns the cell's rich text with per-run formatting. The returned value can be passed back tosetRichText(io.keikai.axyra.sheets.content.RichText)unchanged.- Returns:
- a snapshot of the runs, or
nullwhen the cell is not rich text
-
richRunCount
public int richRunCount()Returns the number of rich-text runs in this cell, or 0 when the cell is not rich text. UseRange.contentFlags()to find rich-text cells in bulk. -
style
Returns the cell's resolved style: the workbook default style for a cell that has none. Two engine calls.- Returns:
- a snapshot; edit it with
toBuilder()and pass it tosetStyle(io.keikai.axyra.sheets.style.CellStyle)
-
setStyle
Replaces this cell's style withstyle. Attributes thatstyleleaves unset take their defaults; they are not merged with the old style. To change one attribute, start fromstyle().toBuilder(). For many cells, useRange.setStyle(io.keikai.axyra.sheets.style.CellStyle).- Parameters:
style- the style to apply; must not benull
-
comment
Returns the cell's plain-text comment (Excel's note). Threaded comments are read withthreadedComments().- Returns:
- a snapshot of the author and text, or
nullwhen the cell has no note
-
setComment
Attaches a plain-text comment (Excel's note) to this cell, or replaces the existing one. A replaced note keeps its box size, visibility, fill and text alignment; set them withsetCommentLayout(double, double, boolean). The cell's value is not changed. For per-run fonts usesetRichComment(java.lang.String, io.keikai.axyra.sheets.content.CommentRun...); for an Excel 365 conversation useaddThreadedComment(java.lang.String, java.lang.String).- Parameters:
author- the author name shown with the notetext- the note text
-
setCommentLayout
public boolean setCommentLayout(double widthPt, double heightPt, boolean visible) Sets the box of this cell's existing note: its size and whether it stays visible without hovering (Excel's "Show Comment"). Imported note geometry is regenerated from these values on the next save. Does nothing when the cell has no note.- Parameters:
widthPt- box width in points (1/72 inch)heightPt- box height in points (1/72 inch)visible-trueto show the note at all times- Returns:
trueif the cell had a note,falseotherwise
-
setComment
Attaches or replaces this cell's plain-text comment (note) with the author and text ofcomment. Same assetComment(String, String).- Parameters:
comment- the note; must not benull
-
setRichComment
Attaches a rich-text comment (note) to this cell, or replaces the existing one. EachCommentRuncarries per-run font overrides (ECMA-376 Part 1 §18.7.7). The note's plainComment.text()becomes the run texts joined. UsesetComment(String, String)for plain text.- Parameters:
author- the author name shown with the noteruns- the text runs, at least one- Throws:
AxyraException- when no runs are given or a run has empty text
-
commentRuns
Returns the rich-text runs of this cell's note.- Returns:
- a new list of runs; empty for a plain-text note, or
nullwhen the cell has no note
-
removeComment
public void removeComment()Removes this cell's plain-text comment (note), if any. Threaded comments are removed withremoveThreadedComment(java.lang.String). The value and style are not changed. -
threadedComments
Returns this cell's Excel 365 comment threads. Each rootThreadedCommentcarries its replies.- Returns:
- a new list; empty when the cell has no thread
-
addThreadedComment
Starts a new Excel 365 comment thread on this cell. The author is added to the workbook's list of persons when new. UsesetComment(String, String)for a classic note.- Parameters:
author- the author nametext- the comment text- Returns:
- the generated comment id, a GUID in braces; pass it to
addThreadedReply(java.lang.String, java.lang.String, java.lang.String)
-
addThreadedReply
Reply to the thread containingparentId(a root or reply id; replies attach to the thread root, like Excel).The id is looked up on the whole sheet, not only on this cell.
- Parameters:
parentId- the id of a comment in the threadauthor- the author nametext- the reply text- Returns:
- the new reply id, or
nullwhen no comment on this sheet hasparentId
-
setThreadedCommentResolved
Resolves or reopens the thread containingid.The id is looked up on the whole sheet, not only on this cell.
- Parameters:
id- the id of a comment in the threadresolved-trueto resolve,falseto reopen- Returns:
trueif a comment on this sheet hasid
-
removeThreadedComment
Remove the comment withid— a root id removes its whole thread, a reply id removes just that reply.The id is looked up on the whole sheet, not only on this cell.
- Parameters:
id- the id of the comment to remove- Returns:
trueif a comment was removed
-
hyperlink
Returns the cell's hyperlink. UseRange.contentFlags()to find linked cells in bulk.- Returns:
- a snapshot of the link, or
nullwhen the cell has none
-
setHyperlink
Attaches a hyperlink to this cell, or replaces the existing one. Same assetHyperlink(Hyperlink.url(url)). The cell's value is not changed, so set the value as well when the cell is empty.- Parameters:
url- the link address: a URL, a file path or an in-workbook reference such as"Sheet2!A1"
-
setHyperlink
Attaches a hyperlink to this cell, or replaces the existing one. The cell's value is not changed: the link's display text is stored with the link but is not written into the cell, so set the value as well when the cell is empty. The address may be a URL, a file path or an in-workbook reference such as"Sheet2!A1"; its kind is detected from the text.- Parameters:
link- the link; must not benull
-
removeHyperlink
public void removeHyperlink()Removes this cell's hyperlink, if any. The value and style are not changed. To remove many, useRange.clearHyperlinks().
-