Skip to content

Commit

Permalink
added function cell-lock to :excel module
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Sep 10, 2024
1 parent 9e7dd80 commit bb75fdb
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 25 deletions.
10 changes: 9 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file.



## [1.12.34] - 2024-09-xx
## [1.12.35] - 2024-09-xx

### Added

Expand All @@ -16,10 +16,18 @@ All notable changes to this project will be documented in this file.
- :openai module support for assistant run api (...)
- :openai module support for assistant run steps api (...)




## [1.12.34] - 2024-09-10

### Added

- function `add-url-hyperlink` to :excel module
- function `add-email-hyperlink` to :excel module
- function `remove-hyperlink` to :excel module
- function `remove-formula` to :excel module
- function `cell-lock` to :excel module



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public DocSection section() {
final DocSection cells = new DocSection("Cells", id());
all.addSection(cells);
cells.addItem(diBuilder.getDocItem("excel/cell-empty?", false));
cells.addItem(diBuilder.getDocItem("excel/cell-lock", false));
cells.addItem(diBuilder.getDocItem("excel/cell-locked?", false));
cells.addItem(diBuilder.getDocItem("excel/cell-hidden?", false));
cells.addItem(diBuilder.getDocItem("excel/cell-type", false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public CellStyle getCellStyle(final String name) {
return (name != null) ? cellStyles.get(name) : null;
}

public CellStyle createCellStyle() {
return workbook.createCellStyle();
}

public Font getFont(final CellStyle style) {
return style == null ? null : workbook.getFontAt(style.getFontIndex());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,32 @@ public String getDataFormatString(final int row, final int col) {
return getDataFormatString(cell);
}

public void lock(final int row, final int col, final boolean locked) {
final Cell cell = getCell(row, col);
if (cell != null) {
final CellStyle lockedCellStyle = cellStyles.createCellStyle();
lockedCellStyle.cloneStyleFrom(cell.getCellStyle());
lockedCellStyle.setLocked(locked);
cell.setCellStyle(lockedCellStyle);
}
}

public boolean isLocked(final int row, final int col) {
final Cell cell = getCell(row, col);
return isLocked(cell);
if (cell == null) {
return false;
}
final CellStyle style = cell.getCellStyle();
return style == null ? false : style.getLocked();
}

public boolean isHidden(final int row, final int col) {
final Cell cell = getCell(row, col);
return isHidden(cell);
if (cell == null) {
return false;
}
final CellStyle style = cell.getCellStyle();
return style == null ? false : style.getHidden();
}

public boolean isColumnHidden(final int col) {
Expand Down Expand Up @@ -1317,24 +1335,6 @@ private String getDataFormatString(final Cell cell) {
return style.getDataFormatString();
}

private boolean isLocked(final Cell cell) {
if (cell == null) {
return false;
}

final CellStyle style = cell.getCellStyle();
return style == null ? false : style.getLocked();
}

private boolean isHidden(final Cell cell) {
if (cell == null) {
return false;
}

final CellStyle style = cell.getCellStyle();
return style == null ? false : style.getHidden();
}

public String getCellType(final CellType type) {
if (type == CellType.BLANK) {
return "blank";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public String getCellType(final int row1, final int col1) {
return sheet.getCellType(row1-1, col1-1);
}

public void lock(final int row1, final int col1, final boolean locked) {
sheet.lock(row1-1, col1-1, locked);
}

public boolean isLocked(final int row1, final int col1) {
return sheet.isLocked(row1-1, col1-1);
}
Expand Down
63 changes: 59 additions & 4 deletions src/main/resources/com/github/jlangch/venice/excel.venice
Original file line number Diff line number Diff line change
Expand Up @@ -3674,11 +3674,57 @@
(. sheet :getErrorCode row col))


(defn
^{ :arglists '("(cell-lock sheet row col locked?)")
:doc
"""
Locks/unlocks a cell.

Note: Excel locks new cells by default.
"""
:examples '(
"""
(do
(load-module :excel)

(let [wbook (excel/create :xlsx)
sheet (excel/add-sheet wbook "Sheet 1")]
(excel/write-values sheet 1 1 "John" "Doe" 28)
(excel/cell-lock sheet 1 1 false)
(excel/cell-lock sheet 1 2 false)
(excel/cell-lock sheet 1 3 true)
(excel/auto-size-columns sheet)
(excel/write->file wbook "sample.xlsx"))

(let [wbook (excel/open "sample.xlsx")
sheet (excel/sheet wbook "Sheet 1")]
[(excel/cell-locked? sheet 1 1)
(excel/cell-locked? sheet 1 2)
(excel/cell-locked? sheet 1 3)]))
""" )
:see-also '(
"excel/cell-locked?",
"excel/cell-hidden?",
"excel/cell-empty?",
"excel/cell-type" ) }

cell-lock [sheet row col locked?]

{ :pre [(instance-of? :ExcelSheetFacade sheet)
(long? row) (pos? row)
(long? col) (pos? col)
(boolean? locked?)] }

(. sheet :lock row col locked?))


(defn
^{ :arglists '("(cell-locked? sheet row col)")
:doc
"""
Returns true if the sheet cell is locked else false.

Note: Excel locks new cells by default.
"""
:examples '(
"""
Expand All @@ -3688,20 +3734,28 @@
(let [wbook (excel/create :xlsx)
sheet (excel/add-sheet wbook "Sheet 1")]
(excel/write-values sheet 1 1 "John" "Doe" 28)
(excel/cell-lock sheet 1 1 false)
(excel/cell-lock sheet 1 2 false)
(excel/cell-lock sheet 1 3 true)
(excel/auto-size-columns sheet)
(excel/write->file wbook "sample.xlsx"))

(let [wbook (excel/open "sample.xlsx")
sheet (excel/sheet wbook "Sheet 1")]
(excel/cell-locked? sheet 1 1)))
[(excel/cell-locked? sheet 1 1)
(excel/cell-locked? sheet 1 2)
(excel/cell-locked? sheet 1 3)]))
""" )
:see-also '(
"excel/cell-hidden?", "excel/cell-empty?", "excel/cell-type" ) }
"excel/cell-lock",
"excel/cell-empty?",
"excel/cell-type" ) }

cell-locked? [sheet row col]

{ :pre [(instance-of? :ExcelSheetFacade sheet)
(long? row) (long? col) (pos? row) (pos? col)] }
(long? row) (pos? row)
(long? col) (pos? col)] }

(. sheet :isLocked row col))

Expand Down Expand Up @@ -3733,7 +3787,8 @@
cell-hidden? [sheet row col]

{ :pre [(instance-of? :ExcelSheetFacade sheet)
(long? row) (long? col) (pos? row) (pos? col)] }
(long? row) (pos? row)
(long? col) (pos? col)] }

(. sheet :isHidden row col))

Expand Down

0 comments on commit bb75fdb

Please sign in to comment.