Skip to content
Snippets Groups Projects
Unverified Commit 5252d8c4 authored by Noah Moss's avatar Noah Moss Committed by GitHub
Browse files

Cap XLSX column widths at 255 characters (#18535)

parent a48733a0
Branches
Tags
No related merge requests found
......@@ -428,12 +428,17 @@
This ensures the cells in the header row have enough room for the filter dropdown icon."
(* 4 256))
(def ^:private max-column-width
"Cap column widths at 255 characters"
(* 255 256))
(defn- autosize-columns!
"Adjusts each column to fit its largest value, plus a constant amount of extra padding."
[sheet]
(doseq [i (.getTrackedColumnsForAutoSizing ^SXSSFSheet sheet)]
(.autoSizeColumn ^SXSSFSheet sheet i)
(.setColumnWidth ^SXSSFSheet sheet i (+ (.getColumnWidth ^SXSSFSheet sheet i) extra-column-width))
(.setColumnWidth ^SXSSFSheet sheet i (min max-column-width
(+ (.getColumnWidth ^SXSSFSheet sheet i) extra-column-width)))
(.untrackColumnForAutoSizing ^SXSSFSheet sheet i)))
(defn- setup-header-row!
......
......@@ -451,4 +451,10 @@
{}
[["abcdef"] ["abcedf"] ["abcdef"]]
parse-column-width))]
(is (<= 2800 col-width 2900))))))
(is (<= 2800 col-width 2900)))))
(testing "An auto-sized column does not exceed max-column-width (the width of 255 characters)"
(let [[col-width] (second (xlsx-export [{:id 0, :name "Col1"}]
{}
[[(apply str (repeat 256 "0"))]]
parse-column-width))]
(is (= 65280 col-width)))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment