From 905e57c8da44cd8b6a843bfd5a25a1ddef3f8b05 Mon Sep 17 00:00:00 2001 From: velios Date: Fri, 27 Oct 2023 15:14:58 +0300 Subject: [PATCH 1/3] fix --- .gitignore | 3 ++- project.clj | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4fa0acd..0d5e37e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ pom.xml.asc .lsp/ settings.xml settings2.xml -.DS_Store \ No newline at end of file +.DS_Store +.idea \ No newline at end of file diff --git a/project.clj b/project.clj index 0c76fa0..f6c2774 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.github.kbosompem/bb-excel "0.0.6" +(defproject com.github.kbosompem/bb-excel "0.0.6-SNAPSHOT" :description "A Simple Clojure/Babashka Library for Reading Data from Excel Files" :url "https://github.com/kbosompem/bb-excel" :license {:name "EPL-2.0" From e249ad0b6942db3041adcf5138f7df19741ac29e Mon Sep 17 00:00:00 2001 From: velios Date: Fri, 27 Oct 2023 17:12:55 +0300 Subject: [PATCH 2/3] fix --- .gitignore | 3 ++- CHANGELOG.md | 6 ++++++ project.clj | 2 +- src/bb_excel/core.clj | 18 +++++++++++------- test/core_test.clj | 5 +++++ test/data/without_sharedfiles.xlsx | Bin 0 -> 5184 bytes 6 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 test/data/without_sharedfiles.xlsx diff --git a/.gitignore b/.gitignore index 0d5e37e..719a12c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ pom.xml.asc settings.xml settings2.xml .DS_Store -.idea \ No newline at end of file +.idea +*.iml \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dc2200..460e2aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +0.0.7 / 2023-10-27 +------------------ +- Changed + - Fix parse xlsx without xl/sharedStrings.xml + - Fix parse cell with number and inlineStr data types + 0.0.6 / 2023-09-16 ------------------ - Changed diff --git a/project.clj b/project.clj index f6c2774..bd9308c 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.github.kbosompem/bb-excel "0.0.6-SNAPSHOT" +(defproject com.github.kbosompem/bb-excel "0.0.7" :description "A Simple Clojure/Babashka Library for Reading Data from Excel Files" :url "https://github.com/kbosompem/bb-excel" :license {:name "EPL-2.0" diff --git a/src/bb_excel/core.clj b/src/bb_excel/core.clj index d3c71fc..6d96875 100644 --- a/src/bb_excel/core.clj +++ b/src/bb_excel/core.clj @@ -138,10 +138,13 @@ (assoc :x row) (assoc :y col))] (cond + ;; Possible data types well explained here https://stackoverflow.com/a/18346273 (= (:t u) "s") (dissoc (assoc-in u [:d] (dict (read-string (:d u)))) :t) (= (:t u) "str") (dissoc u :t) + (= (:t u) "inlineStr") (dissoc u :t) (= (:t u) "b") (dissoc (assoc-in u [:d] (if (= "1" (:d u)) true false)) :t) (= (:t u) "e") (assoc-in u [:d] (error-codes (:d u))) + (= (:t u) "n") (assoc u :d (parse-long (:d u))) (style-check u styles pcts) (assoc-in u [:d] (num2pct (:d u))) (style-check u styles dates) (assoc-in u [:d] (num2date (:d u))) (style-check u styles times) (assoc-in u [:d] (num2time (:d u))) @@ -169,13 +172,14 @@ (defn get-unique-strings "Get dictionary of all unique strings in the Excel spreadsheet" [^ZipFile zipfile] - (let [wb (.getEntry zipfile (str "xl/sharedStrings.xml")) - ins (.getInputStream zipfile wb) - x (parse-str (slurp ins))] - (->> - (filter #((:text-part tags) (:tag %)) (xml-seq x)) - (map get-cell-text) - (zipmap (range))))) + (if-let [wb (.getEntry zipfile (str "xl/sharedStrings.xml"))] + (let [ins (.getInputStream zipfile wb) + x (parse-str (slurp ins))] + (->> + (filter #((:text-part tags) (:tag %)) (xml-seq x)) + (map get-cell-text) + (zipmap (range)))) + {})) (defn get-styles "Get styles" diff --git a/test/core_test.clj b/test/core_test.clj index ddc75e9..682b2b0 100644 --- a/test/core_test.clj +++ b/test/core_test.clj @@ -49,6 +49,11 @@ (is (= '({:_r 10 :A "9" :B "TextData"}) (get-range (get-sheet "test/data/Types.xlsx" "Sheet1") "A10:B10"))))) +(deftest corner-cases-test + (testing "Without shared files" + (is (= '({:_r 1, :A 1}) + (get-sheet "test/data/without_sharedfiles.xlsx" 1))))) + (comment (run-tests) diff --git a/test/data/without_sharedfiles.xlsx b/test/data/without_sharedfiles.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..f52a2f0cdd4c6f3f39073a49e2410cf6fddb94c5 GIT binary patch literal 5184 zcmaJ_2Ut_xvIQd@3B4nzC?!%96p-Et9i$_@w*-@5qZ69+E?t2D0@4+vE1=R#LJ@*= zq&KOGz)ODLyK=qnI_Jwt@_m`TvuD;>vu1QP0O#omNJ&WvOz)c;6Pz&$+-ED8gF9SE z5PvUC=vN2apbp#gjfnGpSi_)XU)>ZwkfG)qklJ%%BbFx2;^pg&BsD9_Cy537?evN% zrhlPz+>6LmjZlFWn}MQYelmOKJ*PTYWovRX?!D4yq|Obr>na{yxL-WN?E!_k*+QXi zf{#4hqwjV?u)@?$2cYwl4&X^wwiJMIOdP=%>cY;n1QkZN2>Oogl-$!v8i#zoaYf*5 z35u!4w8v(XnQqG*?@e+HdvfJFq;%^9gU3ItVeMA>Q=Q^Vf;39G9GNQC9QPoP(T>ku znhutls&14}XDCyDZVXDt214ZYP(uY@)e6RlYHqxvFekJYK-w^CBhx89+zAf(&Pi#J zaycxz4|t1rO^#A6rhU>Vx6=L1^^oAgvP-dIy-t>N>%rZbL?y=KR?*M4ef*vEyJAc` z^NCzvqYH(`9(Kgvnbp5pK216(#eTr&FXxQXTR*u^Qx)`Ly+{MW-Bc-w2k{rEg#TV53fY*2)x_F^+SS4@qo|ZF(FB zeLAG(#}p-BrfMlXF(S7cWVp|pc}L>hu$zD@?;}h+*3|z=*M*^`D6?Y3B$L6|@_9Z4 zy^(zab4JLEfI1-+s>-mO2k`V3IpL(|OUTRQdflCJ-@#1hE3dtF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>^pr(TB2!5(&}LK4 zYe1`qD7>$ItnZj<+{G`mzbqZOEv3%Ntl7`58&nR-<5*>rAc*$)K^r%oY6<)LQ+cVx zUDYI$+mnUShW6tDG)hROdBm&9$A_1aPwyF!m-x);v+B&dBGeW9cdn>z4_<%B8bU32J1+*Ub`tO}Hz6&x} zghCJw5QLS%V^0UT1wN)t29i2$!qk&Tpv&dF54r=W)yD%rk#clJX~Mvob7AhauTQh9 z0Srl^46Yw&LCr^&i|u3XSFrXMM#xHGH*@R~0{9Vp23d)V9~7TxIb!r`KC^m~?ejlN z{OApDO9ipUP3U>Z+2o^*V6o*jj-gB%mVgHK*m9GcWRiuuoZ=m#4akUcv*!~~&jyUL zI2h8<%#}wH5O>M+^QLMe z%TieTIooW{38SRAp1Qr*d$s^?GBC3=JXo~x4PJk@*qe;d_GJ=$Vz5n+ zXcJsgGcHDuV_WZk@nf?6fc(&)oPeXni3vR1FW+Q((pKWIFfcR}% zIKsp^|Jfw}xxiUHiSK!STP5z0xCMT9K!3WPRb6<&`P-m4qQ<%Y7y0?;I%nw}uhD*6 zFxkHX@E?lp&sEN{5WW=rHapz8{-ZGb>3;T^!&B97JBLfkzufA$3ygnH!(H5B Y|IbsZt3gDJ-+~Nx$>4Z%?VrE=KX5wBIsgCw literal 0 HcmV?d00001 From eeeb00a631b28bae3a994a197ad1ba2afb1937ec Mon Sep 17 00:00:00 2001 From: velios Date: Fri, 27 Oct 2023 17:19:34 +0300 Subject: [PATCH 3/3] fix --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 719a12c..9a62847 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ settings.xml settings2.xml .DS_Store .idea -*.iml \ No newline at end of file +*.iml