diff --git a/src/main/java/com/github/jlangch/venice/impl/docgen/cheatsheet/modules/ModuleExcelSection.java b/src/main/java/com/github/jlangch/venice/impl/docgen/cheatsheet/modules/ModuleExcelSection.java index 34ec81db7..f240fa90c 100644 --- a/src/main/java/com/github/jlangch/venice/impl/docgen/cheatsheet/modules/ModuleExcelSection.java +++ b/src/main/java/com/github/jlangch/venice/impl/docgen/cheatsheet/modules/ModuleExcelSection.java @@ -138,6 +138,7 @@ public DocSection section() { formulas.addItem(diBuilder.getDocItem("excel/cell-formula", false)); formulas.addItem(diBuilder.getDocItem("excel/sum-formula", false)); formulas.addItem(diBuilder.getDocItem("excel/evaluate-formulas", false)); + formulas.addItem(diBuilder.getDocItem("excel/remove-formula", false)); final DocSection style = new DocSection("Styles", id()); all.addSection(style); @@ -157,6 +158,14 @@ public DocSection section() { all.addSection(image); image.addItem(diBuilder.getDocItem("excel/add-image", false)); + final DocSection comments = new DocSection("Comments", id()); + all.addSection(comments); + comments.addItem(diBuilder.getDocItem("excel/remove-comment", false)); + + final DocSection hyperlink = new DocSection("Hyperlinks", id()); + all.addSection(hyperlink); + hyperlink.addItem(diBuilder.getDocItem("excel/remove-hyperlink", false)); + final DocSection charts = new DocSection("Charts", id()); all.addSection(charts); charts.addItem(diBuilder.getDocItem("excel/add-line-chart", false)); diff --git a/src/main/java/com/github/jlangch/venice/impl/util/excel/ExcelSheet.java b/src/main/java/com/github/jlangch/venice/impl/util/excel/ExcelSheet.java index ae8d8daaa..ce4071d1f 100644 --- a/src/main/java/com/github/jlangch/venice/impl/util/excel/ExcelSheet.java +++ b/src/main/java/com/github/jlangch/venice/impl/util/excel/ExcelSheet.java @@ -835,6 +835,27 @@ public void setFormula(final int row, final int col, final String formula, final } } + public void removeFormula(final int row, final int col) { + final Cell cell = getCell(row, col); + if (cell != null) { + cell.removeFormula(); + } + } + + public void removeHyperlink(final int row, final int col) { + final Cell cell = getCell(row, col); + if (cell != null) { + cell.removeHyperlink(); + } + } + + public void removeComment(final int row, final int col) { + final Cell cell = getCell(row, col); + if (cell != null) { + cell.removeCellComment(); + } + } + public Map getCellStyleInfo(final int row, final int col) { final Map info = new LinkedHashMap<>(); diff --git a/src/main/java/com/github/jlangch/venice/util/excel/ExcelSheetFacade.java b/src/main/java/com/github/jlangch/venice/util/excel/ExcelSheetFacade.java index f3c8d0f5c..f00b3ebcf 100644 --- a/src/main/java/com/github/jlangch/venice/util/excel/ExcelSheetFacade.java +++ b/src/main/java/com/github/jlangch/venice/util/excel/ExcelSheetFacade.java @@ -589,6 +589,18 @@ public Map getCellStyleInfo(final int row1, final int col1) { return sheet.getCellStyleInfo(row1-1, col1-1); } + public void removeFormula(final int row1, final int col1) { + sheet.removeFormula(row1-1, col1-1); + } + + public void removeHyperlink(final int row1, final int col1) { + sheet.removeHyperlink(row1-1, col1-1); + } + + public void removeComment(final int row1, final int col1) { + sheet.removeComment(row1-1, col1-1); + } + // ------------------------------------------------------------------------ // Reader functions diff --git a/src/main/resources/com/github/jlangch/venice/excel.venice b/src/main/resources/com/github/jlangch/venice/excel.venice index 95b945956..e3bbe5179 100644 --- a/src/main/resources/com/github/jlangch/venice/excel.venice +++ b/src/main/resources/com/github/jlangch/venice/excel.venice @@ -1617,7 +1617,6 @@ (. :PieDataSeries :new "" data-address-range)) - ;; ----------------------------------------------------------------------------- ;; Formulas ;; ----------------------------------------------------------------------------- @@ -1726,6 +1725,114 @@ (. sheet :sumFormula row-from row-to col-from col-to)) +(defn + ^{ :arglists '("(remove-formula sheet row col)") + :doc "Remove a cell formula" + :examples '( + """ + (do + (load-module :excel) + (let [data [ {:a 100 :b 200 } + {:a 101 :b 201 } + {:a 102 :b 202 } ] + wbook (excel/create :xlsx) + sheet (excel/add-sheet wbook "Sheet 1" { :no-header-row true })] + (excel/add-column sheet "A" { :field :a }) + (excel/add-column sheet "B" { :field :b }) + (excel/add-column sheet "C" { :field :c }) + (excel/write-items sheet data) + (excel/cell-formula sheet 1 3 (excel/sum-formula sheet 1 1 1 2)) + (excel/cell-formula sheet 2 3 (excel/sum-formula sheet 2 2 1 2)) + (excel/cell-formula sheet 3 3 (excel/sum-formula sheet 3 3 1 2)) + (excel/remove-formula sheet 1 3) + (excel/evaluate-formulas wbook) + (excel/auto-size-columns sheet) + (excel/write->file wbook "sample.xlsx"))) + """ ) + :see-also '( + "excel/remove-comment" + "excel/remove-hyperlink") } + + remove-formula [sheet row col] + + { :pre [(instance-of? :ExcelSheetFacade sheet) + (long? row) (long? row) + (long? col) (long? col)] } + + (. sheet :removeFormula row col)) + + + +;; ----------------------------------------------------------------------------- +;; Comments +;; ----------------------------------------------------------------------------- + +(defn + ^{ :arglists '("(remove-comment sheet row col)") + :doc "Remove a cell comment" + :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" 45) + (excel/write-values sheet 2 1 "Sue" "Ford" 26) + (excel/remove-comment sheet 1 1) + (excel/auto-size-columns sheet) + (excel/write->file wbook "sample.xlsx"))) + """ ) + :see-also '( + "excel/remove-formula" + "excel/remove-hyperlink") } + + remove-comment [sheet row col] + + { :pre [(instance-of? :ExcelSheetFacade sheet) + (long? row) (long? row) + (long? col) (long? col)] } + + (. sheet :removeComment row col)) + + + +;; ----------------------------------------------------------------------------- +;; Hyperlinks +;; ----------------------------------------------------------------------------- + +(defn + ^{ :arglists '("(remove-hyperlink sheet row col)") + :doc "Remove a cell comment" + :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" 45) + (excel/write-values sheet 2 1 "Sue" "Ford" 26) + (excel/remove-hyperlink sheet 1 1) + (excel/auto-size-columns sheet) + (excel/write->file wbook "sample.xlsx"))) + """ ) + :see-also '( + "excel/remove-comment" + "excel/remove-formula") } + + remove-hyperlink [sheet row col] + + { :pre [(instance-of? :ExcelSheetFacade sheet) + (long? row) (long? row) + (long? col) (long? col)] } + + (. sheet :removeHyperlink row col)) + + + +;; ----------------------------------------------------------------------------- +;; Utils +;; ----------------------------------------------------------------------------- + (defn ^{ :arglists '("(cell-address sheet row col)") :doc "Returns the cell address in A1 style for a cell at row/col in a sheet"