From 76ceb71040106d5fc2fdf9d6ece61727bf9b7da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20V=C4=A9nh=20Thi=E1=BB=87n=20Ph=C3=BAc?= <143604440+tvtphuc-axonivy@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:15:48 +0700 Subject: [PATCH] MARP-1315 Excel Importer: Solution for adding cells with more than 255 chars (#66) --- .../util/excel/test/TestExcelReader.java | 14 ++++++++++++-- .../excel/test/sample_over_255_characters.xlsx | Bin 0 -> 10285 bytes .../util/excel/importer/ExcelReader.java | 5 ++++- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 excel-importer-test/src_test/com/axonivy/util/excel/test/sample_over_255_characters.xlsx diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestExcelReader.java b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestExcelReader.java index 5d0471e..1d6fe91 100644 --- a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestExcelReader.java +++ b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestExcelReader.java @@ -6,11 +6,9 @@ import java.nio.file.Path; import java.sql.Timestamp; import java.util.List; - import org.apache.poi.ss.usermodel.Workbook; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - import com.axonivy.util.excel.importer.Column; import com.axonivy.util.excel.importer.ExcelLoader; import com.axonivy.util.excel.importer.ExcelReader; @@ -33,5 +31,17 @@ void parseColumns_xlsx(@TempDir Path dir) throws IOException { new Column("Column contains both text and numeric", String.class, 255) ); } + + @Test + void parseColumnsOver255Characters_xlsx(@TempDir Path dir) throws IOException { + Path path = dir.resolve("customers.xlsx"); + TstRes.loadTo(path, "sample_over_255_characters.xlsx"); + Workbook wb = ExcelLoader.load(path); + List columns = ExcelReader.parseColumns(wb.getSheetAt(0)); + assertThat(columns).extracting(Column::getName).contains("FirstName", "LastName" , "Summary"); + assertThat(columns).contains(new Column("FirstName", String.class, 255), + new Column("LastName", String.class, 255), + new Column("Summary", String.class, 823)); + } } diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/sample_over_255_characters.xlsx b/excel-importer-test/src_test/com/axonivy/util/excel/test/sample_over_255_characters.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..61eb94f1ebd7f296c0927e11bf1df5bf200a5d02 GIT binary patch literal 10285 zcma)i1y~)+vNi4=+&AtPEQH{}-QC??g0peAKyVAeHMqOGy9al-ga^qzmUrI$|Nizj zvuC=ht7mo3n(nHSl>mo;19>Sy(i?m)=RXSU^B+SS16g|;TL(tjXEF5W8!$h`h$Cjw zSwKNRxWGU_Q2s8aXKTygYGs)g(=HCqjQ;+{?+K;SW)c&X`Zcv*@LOngCxX{D3vH5U z=jnn6wRLuYTj=iG{e)YW1J z5tCE^wMOBBTHhT~G~?EpoHE1?AR5$=xkG=1L&%E(Vjqzeu6Mjl>pok`C zy<;y3iY{c{(4IzDLRW%H#EYm;VWTPcDKJ6W#ly96;SPrGtHX&!4n}vvd8uk;E^?;$ z5(tX1{;sjgc<>Rt5!gU+t{Z%^rmiWW!4r}&67ixrH$Hy$((*_#FOkSTn!L@Y2Iz_6{4cOiY zKxdV6<&sw8(WBuJ>Yw;}>bZ0AJmahLj4$fn@inlqH+lg$B390#g9$xg75V|0{KQJW zge0q^95I6eVTO5LL$p+V<})Bf`RV(FvPF>loWb#%o5mgOSO%F&xJX?~wIYOWRDMt@ z?J)TxmP@(f4oJ9S1M%`g<>;)}s#QZoMDnH7Wr$5l>Oed4xwg3YTul?xlhiNR8ZFTM zmRke^VT%i*+mDln<;IUGM<6mVNd~Zyu-n+yzFCC9yME{%eEYxxE}u1Qn&`~bZaehN zlv&@H>(M}IoHs^$BMT>vA#aW0SHge~hJ)>MtWr~wjo3Wi;T#9EH`deTibo}!ncNtu z_TWR)6fPopH_+)DawW|=-NhOY3N{ibGCL_p+UHda9#Igex13eT-by@qqm12f-(InZ zb#Nky$w$AD(iiVjd3&egjaSClH~9F3vID6$HXl9`i+Tpvr{Hl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}ekV{JeUpQ4}XG=?Pk}qg|;+Ar}YQ{@?mz7HA3x|&t zf&!G6xg-SZ#<{7%Y*6`lPhH{&@6QvK9Qo6}_|0X?75FDB-!$p`iY)(oybbDkTcKlb zWchoX&7IS^>FK#{^*PoC|ECPYi)2acsCX9>O3#Vk3CebhlnVyxydxvYp_HMg&nL;J zF^X5QYDX>2{Bm?t4bV|ZciSne9)^v0%f#BuUm~0QoaFrYZ2FvAL2s$!%*OW=W%)ARvc1oH!)rhaWN)^XwH`PZ z?#UpOmE!JRp$T?xgtFrdXu7kpDLfcidzX|WIQp7)OED(R$ub%v9O#iV*NSrW9t!Hs zsJ#=<;E9WPP;rSdJ>q-KfKLjcOW!nG?dXzvHKmC{$uo!V_$DWJI@)8#HL38=|UkZpiZUAM7bCZzkFUZ+#*g7N!? zr-*SK-L*bFHX{hrT7;4dO|489>s+aVN`J^*E;c5LOFU1<_~ft9;R?;B0bV(NdT-98 z2HoaYNH9|@M$K&-SqVy8eh!L1Ea_QAGR`#Oiek@T+-Bq6{Fb3vVog3t9g!WMyIqk^ zk|tf{(tVT6k6)SF8ndQ2IRqsmTfxy`ZymytobTt2I|K$ zALcuLX~zPe9h+7M5VdWH)4|@myqk-W^3E#is{y#9k+mIqfd$XPy_Kt$n3`6)ri=Cq z1NIlX00l$;>2Lm(>ht@^JP!^CCUH$j`lfTq2pBdvX^*^&w{@X*pBw73_FApsX@sn=;o5DX)q6hqqpMLM? z??m=u=NC$fe^>iowDx;DzXvw{YA5{J)Aes*j^A7O-8uGG3!%^K@zTPduCo9CXIF#% zsrpA){+~1C_rUyL7JdG%_E(tx_b&hLz5T0!)aMMZ=Pv&pw*S`Ymn@lI(UUYwrTH628{VRt?Rs!;6dGMTlh6)1xEQdn&a`itu+vPF< literal 0 HcmV?d00001 diff --git a/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java b/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java index 5c9ffd4..1300ae1 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -91,7 +92,9 @@ private static void updateColumn(Column column, Cell cell) { } if (cell.getCellType() == CellType.STRING) { column.setType(String.class); - column.setDatabaseFieldLength(DEFAULT_STRING_LENGTH); + if (ObjectUtils.isEmpty(column.getDatabaseFieldLength())) { + column.setDatabaseFieldLength(DEFAULT_STRING_LENGTH); + } } if (column.getType().equals(String.class)) { var cellValue = getCellValueAsString(cell);