├── .gitignore ├── .travis.yml ├── .rultor.yml ├── settings.xml.asc ├── LICENSE.txt └── src ├── main └── java │ └── com │ └── vgv │ └── excel │ └── io │ ├── package-info.java │ ├── cells │ ├── package-info.java │ ├── AbstractStyleableCell.java │ ├── AbstractStyleableCells.java │ ├── TextCell.java │ ├── DateCell.java │ ├── NumberCell.java │ ├── FormulaCell.java │ ├── CalendarCell.java │ ├── TextCells.java │ ├── NumberCells.java │ ├── DateCells.java │ ├── FormulaCells.java │ ├── EmptyCell.java │ └── CalendarCells.java │ ├── props │ ├── package-info.java │ ├── row │ │ ├── package-info.java │ │ ├── ZeroHeight.java │ │ ├── Height.java │ │ └── HeightInPoints.java │ └── sheet │ │ ├── package-info.java │ │ ├── FitToPage.java │ │ ├── DefaultColumnWidth.java │ │ ├── MergedRegion.java │ │ ├── ColumnWidth.java │ │ ├── AutoSizeColumn.java │ │ └── DefaultRowHeight.java │ ├── styles │ ├── package-info.java │ ├── BorderTop.java │ ├── BorderLeft.java │ ├── BorderRight.java │ ├── BorderBottom.java │ ├── DataFormat.java │ ├── BackgroundColor.java │ ├── ForegroundColor.java │ ├── Hidden.java │ ├── Indention.java │ ├── Locked.java │ ├── Rotation.java │ ├── AlignHorizontal.java │ ├── FillPattern.java │ ├── AlignVertical.java │ ├── WrappedText.java │ └── QuotePrefixed.java │ ├── templates │ ├── package-info.java │ ├── CellTemplate.java │ ├── StyleTemplate.java │ └── RowTemplate.java │ ├── Props.java │ ├── Style.java │ ├── ESheet.java │ ├── ERow.java │ ├── XsProps.java │ ├── EWorkbook.java │ ├── XsStyle.java │ ├── ECells.java │ └── ECell.java └── test └── java └── com └── vgv └── excel └── io ├── package-info.java ├── cells ├── package-info.java ├── FormulaCellsTest.java ├── DateCellsTest.java ├── NumberCellsTest.java ├── CalendarCellsTest.java ├── EmptyCellTest.java ├── NumberCellTest.java ├── DateCellTest.java ├── FormulaCellTest.java └── CalendarCellTest.java ├── props ├── package-info.java ├── row │ ├── package-info.java │ ├── ZeroHeightTest.java │ ├── HeightTest.java │ ├── HeightInPointsTest.java │ └── RowPropsTest.java └── sheet │ ├── package-info.java │ ├── ColumnWidthTest.java │ ├── DefaultColumnWidthTest.java │ └── SheetPropsTest.java ├── styles ├── package-info.java ├── HiddenTest.java ├── LockedTest.java ├── WrappedTextTest.java ├── QuotePrefixedTest.java ├── BorderTopTest.java ├── BorderLeftTest.java ├── BorderRightTest.java ├── RotationTest.java ├── BorderBottomTest.java ├── IndentionTest.java ├── DataFormatTest.java ├── AlignHorizontalTest.java ├── AlignVerticalTest.java └── BackgroundColorTest.java ├── templates └── package-info.java └── XsSheetTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea 3 | *.iml 4 | /bin 5 | .settings/ 6 | .classpath 7 | .project 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | jdk: 4 | - oraclejdk8 5 | script: 6 | - set -e 7 | - mvn clean install -Pqulice --errors --batch-mode 8 | after_success: 9 | - bash <(curl -s https://codecov.io/bash) 10 | -------------------------------------------------------------------------------- /.rultor.yml: -------------------------------------------------------------------------------- 1 | decrypt: 2 | settings.xml: "repo/settings.xml.asc" 3 | pubring.gpg: "repo/pubring.gpg.asc" 4 | secring.gpg: "repo/secring.gpg.asc" 5 | release: 6 | script: | 7 | mvn versions:set "-DnewVersion=${tag}" 8 | git commit -am "${tag}" 9 | mvn clean deploy -Pqulice -Psonatype -Pexcel-io --settings /home/r/settings.xml 10 | -------------------------------------------------------------------------------- /settings.xml.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP MESSAGE----- 2 | Version: GnuPG v1 3 | 4 | hQEMA5qETcGag5w6AQf9HcKdfoEAEFeOcrCeHADdz0Y0BmZa1KlwLRsUfDE6V4+J 5 | 0ZtUdubpyd5JVvHhOBJ6t8paN9Z3jYPC+DLvlP0z8/5wkm3bIQD7jpVs91eSGSnn 6 | LvUk/w9W+qbcfqhf5na9WejD+iwUBbPFsfoZ+uq7w+Eb1atoGgPyqSHBwGbS2qmQ 7 | bwl72xU4G5JCJ485WbEMNDChD0DM+9NCS9wCw5tKri2AlWHco/n/jsXH9dNrvY+9 8 | dIkzMfYdVyNGf+acmPVNnHTUf+OSa64HCzI/kG3vffv8Q2y5lPxAK3gFH/i5gKbm 9 | vW+ItoUpTV4YLVE2gKSOEtHYnFY5+ORzYJMFfLh0U9LBCwFsa7VhjpvZ9xxOiMQ1 10 | p45Fomp91zqZvZFsD4dZMVamsHd6f3flC5d2g7s63KApovEkwjT5aLl6Fy2+5n89 11 | oWtI2sNZ/rUnpCAQVmbkmbCFVh1BbwTlgGL5mleB7dR8nb6ZCEixH8P0tzC11WHv 12 | ZrM2k2+4a9yDOr9CQ1fkFmX84LfCIUMXFuldcMkF0dlip6jxlyRZeq2P7n50NQc+ 13 | G1Y82NedNxb4fzSGU9qa5U4n7JaP9Nmhv+pee3Ei0do/pMhAB5J7PpNnDhg/l2xb 14 | lzI1WkswoKx59PcyBRRMfsowXevGd/odOOZKH/pieT8XI86BWJbBg0cDw5IalnPz 15 | DH0k4M1J5EQS4lXVvzsCPgo0pPkIoBgkpgT5aIqlpOFeWiZiJuFebwyEM0XnFVla 16 | ++0sEobV/FpHAghXzmp0LEyN8ioRq0SBvcXbLr/MOTZVKxtXo4RtWpLcRLDc9wsw 17 | wka57AEczfMdcz/bs6o5Ek+A+mHVDxwWRGRzjZU7rpz4ch8L16E33/sxI7maOp86 18 | RlWru/unDrpx3TsYqjj3hzNHy/ij8KBuBPy888gvd9M2aMeC4e6iAqJQk9GJOJr/ 19 | 1Kbkt15hGTPP6bl8MQ== 20 | =WDcY 21 | -----END PGP MESSAGE----- 22 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Vedran Grgo Vatavuk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Styles. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io; 33 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Styles. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io; 33 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Cells. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.4 31 | */ 32 | package com.vgv.excel.io.cells; 33 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Cells. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.4 31 | */ 32 | package com.vgv.excel.io.cells; 33 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Properties. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io.props; 33 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Styles. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io.styles; 33 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Properties. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io.props; 33 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Styles. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io.styles; 33 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/templates/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Templates. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.4 31 | */ 32 | package com.vgv.excel.io.templates; 33 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/templates/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Templates. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.5 31 | */ 32 | package com.vgv.excel.io.templates; 33 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/row/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Row properties. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io.props.row; 33 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/row/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Row properties. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io.props.row; 33 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/sheet/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Sheet properties. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io.props.sheet; 33 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/sheet/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Sheet properties. 27 | * 28 | * @author Vedran Vatavuk (123vgv@gmail.com) 29 | * @version $Id$ 30 | * @since 0.1 31 | */ 32 | package com.vgv.excel.io.props.sheet; 33 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/Props.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io; 25 | 26 | import java.util.function.Consumer; 27 | 28 | /** 29 | * Properties. 30 | * @author Vedran Vatavuk (123vgv@gmail.com) 31 | * @version $Id$ 32 | * @param Props 33 | * @since 0.1 34 | */ 35 | public interface Props extends Consumer { 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/AbstractStyleableCell.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.vgv.excel.io.ECell; 27 | import com.vgv.excel.io.Style; 28 | 29 | /** 30 | * Cell which style can be edited. 31 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | abstract class AbstractStyleableCell implements ECell { 36 | 37 | @Override 38 | public final ECell with(final Style style) { 39 | return new ECell.WithStyle(this, style); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/AbstractStyleableCells.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.vgv.excel.io.ECells; 27 | import com.vgv.excel.io.Style; 28 | 29 | /** 30 | * Multiple cells which styles can be edited. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.3 34 | */ 35 | abstract class AbstractStyleableCells implements ECells { 36 | 37 | @Override 38 | public final ECells with(final Style style) { 39 | return new ECells.WithStyle(this, style); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/Style.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io; 25 | 26 | import org.apache.poi.ss.usermodel.Cell; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Cell Style. 31 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public interface Style { 36 | 37 | /** 38 | * Attach style to a cell. 39 | * @param cell Cell 40 | * @return Cell style 41 | */ 42 | CellStyle attachTo(Cell cell); 43 | 44 | /** 45 | * Add property to the style. 46 | * @param property Property 47 | * @return Style 48 | */ 49 | Style with(Props property); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/row/ZeroHeight.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.row; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Row; 28 | 29 | /** 30 | * Row zero height. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public final class ZeroHeight implements Props { 36 | 37 | /** 38 | * Zero height. 39 | */ 40 | private final boolean value; 41 | 42 | /** 43 | * Ctor. 44 | * @param zero Zero 45 | */ 46 | public ZeroHeight(final boolean zero) { 47 | this.value = zero; 48 | } 49 | 50 | @Override 51 | public void accept(final Row row) { 52 | row.setZeroHeight(this.value); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/sheet/FitToPage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | 29 | /** 30 | * Fit to page. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 1.0 34 | */ 35 | public final class FitToPage implements Props { 36 | 37 | /** 38 | * Fit to page. 39 | */ 40 | private final boolean value; 41 | 42 | /** 43 | * Ctor. 44 | * @param fit Fit to page 45 | */ 46 | public FitToPage(final boolean fit) { 47 | this.value = fit; 48 | } 49 | 50 | @Override 51 | public void accept(final Sheet sheet) { 52 | sheet.setFitToPage(this.value); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/row/Height.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.row; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Row; 28 | 29 | /** 30 | * Row height. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | @SuppressWarnings("PMD.AvoidUsingShortType") 36 | public final class Height implements Props { 37 | 38 | /** 39 | * Height. 40 | */ 41 | private final short value; 42 | 43 | /** 44 | * Ctor. 45 | * @param height Height 46 | */ 47 | public Height(final short height) { 48 | this.value = height; 49 | } 50 | 51 | @Override 52 | public void accept(final Row row) { 53 | row.setHeight(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/row/HeightInPoints.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.row; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Row; 28 | 29 | /** 30 | * Row height in points. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public final class HeightInPoints implements Props { 36 | 37 | /** 38 | * Height in points. 39 | */ 40 | private final float value; 41 | 42 | /** 43 | * Ctor. 44 | * @param points Points 45 | */ 46 | public HeightInPoints(final float points) { 47 | this.value = points; 48 | } 49 | 50 | @Override 51 | public void accept(final Row row) { 52 | row.setHeightInPoints(this.value); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/sheet/DefaultColumnWidth.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | 29 | /** 30 | * Default column width. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public final class DefaultColumnWidth implements Props { 36 | 37 | /** 38 | * Width in pixels. 39 | */ 40 | private final int width; 41 | 42 | /** 43 | * Ctor. 44 | * @param pixels Pixels 45 | */ 46 | public DefaultColumnWidth(final int pixels) { 47 | this.width = pixels; 48 | } 49 | 50 | @Override 51 | public void accept(final Sheet sheet) { 52 | sheet.setDefaultColumnWidth(this.width); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/BorderTop.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.BorderStyle; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | 30 | /** 31 | * Cell top border style. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.5 35 | */ 36 | public final class BorderTop implements Props { 37 | 38 | /** 39 | * Border. 40 | */ 41 | private final BorderStyle value; 42 | 43 | /** 44 | * Ctor. 45 | * @param style Style 46 | */ 47 | public BorderTop(final BorderStyle style) { 48 | this.value = style; 49 | } 50 | 51 | @Override 52 | public void accept(final CellStyle style) { 53 | style.setBorderTop(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/BorderLeft.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.BorderStyle; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | 30 | /** 31 | * Cell left border style. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.5 35 | */ 36 | public final class BorderLeft implements Props { 37 | 38 | /** 39 | * Border. 40 | */ 41 | private final BorderStyle value; 42 | 43 | /** 44 | * Ctor. 45 | * @param style Style 46 | */ 47 | public BorderLeft(final BorderStyle style) { 48 | this.value = style; 49 | } 50 | 51 | @Override 52 | public void accept(final CellStyle style) { 53 | style.setBorderLeft(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/BorderRight.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.BorderStyle; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | 30 | /** 31 | * Cell right border style. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.5 35 | */ 36 | public final class BorderRight implements Props { 37 | 38 | /** 39 | * Border. 40 | */ 41 | private final BorderStyle value; 42 | 43 | /** 44 | * Ctor. 45 | * @param style Style 46 | */ 47 | public BorderRight(final BorderStyle style) { 48 | this.value = style; 49 | } 50 | 51 | @Override 52 | public void accept(final CellStyle style) { 53 | style.setBorderRight(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/BorderBottom.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.BorderStyle; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | 30 | /** 31 | * Cell bottom border style. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.5 35 | */ 36 | public final class BorderBottom implements Props { 37 | 38 | /** 39 | * Border. 40 | */ 41 | private final BorderStyle value; 42 | 43 | /** 44 | * Ctor. 45 | * @param style Style 46 | */ 47 | public BorderBottom(final BorderStyle style) { 48 | this.value = style; 49 | } 50 | 51 | @Override 52 | public void accept(final CellStyle style) { 53 | style.setBorderBottom(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/DataFormat.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Cell data format. See apache POI class BuiltinFormats 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | @SuppressWarnings("PMD.AvoidUsingShortType") 36 | public final class DataFormat implements Props { 37 | 38 | /** 39 | * Format. 40 | */ 41 | private final short value; 42 | 43 | /** 44 | * Ctor. 45 | * @param format Format 46 | */ 47 | public DataFormat(final short format) { 48 | this.value = format; 49 | } 50 | 51 | @Override 52 | public void accept(final CellStyle style) { 53 | style.setDataFormat(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/sheet/MergedRegion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | import org.apache.poi.ss.util.CellRangeAddress; 29 | 30 | /** 31 | * Merged region. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 1.0 35 | */ 36 | public final class MergedRegion implements Props { 37 | 38 | /** 39 | * CellRangeAddress. 40 | */ 41 | private final CellRangeAddress value; 42 | 43 | /** 44 | * Ctor. 45 | * @param region Region 46 | */ 47 | public MergedRegion(final CellRangeAddress region) { 48 | this.value = region; 49 | } 50 | 51 | @Override 52 | public void accept(final Sheet sheet) { 53 | sheet.addMergedRegion(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/BackgroundColor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Background cell color. 31 | * 32 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.5 35 | */ 36 | @SuppressWarnings("PMD.AvoidUsingShortType") 37 | public final class BackgroundColor implements Props { 38 | 39 | /** 40 | * Color. 41 | */ 42 | private final short color; 43 | 44 | /** 45 | * Ctor. 46 | * @param rgb Rgb color value 47 | */ 48 | public BackgroundColor(final short rgb) { 49 | this.color = rgb; 50 | } 51 | 52 | @Override 53 | public void accept(final CellStyle style) { 54 | style.setFillBackgroundColor(this.color); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/ForegroundColor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Foreground cell color. 31 | * 32 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.1 35 | */ 36 | @SuppressWarnings("PMD.AvoidUsingShortType") 37 | public final class ForegroundColor implements Props { 38 | 39 | /** 40 | * Color. 41 | */ 42 | private final short color; 43 | 44 | /** 45 | * Ctor. 46 | * @param rgb Rgb color value 47 | */ 48 | public ForegroundColor(final short rgb) { 49 | this.color = rgb; 50 | } 51 | 52 | @Override 53 | public void accept(final CellStyle style) { 54 | style.setFillForegroundColor(this.color); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/Hidden.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Hidden cell. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.5 34 | */ 35 | public final class Hidden implements Props { 36 | 37 | /** 38 | * Is hidden value. 39 | */ 40 | private final boolean value; 41 | 42 | /** 43 | * Ctor. 44 | */ 45 | public Hidden() { 46 | this(true); 47 | } 48 | 49 | /** 50 | * Ctor. 51 | * @param hidden Is hidden 52 | */ 53 | public Hidden(final boolean hidden) { 54 | this.value = hidden; 55 | } 56 | 57 | @Override 58 | public void accept(final CellStyle style) { 59 | style.setHidden(this.value); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/Indention.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Cell indention (Number of spaces to indent the text in the cell). 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.5 34 | */ 35 | @SuppressWarnings("PMD.AvoidUsingShortType") 36 | public final class Indention implements Props { 37 | 38 | /** 39 | * Indention. 40 | */ 41 | private final short value; 42 | 43 | /** 44 | * Ctor. 45 | * @param indention Indention 46 | */ 47 | public Indention(final short indention) { 48 | this.value = indention; 49 | } 50 | 51 | @Override 52 | public void accept(final CellStyle style) { 53 | style.setIndention(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/Locked.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Locked cell. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.5 34 | */ 35 | public final class Locked implements Props { 36 | 37 | /** 38 | * Is locked value. 39 | */ 40 | private final boolean value; 41 | 42 | /** 43 | * Ctor. 44 | */ 45 | public Locked() { 46 | this(true); 47 | } 48 | 49 | /** 50 | * Ctor. 51 | * @param locked Is locked 52 | */ 53 | public Locked(final boolean locked) { 54 | this.value = locked; 55 | } 56 | 57 | @Override 58 | public void accept(final CellStyle style) { 59 | style.setLocked(this.value); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/Rotation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Cell rotation. 31 | * Available values: 0 to 180 degrees 32 | * 33 | * @author Vedran Vatavuk (123vgv@gmail.com) 34 | * @version $Id$ 35 | * @since 0.5 36 | */ 37 | @SuppressWarnings("PMD.AvoidUsingShortType") 38 | public final class Rotation implements Props { 39 | 40 | /** 41 | * Rotation in degrees. 42 | */ 43 | private final short value; 44 | 45 | /** 46 | * Ctor. 47 | * @param rotation Rotation 48 | */ 49 | public Rotation(final short rotation) { 50 | this.value = rotation; 51 | } 52 | 53 | @Override 54 | public void accept(final CellStyle style) { 55 | style.setRotation(this.value); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/AlignHorizontal.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.HorizontalAlignment; 29 | 30 | /** 31 | * Cell alignment. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.5 35 | */ 36 | public final class AlignHorizontal implements Props { 37 | 38 | /** 39 | * Aligment. 40 | */ 41 | private final HorizontalAlignment value; 42 | 43 | /** 44 | * Ctor. 45 | * @param alignment Alignment 46 | */ 47 | public AlignHorizontal(final HorizontalAlignment alignment) { 48 | this.value = alignment; 49 | } 50 | 51 | @Override 52 | public void accept(final CellStyle style) { 53 | style.setAlignment(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/FillPattern.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.FillPatternType; 29 | 30 | /** 31 | * Fill pattern style. 32 | * 33 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 34 | * @version $Id$ 35 | * @since 0.1 36 | */ 37 | public final class FillPattern implements Props { 38 | 39 | /** 40 | * Type of fill pattern. 41 | */ 42 | private final FillPatternType pattern; 43 | 44 | /** 45 | * Ctor. 46 | * @param type Pattern type 47 | */ 48 | public FillPattern(final FillPatternType type) { 49 | this.pattern = type; 50 | } 51 | 52 | @Override 53 | public void accept(final CellStyle style) { 54 | style.setFillPattern(this.pattern); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/ESheet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | 30 | /** 31 | * Sheet. 32 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.1 35 | */ 36 | public interface ESheet { 37 | 38 | /** 39 | * Attach sheet to a workbook. 40 | * @param workbook Workbook 41 | * @return Sheet 42 | * @throws IOException If fails 43 | */ 44 | Sheet attachTo(Workbook workbook) throws IOException; 45 | 46 | /** 47 | * Add row to the sheet. 48 | * @param row Row 49 | * @return Sheet 50 | */ 51 | ESheet with(ERow row); 52 | 53 | /** 54 | * Add style to the sheet. 55 | * @param style Style 56 | * @return Sheet 57 | */ 58 | ESheet with(Style style); 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/AlignVertical.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.VerticalAlignment; 29 | 30 | /** 31 | * Vertical alignment in cell. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.5 35 | */ 36 | public final class AlignVertical implements Props { 37 | 38 | /** 39 | * Vertical alignment. 40 | */ 41 | private final VerticalAlignment value; 42 | 43 | /** 44 | * Ctor. 45 | * @param alignment Vertical align. 46 | */ 47 | public AlignVertical(final VerticalAlignment alignment) { 48 | this.value = alignment; 49 | } 50 | 51 | @Override 52 | public void accept(final CellStyle style) { 53 | style.setVerticalAlignment(this.value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/WrappedText.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * Wrapped text in cell. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.5 34 | */ 35 | public final class WrappedText implements Props { 36 | 37 | /** 38 | * Is text wrapped. 39 | */ 40 | private final boolean value; 41 | 42 | /** 43 | * Ctor. 44 | */ 45 | public WrappedText() { 46 | this(true); 47 | } 48 | 49 | /** 50 | * Ctor. 51 | * @param wrapped Is text wrapped 52 | */ 53 | public WrappedText(final boolean wrapped) { 54 | this.value = wrapped; 55 | } 56 | 57 | @Override 58 | public void accept(final CellStyle style) { 59 | style.setWrapText(this.value); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/styles/QuotePrefixed.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | 29 | /** 30 | * QuotePrefixed prop on cell. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.5 34 | */ 35 | public final class QuotePrefixed implements Props { 36 | 37 | /** 38 | * Is prefixed. 39 | */ 40 | private final boolean value; 41 | 42 | /** 43 | * Ctor. 44 | */ 45 | public QuotePrefixed() { 46 | this(true); 47 | } 48 | 49 | /** 50 | * Ctor. 51 | * @param prefixed Is prefixed 52 | */ 53 | public QuotePrefixed(final boolean prefixed) { 54 | this.value = prefixed; 55 | } 56 | 57 | @Override 58 | public void accept(final CellStyle style) { 59 | style.setQuotePrefixed(this.value); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/sheet/ColumnWidth.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | 29 | /** 30 | * Column width. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public final class ColumnWidth implements Props { 36 | 37 | /** 38 | * Column. 39 | */ 40 | private final int col; 41 | 42 | /** 43 | * Width in pixels. 44 | */ 45 | private final int width; 46 | 47 | /** 48 | * Ctor. 49 | * @param column Column 50 | * @param pixels Pixels 51 | */ 52 | public ColumnWidth(final int column, final int pixels) { 53 | this.col = column; 54 | this.width = pixels; 55 | } 56 | 57 | @Override 58 | public void accept(final Sheet sheet) { 59 | sheet.setColumnWidth(this.col, this.width); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/HiddenTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link Hidden}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.5 39 | */ 40 | public final class HiddenTest { 41 | 42 | /** 43 | * Hides cell. 44 | * @throws IOException If fails 45 | */ 46 | @Test 47 | public void addsHiddenStyleToCell() throws IOException { 48 | try (final Workbook wbook = new XSSFWorkbook()) { 49 | final CellStyle style = wbook.createCellStyle(); 50 | new Hidden().accept(style); 51 | MatcherAssert.assertThat( 52 | style.getHidden(), 53 | Matchers.equalTo(true) 54 | ); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/LockedTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link Locked}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.5 39 | */ 40 | public final class LockedTest { 41 | 42 | /** 43 | * Locks cell. 44 | * @throws IOException If fails 45 | */ 46 | @Test 47 | public void addsLockedStyleToCell() throws IOException { 48 | try (final Workbook wbook = new XSSFWorkbook()) { 49 | final CellStyle style = wbook.createCellStyle(); 50 | new Locked().accept(style); 51 | MatcherAssert.assertThat( 52 | style.getLocked(), 53 | Matchers.equalTo(true) 54 | ); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/ERow.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io; 25 | 26 | import org.apache.poi.ss.usermodel.Row; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | 29 | /** 30 | * Row. 31 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public interface ERow { 36 | 37 | /** 38 | * Attach row to a sheet. 39 | * @param sheet Sheet 40 | * @return Row 41 | */ 42 | Row attachTo(Sheet sheet); 43 | 44 | /** 45 | * Add style to the row. 46 | * @param style Style 47 | * @return Row 48 | */ 49 | ERow with(Style style); 50 | 51 | /** 52 | * Add cells to the row. 53 | * @param cells Cells 54 | * @return Row 55 | */ 56 | ERow with(ECell... cells); 57 | 58 | /** 59 | * Add cells to the row. 60 | * @param cells Cells 61 | * @return Row 62 | */ 63 | ERow with(ECells cells); 64 | 65 | /** 66 | * Add props to the row. 67 | * @param props Properties 68 | * @return Row 69 | */ 70 | ERow with(Props props); 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/WrappedTextTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link WrappedText}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.5 39 | */ 40 | public final class WrappedTextTest { 41 | 42 | /** 43 | * Wraps text in a cell. 44 | * @throws IOException If fails 45 | */ 46 | @Test 47 | public void wrapsTextInCell() throws IOException { 48 | try (final Workbook wbook = new XSSFWorkbook()) { 49 | final CellStyle style = wbook.createCellStyle(); 50 | new WrappedText().accept(style); 51 | MatcherAssert.assertThat( 52 | style.getWrapText(), 53 | Matchers.equalTo(true) 54 | ); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/row/ZeroHeightTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.row; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Row; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link ZeroHeight}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.1 39 | */ 40 | public final class ZeroHeightTest { 41 | 42 | /** 43 | * Set row zero height. 44 | * @throws IOException If fails 45 | */ 46 | @Test 47 | public void setsZeroHeight() throws IOException { 48 | try (final Workbook wbook = new XSSFWorkbook()) { 49 | final boolean zero = true; 50 | final Row row = wbook.createSheet().createRow(0); 51 | new ZeroHeight(zero).accept(row); 52 | MatcherAssert.assertThat( 53 | row.getZeroHeight(), 54 | Matchers.equalTo(zero) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/QuotePrefixedTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link QuotePrefixed}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.5 39 | */ 40 | public final class QuotePrefixedTest { 41 | 42 | /** 43 | * Add quote prefixed style to cell. 44 | * @throws IOException If fails 45 | */ 46 | @Test 47 | public void addsQuotePrefixedStyleToCell() throws IOException { 48 | try (final Workbook wbook = new XSSFWorkbook()) { 49 | final CellStyle style = wbook.createCellStyle(); 50 | new QuotePrefixed().accept(style); 51 | MatcherAssert.assertThat( 52 | style.getQuotePrefixed(), 53 | Matchers.equalTo(true) 54 | ); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/sheet/ColumnWidthTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test cases for {@link ColumnWidth}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.1 39 | */ 40 | public final class ColumnWidthTest { 41 | 42 | /** 43 | * Set column width. 44 | * @throws IOException If fails 45 | */ 46 | @Test 47 | public void setColumnWidth() throws IOException { 48 | try (final Workbook wbook = new XSSFWorkbook()) { 49 | final int width = 100; 50 | final Sheet sheet = wbook.createSheet(); 51 | new ColumnWidth(0, width).accept(sheet); 52 | MatcherAssert.assertThat( 53 | sheet.getColumnWidth(0), 54 | Matchers.equalTo(width) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/XsProps.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io; 25 | 26 | import com.jcabi.immutable.Array; 27 | 28 | /** 29 | * Properties. 30 | * @author Vedran Vatavuk (123vgv@gmail.com) 31 | * @version $Id$ 32 | * @param Props 33 | * @since 0.1 34 | */ 35 | public final class XsProps implements Props { 36 | 37 | /** 38 | * List of properties. 39 | */ 40 | private final Array> props; 41 | 42 | /** 43 | * Ctor. 44 | */ 45 | public XsProps() { 46 | this(new Array<>()); 47 | } 48 | 49 | /** 50 | * Ctor. 51 | * @param properties Properties 52 | */ 53 | @SafeVarargs 54 | @SuppressWarnings("unchecked") 55 | public XsProps(final Props... properties) { 56 | this(new Array<>(properties)); 57 | } 58 | 59 | /** 60 | * Ctor. 61 | * @param properties Properties 62 | */ 63 | public XsProps(final Iterable> properties) { 64 | this.props = new Array<>(properties); 65 | } 66 | 67 | @Override 68 | public void accept(final T element) { 69 | this.props.forEach(prop -> prop.accept(element)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/sheet/AutoSizeColumn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | 29 | /** 30 | * Auto size column. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 1.0 34 | */ 35 | public final class AutoSizeColumn implements Props { 36 | 37 | /** 38 | * Column. 39 | */ 40 | private final int value; 41 | 42 | /** 43 | * Are cells to be merged. 44 | */ 45 | private final boolean ismerged; 46 | 47 | /** 48 | * Ctor. 49 | * @param column Column 50 | */ 51 | public AutoSizeColumn(final int column) { 52 | this(column, false); 53 | } 54 | 55 | /** 56 | * Ctor. 57 | * @param column Column 58 | * @param merged Is cells to be merged 59 | */ 60 | public AutoSizeColumn(final int column, final boolean merged) { 61 | this.value = column; 62 | this.ismerged = merged; 63 | } 64 | 65 | @Override 66 | public void accept(final Sheet sheet) { 67 | sheet.autoSizeColumn(this.value, this.ismerged); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/row/HeightTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.row; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Row; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test cases for {@link Height}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.1 39 | */ 40 | @SuppressWarnings("PMD.AvoidUsingShortType") 41 | public final class HeightTest { 42 | 43 | /** 44 | * Set row height. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void setsRowHeight() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final short height = (short) 10; 51 | final Row row = wbook.createSheet().createRow(0); 52 | new Height(height).accept(row); 53 | MatcherAssert.assertThat( 54 | row.getHeight(), 55 | Matchers.equalTo(height) 56 | ); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/row/HeightInPointsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.row; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Row; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link HeightInPoints}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.1 39 | */ 40 | public final class HeightInPointsTest { 41 | 42 | /** 43 | * Set row height in points. 44 | * @throws IOException If fails 45 | */ 46 | @Test 47 | public void setsRowHightInPoints() throws IOException { 48 | try (final Workbook wbook = new XSSFWorkbook()) { 49 | final float points = 10.0F; 50 | final Row row = wbook.createSheet().createRow(0); 51 | new HeightInPoints(points).accept(row); 52 | MatcherAssert.assertThat( 53 | row.getHeightInPoints(), 54 | Matchers.equalTo(points) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/sheet/DefaultColumnWidthTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test cases for {@link DefaultColumnWidth}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.1 39 | */ 40 | public final class DefaultColumnWidthTest { 41 | 42 | /** 43 | * Set default column width. 44 | * @throws IOException If fails 45 | */ 46 | @Test 47 | public void setsDefaultColumnWidth() throws IOException { 48 | try (final Workbook wbook = new XSSFWorkbook()) { 49 | final int width = 100; 50 | final Sheet sheet = wbook.createSheet(); 51 | new DefaultColumnWidth(width).accept(sheet); 52 | MatcherAssert.assertThat( 53 | sheet.getDefaultColumnWidth(), 54 | Matchers.equalTo(width) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/BorderTopTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.BorderStyle; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | import org.apache.poi.ss.usermodel.Workbook; 30 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.Matchers; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link BorderTop}. 37 | * @author Vedran Vatavuk (123vgv@gmail.com) 38 | * @version $Id$ 39 | * @since 0.5 40 | */ 41 | public final class BorderTopTest { 42 | 43 | /** 44 | * Add top border to cell. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addsTopBorderToCell() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final CellStyle style = wbook.createCellStyle(); 51 | new BorderTop(BorderStyle.DASH_DOT).accept(style); 52 | MatcherAssert.assertThat( 53 | style.getBorderTopEnum(), 54 | Matchers.equalTo(BorderStyle.DASH_DOT) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/BorderLeftTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.BorderStyle; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | import org.apache.poi.ss.usermodel.Workbook; 30 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.Matchers; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link BorderLeft}. 37 | * @author Vedran Vatavuk (123vgv@gmail.com) 38 | * @version $Id$ 39 | * @since 0.5 40 | */ 41 | public final class BorderLeftTest { 42 | 43 | /** 44 | * Add left border to cell. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addsLeftBorderToCell() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final CellStyle style = wbook.createCellStyle(); 51 | new BorderLeft(BorderStyle.DASH_DOT).accept(style); 52 | MatcherAssert.assertThat( 53 | style.getBorderLeftEnum(), 54 | Matchers.equalTo(BorderStyle.DASH_DOT) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/BorderRightTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.BorderStyle; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | import org.apache.poi.ss.usermodel.Workbook; 30 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.Matchers; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link BorderRight}. 37 | * @author Vedran Vatavuk (123vgv@gmail.com) 38 | * @version $Id$ 39 | * @since 0.5 40 | */ 41 | public final class BorderRightTest { 42 | 43 | /** 44 | * Add right border to cell. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addsRightBorderToCell() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final CellStyle style = wbook.createCellStyle(); 51 | new BorderRight(BorderStyle.DASH_DOT).accept(style); 52 | MatcherAssert.assertThat( 53 | style.getBorderRightEnum(), 54 | Matchers.equalTo(BorderStyle.DASH_DOT) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/RotationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link Rotation}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.5 39 | */ 40 | @SuppressWarnings("PMD.AvoidUsingShortType") 41 | public final class RotationTest { 42 | 43 | /** 44 | * Adds cell rotation style. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addCellRotation() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final short expected = (short) 45; 51 | final CellStyle style = wbook.createCellStyle(); 52 | new Rotation(expected).accept(style); 53 | MatcherAssert.assertThat( 54 | style.getRotation(), 55 | Matchers.equalTo(expected) 56 | ); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/BorderBottomTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.BorderStyle; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | import org.apache.poi.ss.usermodel.Workbook; 30 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.Matchers; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link BorderBottom}. 37 | * @author Vedran Vatavuk (123vgv@gmail.com) 38 | * @version $Id$ 39 | * @since 0.5 40 | */ 41 | public final class BorderBottomTest { 42 | 43 | /** 44 | * Add bottom border to cell. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addsBottomBorderToCell() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final CellStyle style = wbook.createCellStyle(); 51 | new BorderBottom(BorderStyle.DASH_DOT).accept(style); 52 | MatcherAssert.assertThat( 53 | style.getBorderBottomEnum(), 54 | Matchers.equalTo(BorderStyle.DASH_DOT) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/IndentionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link Indention}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.5 39 | */ 40 | @SuppressWarnings("PMD.AvoidUsingShortType") 41 | public final class IndentionTest { 42 | 43 | /** 44 | * Adds indention to cell. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addIndentionToCell() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final short expected = (short) 10; 51 | final CellStyle style = wbook.createCellStyle(); 52 | new Indention(expected).accept(style); 53 | MatcherAssert.assertThat( 54 | style.getIndention(), 55 | Matchers.equalTo(expected) 56 | ); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/TextCell.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import org.apache.poi.ss.usermodel.Cell; 27 | import org.apache.poi.ss.usermodel.Row; 28 | 29 | /** 30 | * TextCell. 31 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public final class TextCell extends AbstractStyleableCell { 36 | 37 | /** 38 | * Cell position. 39 | */ 40 | private final int position; 41 | 42 | /** 43 | * Textual value. 44 | */ 45 | private final String value; 46 | 47 | /** 48 | * Ctor. 49 | * @param text Text 50 | */ 51 | public TextCell(final String text) { 52 | this(-1, text); 53 | } 54 | 55 | /** 56 | * Ctor. 57 | * @param column Column 58 | * @param text Text 59 | */ 60 | public TextCell(final int column, final String text) { 61 | super(); 62 | this.position = column; 63 | this.value = text; 64 | } 65 | 66 | @Override 67 | public Cell attachTo(final Row row) { 68 | final Cell cell = new EmptyCell(this.position).attachTo(row); 69 | cell.setCellValue(this.value); 70 | return cell; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/DataFormatTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test for {@link DataFormat }. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.3 39 | */ 40 | @SuppressWarnings("PMD.AvoidUsingShortType") 41 | public final class DataFormatTest { 42 | 43 | /** 44 | * Add data format to cell. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addsDataFormatStyleToCell() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final short expected = (short) 0; 51 | final CellStyle style = wbook.createCellStyle(); 52 | new DataFormat(expected).accept(style); 53 | MatcherAssert.assertThat( 54 | style.getDataFormat(), 55 | Matchers.equalTo(expected) 56 | ); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/AlignHorizontalTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.HorizontalAlignment; 29 | import org.apache.poi.ss.usermodel.Workbook; 30 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.Matchers; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link AlignHorizontal}. 37 | * @author Vedran Vatavuk (123vgv@gmail.com) 38 | * @version $Id$ 39 | * @since 0.5 40 | */ 41 | public final class AlignHorizontalTest { 42 | 43 | /** 44 | * Adds cell alignment. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addsCellAlignment() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final CellStyle style = wbook.createCellStyle(); 51 | new AlignHorizontal(HorizontalAlignment.CENTER).accept(style); 52 | MatcherAssert.assertThat( 53 | style.getAlignmentEnum(), 54 | Matchers.equalTo(HorizontalAlignment.CENTER) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/AlignVerticalTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.VerticalAlignment; 29 | import org.apache.poi.ss.usermodel.Workbook; 30 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.Matchers; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link AlignVerticalTest}. 37 | * @author Vedran Vatavuk (123vgv@gmail.com) 38 | * @version $Id$ 39 | * @since 0.5 40 | */ 41 | public final class AlignVerticalTest { 42 | 43 | /** 44 | * Adds cell alignment. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addsCellAlignment() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final CellStyle style = wbook.createCellStyle(); 51 | new AlignVertical(VerticalAlignment.CENTER).accept(style); 52 | MatcherAssert.assertThat( 53 | style.getVerticalAlignmentEnum(), 54 | Matchers.equalTo(VerticalAlignment.CENTER) 55 | ); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/DateCell.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import java.util.Date; 27 | import org.apache.poi.ss.usermodel.Cell; 28 | import org.apache.poi.ss.usermodel.Row; 29 | 30 | /** 31 | * Cell that represents Date. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.3 35 | */ 36 | public final class DateCell extends AbstractStyleableCell { 37 | 38 | /** 39 | * Cell position. 40 | */ 41 | private final int position; 42 | 43 | /** 44 | * Date value. 45 | */ 46 | private final Date value; 47 | 48 | /** 49 | * Ctor. 50 | * @param date Date 51 | */ 52 | public DateCell(final Date date) { 53 | this(-1, date); 54 | } 55 | 56 | /** 57 | * Ctor. 58 | * @param column Column 59 | * @param date Date 60 | */ 61 | public DateCell(final int column, final Date date) { 62 | super(); 63 | this.position = column; 64 | this.value = date; 65 | } 66 | 67 | @Override 68 | public Cell attachTo(final Row row) { 69 | final Cell cell = new EmptyCell(this.position).attachTo(row); 70 | cell.setCellValue(this.value); 71 | return cell; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/styles/BackgroundColorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.styles; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.CellStyle; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link BackgroundColor}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.5 39 | */ 40 | @SuppressWarnings("PMD.AvoidUsingShortType") 41 | public final class BackgroundColorTest { 42 | 43 | /** 44 | * Add background color to cell. 45 | * @throws IOException If fails 46 | */ 47 | @Test 48 | public void addsBackgroundColorToCell() throws IOException { 49 | try (final Workbook wbook = new XSSFWorkbook()) { 50 | final short expected = (short) 50; 51 | final CellStyle style = wbook.createCellStyle(); 52 | new BackgroundColor(expected).accept(style); 53 | MatcherAssert.assertThat( 54 | style.getFillBackgroundColor(), 55 | Matchers.equalTo(expected) 56 | ); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/NumberCell.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import org.apache.poi.ss.usermodel.Cell; 27 | import org.apache.poi.ss.usermodel.Row; 28 | 29 | /** 30 | * Cell that holds numeric value. 31 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public final class NumberCell extends AbstractStyleableCell { 36 | 37 | /** 38 | * Cell position. 39 | */ 40 | private final int position; 41 | 42 | /** 43 | * Numeric value. 44 | */ 45 | private final double value; 46 | 47 | /** 48 | * Ctor. 49 | * @param number Number 50 | */ 51 | public NumberCell(final double number) { 52 | this(-1, number); 53 | } 54 | 55 | /** 56 | * Ctor. 57 | * @param column Column 58 | * @param number Number 59 | */ 60 | public NumberCell(final int column, final double number) { 61 | super(); 62 | this.position = column; 63 | this.value = number; 64 | } 65 | 66 | @Override 67 | public Cell attachTo(final Row row) { 68 | final Cell cell = new EmptyCell(this.position).attachTo(row); 69 | cell.setCellValue(this.value); 70 | return cell; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/FormulaCell.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import org.apache.poi.ss.usermodel.Cell; 27 | import org.apache.poi.ss.usermodel.Row; 28 | 29 | /** 30 | * Cell that holds formula value. 31 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 0.1 34 | */ 35 | public final class FormulaCell extends AbstractStyleableCell { 36 | 37 | /** 38 | * Cell position. 39 | */ 40 | private final int position; 41 | 42 | /** 43 | * Formula value. 44 | */ 45 | private final String value; 46 | 47 | /** 48 | * Ctor. 49 | * @param formula Formula 50 | */ 51 | public FormulaCell(final String formula) { 52 | this(-1, formula); 53 | } 54 | 55 | /** 56 | * Ctor. 57 | * @param column Column 58 | * @param formula Formula 59 | */ 60 | public FormulaCell(final int column, final String formula) { 61 | super(); 62 | this.position = column; 63 | this.value = formula; 64 | } 65 | 66 | @Override 67 | public Cell attachTo(final Row row) { 68 | final Cell cell = new EmptyCell(this.position).attachTo(row); 69 | cell.setCellFormula(this.value); 70 | return cell; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/EWorkbook.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io; 25 | 26 | import java.io.ByteArrayOutputStream; 27 | import java.io.IOException; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | 30 | /** 31 | * Workbook. 32 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.1 35 | */ 36 | public interface EWorkbook { 37 | 38 | /** 39 | * Describe object as a byte stream. 40 | * @return Byte array output stream 41 | * @throws IOException IOException 42 | */ 43 | ByteArrayOutputStream asStream() throws IOException; 44 | 45 | /** 46 | * Describe object as a workbook. 47 | * @return Workbook 48 | * @throws IOException IOException 49 | */ 50 | Workbook asWorkbook() throws IOException; 51 | 52 | /** 53 | * Save workbook to a file. 54 | * @param path Path 55 | * @throws IOException IOException 56 | */ 57 | void saveTo(String path) throws IOException; 58 | 59 | /** 60 | * Add sheet to the workbook. 61 | * @param sheet Sheet 62 | * @return Workbook 63 | */ 64 | EWorkbook with(ESheet sheet); 65 | 66 | /** 67 | * Add style to the workbook. 68 | * @param style Style 69 | * @return Workbook 70 | */ 71 | EWorkbook with(Style style); 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/row/RowPropsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.row; 25 | 26 | import com.vgv.excel.io.XsProps; 27 | import com.vgv.excel.io.XsRow; 28 | import java.io.IOException; 29 | import org.apache.poi.ss.usermodel.Row; 30 | import org.apache.poi.ss.usermodel.Workbook; 31 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 32 | import org.hamcrest.MatcherAssert; 33 | import org.hamcrest.Matchers; 34 | import org.junit.Test; 35 | 36 | /** 37 | * Test case for row properties. 38 | * @author Vedran Vatavuk (123vgv@gmail.com) 39 | * @version $Id$ 40 | * @since 0.1 41 | */ 42 | public final class RowPropsTest { 43 | 44 | /** 45 | * Add properties to row. 46 | * @throws IOException If fails 47 | */ 48 | @Test 49 | public void addRowWithPropertiesToSheet() throws IOException { 50 | try (final Workbook wbook = new XSSFWorkbook()) { 51 | final float points = 10.0F; 52 | final Row row = new XsRow().with( 53 | new XsProps( 54 | new HeightInPoints(points) 55 | ) 56 | ).attachTo(wbook.createSheet()); 57 | MatcherAssert.assertThat( 58 | row.getHeightInPoints(), 59 | Matchers.equalTo(points) 60 | ); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/CalendarCell.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import java.util.Calendar; 27 | import org.apache.poi.ss.usermodel.Cell; 28 | import org.apache.poi.ss.usermodel.Row; 29 | 30 | /** 31 | * Cell that holds calendar value. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.3 35 | */ 36 | public final class CalendarCell extends AbstractStyleableCell { 37 | 38 | /** 39 | * Cell position. 40 | */ 41 | private final int position; 42 | 43 | /** 44 | * Calendar value. 45 | */ 46 | private final Calendar value; 47 | 48 | /** 49 | * Ctor. 50 | * @param calendar Calendar 51 | */ 52 | public CalendarCell(final Calendar calendar) { 53 | this(-1, calendar); 54 | } 55 | 56 | /** 57 | * Ctor. 58 | * @param column Cell position 59 | * @param calendar Calendar 60 | */ 61 | public CalendarCell(final int column, final Calendar calendar) { 62 | super(); 63 | this.position = column; 64 | this.value = calendar; 65 | } 66 | 67 | @Override 68 | public Cell attachTo(final Row row) { 69 | final Cell cell = new EmptyCell(this.position).attachTo(row); 70 | cell.setCellValue(this.value); 71 | return cell; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/props/sheet/SheetPropsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import com.vgv.excel.io.XsProps; 27 | import com.vgv.excel.io.XsSheet; 28 | import java.io.IOException; 29 | import org.apache.poi.ss.usermodel.Sheet; 30 | import org.apache.poi.ss.usermodel.Workbook; 31 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 32 | import org.hamcrest.MatcherAssert; 33 | import org.hamcrest.Matchers; 34 | import org.junit.Test; 35 | 36 | /** 37 | * Sheet props test. 38 | * @author Vedran Vatavuk (123vgv@gmail.com) 39 | * @version $Id$ 40 | * @since 0.1 41 | */ 42 | public final class SheetPropsTest { 43 | 44 | /** 45 | * Add new sheet with properties to workbook. 46 | * @throws IOException If fails 47 | */ 48 | @Test 49 | public void addsSheetWithPropertiesToWorkbook() throws IOException { 50 | try (final Workbook workbook = new XSSFWorkbook()) { 51 | final int width = 100; 52 | final Sheet sheet = new XsSheet() 53 | .with( 54 | new XsProps( 55 | new DefaultColumnWidth(width) 56 | ) 57 | ) 58 | .attachTo(workbook); 59 | MatcherAssert.assertThat( 60 | sheet.getDefaultColumnWidth(), 61 | Matchers.equalTo(width) 62 | ); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/templates/CellTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.templates; 25 | 26 | import com.vgv.excel.io.ECell; 27 | import com.vgv.excel.io.Style; 28 | import org.apache.poi.ss.usermodel.Cell; 29 | import org.apache.poi.ss.usermodel.Row; 30 | 31 | /** 32 | * Template to build custom cells. 33 | * 34 | *

This is how you can use it:

35 | * 36 | *
 class MyGoldCell extends CellTemplate {
37 |  *      public MyGoldCell(final ECell cell) {
38 |  *          super(cell.with(
39 |  *              new XsStyle(
40 |  *                  new ForegroundColor(IndexedColors.GOLD.getIndex()),
41 |  *                  new FillPattern(FillPatternType.SOLID_FOREGROUND)
42 |  *              )
43 |  *          ));
44 |  *      }
45 |  *  }
46 |  * 
47 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 48 | * @version $Id$ 49 | * @since 0.1 50 | */ 51 | public class CellTemplate implements ECell { 52 | 53 | /** 54 | * Origin cell. 55 | */ 56 | private final ECell origin; 57 | 58 | /** 59 | * Ctor. 60 | * @param cell Cell 61 | */ 62 | public CellTemplate(final ECell cell) { 63 | this.origin = cell; 64 | } 65 | 66 | @Override 67 | public final Cell attachTo(final Row row) { 68 | return this.origin.attachTo(row); 69 | } 70 | 71 | @Override 72 | public final ECell with(final Style style) { 73 | return this.origin.with(style); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/props/sheet/DefaultRowHeight.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.props.sheet; 25 | 26 | import com.vgv.excel.io.Props; 27 | import org.apache.poi.ss.usermodel.Sheet; 28 | 29 | /** 30 | * Default row height. 31 | * @author Vedran Vatavuk (123vgv@gmail.com) 32 | * @version $Id$ 33 | * @since 1.0 34 | */ 35 | @SuppressWarnings("PMD.AvoidUsingShortType") 36 | public final class DefaultRowHeight implements Props { 37 | 38 | /** 39 | * Row height. 40 | */ 41 | private final short value; 42 | 43 | /** 44 | * Ctor. 45 | * @param height Height. 46 | */ 47 | public DefaultRowHeight(final short height) { 48 | this.value = height; 49 | } 50 | 51 | @Override 52 | public void accept(final Sheet sheet) { 53 | sheet.setDefaultRowHeight(this.value); 54 | } 55 | 56 | /** 57 | * Default row height in points. 58 | */ 59 | public static final class InPoints implements Props { 60 | 61 | /** 62 | * Heith in points. 63 | */ 64 | private final float value; 65 | 66 | /** 67 | * Ctor. 68 | * @param height Height in points 69 | */ 70 | public InPoints(final float height) { 71 | this.value = height; 72 | } 73 | 74 | @Override 75 | public void accept(final Sheet sheet) { 76 | sheet.setDefaultRowHeightInPoints(this.value); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/FormulaCellsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link FormulaCells}. 34 | * @author Vedran Vatavuk (123vgv@gmail.com) 35 | * @version $Id$ 36 | * @since 1.0 37 | * @checkstyle JavadocMethodCheck (500 lines) 38 | */ 39 | public final class FormulaCellsTest { 40 | 41 | @Test 42 | public void createsMultipleNumberCells() { 43 | final int expected = 3; 44 | final String[] formulas = {"A+B", "A*B", "A-B"}; 45 | final Array cells = new FormulaCells(formulas).asArray(); 46 | MatcherAssert.assertThat( 47 | cells.size(), 48 | Matchers.equalTo(expected) 49 | ); 50 | MatcherAssert.assertThat( 51 | cells.get(0), 52 | Matchers.instanceOf(FormulaCell.class) 53 | ); 54 | } 55 | 56 | @Test 57 | public void createsMultipleNumberCellsInPosition() { 58 | final int expected = 1; 59 | final Array cells = new FormulaCells(2, "C+D").asArray(); 60 | MatcherAssert.assertThat( 61 | cells.size(), 62 | Matchers.equalTo(expected) 63 | ); 64 | MatcherAssert.assertThat( 65 | cells.get(0), 66 | Matchers.instanceOf(FormulaCell.class) 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/DateCellsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import java.util.Date; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.Matchers; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Test case for {@link DateCells}. 35 | * @author Vedran Vatavuk (123vgv@gmail.com) 36 | * @version $Id$ 37 | * @since 0.3 38 | * @checkstyle JavadocMethodCheck (500 lines) 39 | */ 40 | public final class DateCellsTest { 41 | 42 | @Test 43 | public void createsMultipleDateCells() { 44 | final int expected = 3; 45 | final Date[] dates = {new Date(), new Date(), new Date()}; 46 | final Array cells = new DateCells(dates).asArray(); 47 | MatcherAssert.assertThat( 48 | cells.size(), 49 | Matchers.equalTo(expected) 50 | ); 51 | MatcherAssert.assertThat( 52 | cells.get(0), 53 | Matchers.instanceOf(DateCell.class) 54 | ); 55 | } 56 | 57 | @Test 58 | public void createsMultipleDateCellsInPosition() { 59 | final int expected = 1; 60 | final Array cells = new DateCells(2, new Date()).asArray(); 61 | MatcherAssert.assertThat( 62 | cells.size(), 63 | Matchers.equalTo(expected) 64 | ); 65 | MatcherAssert.assertThat( 66 | cells.get(0), 67 | Matchers.instanceOf(DateCell.class) 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/templates/StyleTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.templates; 25 | 26 | import com.vgv.excel.io.Props; 27 | import com.vgv.excel.io.Style; 28 | import org.apache.poi.ss.usermodel.Cell; 29 | import org.apache.poi.ss.usermodel.CellStyle; 30 | 31 | /** 32 | * Template to build custom styles. 33 | * 34 | *

This is how you can use it:

35 | * 36 | *
 class MyGoldStyle extends StyleTemplate {
37 |  *      public MyGoldStyle(final Style style) {
38 |  *          super(style
39 |  *                  .with(
40 |  *                      new ForegroundColor(IndexedColors.GOLD.getIndex()
41 |  *                  )
42 |  *                  .with(
43 |  *                      new FillPattern(FillPatternType.SOLID_FOREGROUND)
44 |  *              )
45 |  *          ));
46 |  *      }
47 |  *  }
48 |  * 
49 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 50 | * @version $Id$ 51 | * @since 0.1 52 | */ 53 | public class StyleTemplate implements Style { 54 | 55 | /** 56 | * Origin style. 57 | */ 58 | private final Style origin; 59 | 60 | /** 61 | * Ctor. 62 | * @param style Style 63 | */ 64 | public StyleTemplate(final Style style) { 65 | this.origin = style; 66 | } 67 | 68 | @Override 69 | public final CellStyle attachTo(final Cell cell) { 70 | return this.origin.attachTo(cell); 71 | } 72 | 73 | @Override 74 | public final Style with(final Props property) { 75 | return this.origin.with(property); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/NumberCellsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import org.hamcrest.MatcherAssert; 29 | import org.hamcrest.Matchers; 30 | import org.junit.Test; 31 | 32 | /** 33 | * Test case for {@link NumberCells}. 34 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 35 | * @version $Id$ 36 | * @since 0.1 37 | * @checkstyle JavadocMethodCheck (500 lines) 38 | */ 39 | public final class NumberCellsTest { 40 | 41 | @Test 42 | public void createsMultipleNumberCells() { 43 | final int expected = 3; 44 | final Double[] numbers = {1.0, 2.0, 3.0}; 45 | final Array cells = new NumberCells(numbers).asArray(); 46 | MatcherAssert.assertThat( 47 | cells.size(), 48 | Matchers.equalTo(expected) 49 | ); 50 | MatcherAssert.assertThat( 51 | cells.get(0), 52 | Matchers.instanceOf(NumberCell.class) 53 | ); 54 | } 55 | 56 | @Test 57 | public void createsMultipleNumberCellsInPosition() { 58 | final int expected = 1; 59 | final int column = 2; 60 | final double number = 5.0; 61 | final Array cells = new NumberCells(column, number).asArray(); 62 | MatcherAssert.assertThat( 63 | cells.size(), 64 | Matchers.equalTo(expected) 65 | ); 66 | MatcherAssert.assertThat( 67 | cells.get(0), 68 | Matchers.instanceOf(NumberCell.class) 69 | ); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/XsStyle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io; 25 | 26 | import com.jcabi.immutable.Array; 27 | import org.apache.poi.ss.usermodel.Cell; 28 | import org.apache.poi.ss.usermodel.CellStyle; 29 | 30 | /** 31 | * Cell style which can be applied to cell/row/sheet/workbook. 32 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.1 35 | */ 36 | public final class XsStyle implements Style { 37 | 38 | /** 39 | * Array of style properties. 40 | */ 41 | private final Array> properties; 42 | 43 | /** 44 | * Ctor. 45 | */ 46 | public XsStyle() { 47 | this(new Array<>()); 48 | } 49 | 50 | /** 51 | * Ctor. 52 | * @param props Properties 53 | */ 54 | @SafeVarargs 55 | @SuppressWarnings("unchecked") 56 | public XsStyle(final Props... props) { 57 | this(new Array<>(props)); 58 | } 59 | 60 | /** 61 | * Ctor. 62 | * @param props Properties 63 | */ 64 | public XsStyle(final Iterable> props) { 65 | this.properties = new Array<>(props); 66 | } 67 | 68 | @Override 69 | public CellStyle attachTo(final Cell cell) { 70 | final CellStyle style = cell.getCellStyle(); 71 | for (final Props property : this.properties) { 72 | property.accept(style); 73 | } 74 | return style; 75 | } 76 | 77 | @Override 78 | public Style with(final Props element) { 79 | return new XsStyle(this.properties.with(element)); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/CalendarCellsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import java.util.Calendar; 29 | import org.hamcrest.MatcherAssert; 30 | import org.hamcrest.Matchers; 31 | import org.junit.Test; 32 | 33 | /** 34 | * Test case for {@link CalendarCells}. 35 | * @author Vedran Vatavuk (123vgv@gmail.com) 36 | * @version $Id$ 37 | * @since 1.0 38 | * @checkstyle JavadocMethodCheck (500 lines) 39 | */ 40 | public final class CalendarCellsTest { 41 | 42 | @Test 43 | public void createsMultipleCalendarCells() { 44 | final int expected = 3; 45 | final Calendar calendar = Calendar.getInstance(); 46 | final Calendar[] dates = {calendar, calendar, calendar}; 47 | final Array cells = new CalendarCells(dates).asArray(); 48 | MatcherAssert.assertThat( 49 | cells.size(), 50 | Matchers.equalTo(expected) 51 | ); 52 | MatcherAssert.assertThat( 53 | cells.get(0), 54 | Matchers.instanceOf(CalendarCell.class) 55 | ); 56 | } 57 | 58 | @Test 59 | public void createsMultipleCalendarCellsInPosition() { 60 | final int expected = 1; 61 | final Array cells = 62 | new CalendarCells(2, Calendar.getInstance()).asArray(); 63 | MatcherAssert.assertThat( 64 | cells.size(), 65 | Matchers.equalTo(expected) 66 | ); 67 | MatcherAssert.assertThat( 68 | cells.get(0), 69 | Matchers.instanceOf(CalendarCell.class) 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/EmptyCellTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Cell; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link EmptyCell}. 36 | * @author Vedran Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 1.0 39 | * @checkstyle JavadocMethodCheck (500 lines) 40 | */ 41 | public final class EmptyCellTest { 42 | 43 | @Test 44 | public void createsEmptyCell() throws IOException { 45 | try (final Workbook workbook = new XSSFWorkbook()) { 46 | final int column = 0; 47 | final Cell cell = new EmptyCell().attachTo( 48 | workbook.createSheet().createRow(column) 49 | ); 50 | MatcherAssert.assertThat( 51 | cell.getColumnIndex(), 52 | Matchers.equalTo(column) 53 | ); 54 | } 55 | } 56 | 57 | @Test 58 | public void createsEmptyCellWithPositioning() throws IOException { 59 | try (final Workbook workbook = new XSSFWorkbook()) { 60 | final int column = 2; 61 | final int expected = 1; 62 | final Cell cell = new EmptyCell(column).attachTo( 63 | workbook.createSheet().createRow(0) 64 | ); 65 | MatcherAssert.assertThat( 66 | cell.getColumnIndex(), 67 | Matchers.equalTo(expected) 68 | ); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/NumberCellTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Cell; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link NumberCell}. 36 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.1 39 | * @checkstyle JavadocMethodCheck (500 lines) 40 | */ 41 | public final class NumberCellTest { 42 | 43 | @Test 44 | public void addsCellContainingNumberToRow() throws IOException { 45 | try (final Workbook workbook = new XSSFWorkbook()) { 46 | final Double number = 5.0; 47 | final Cell cell = new NumberCell(number).attachTo( 48 | workbook.createSheet().createRow(0) 49 | ); 50 | MatcherAssert.assertThat( 51 | cell.getNumericCellValue(), 52 | Matchers.equalTo(number) 53 | ); 54 | } 55 | } 56 | 57 | @Test 58 | public void addsCellContainingNumberInPosition() throws IOException { 59 | try (final Workbook workbook = new XSSFWorkbook()) { 60 | final int column = 2; 61 | final int expected = 1; 62 | final Double number = 5.0; 63 | final Cell cell = new NumberCell(column, number).attachTo( 64 | workbook.createSheet().createRow(0) 65 | ); 66 | MatcherAssert.assertThat( 67 | cell.getColumnIndex(), 68 | Matchers.equalTo(expected) 69 | ); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/DateCellTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import java.io.IOException; 27 | import java.util.Date; 28 | import org.apache.poi.ss.usermodel.Cell; 29 | import org.apache.poi.ss.usermodel.Workbook; 30 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.Matchers; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link DateCell}. 37 | * @author Vedran Vatavuk (123vgv@gmail.com) 38 | * @version $Id$ 39 | * @since 0.3 40 | * @checkstyle JavadocMethodCheck (500 lines) 41 | */ 42 | public final class DateCellTest { 43 | 44 | @Test 45 | public void addsCellContainingDateToRow() throws IOException { 46 | try (final Workbook workbook = new XSSFWorkbook()) { 47 | final Date date = new Date(); 48 | final Cell cell = new DateCell(date).attachTo( 49 | workbook.createSheet().createRow(0) 50 | ); 51 | MatcherAssert.assertThat( 52 | cell.getDateCellValue(), 53 | Matchers.equalTo(date) 54 | ); 55 | } 56 | } 57 | 58 | @Test 59 | public void addsCellContainingDateWithPosition() throws IOException { 60 | try (final Workbook workbook = new XSSFWorkbook()) { 61 | final int position = 2; 62 | final int expected = 1; 63 | final Date date = new Date(); 64 | final Cell cell = new DateCell(position, date).attachTo( 65 | workbook.createSheet().createRow(0) 66 | ); 67 | MatcherAssert.assertThat( 68 | cell.getColumnIndex(), 69 | Matchers.equalTo(expected) 70 | ); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/TextCells.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import java.util.stream.Collectors; 29 | 30 | /** 31 | * TextCells. 32 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.1 35 | */ 36 | public final class TextCells extends AbstractStyleableCells { 37 | 38 | /** 39 | * Position of cells. 40 | */ 41 | private final int position; 42 | 43 | /** 44 | * Array of text values. 45 | */ 46 | private final Array text; 47 | 48 | /** 49 | * Ctor. 50 | * @param values Values 51 | */ 52 | public TextCells(final String... values) { 53 | this(new Array<>(values)); 54 | } 55 | 56 | /** 57 | * Ctor. 58 | * @param column Column 59 | * @param values Values 60 | */ 61 | public TextCells(final int column, final String... values) { 62 | this(column, new Array<>(values)); 63 | } 64 | 65 | /** 66 | * Ctor. 67 | * @param values Values 68 | */ 69 | public TextCells(final Iterable values) { 70 | this(-1, new Array<>(values)); 71 | } 72 | 73 | /** 74 | * Ctor. 75 | * @param column Column 76 | * @param values Values 77 | */ 78 | public TextCells(final int column, final Iterable values) { 79 | super(); 80 | this.position = column; 81 | this.text = new Array<>(values); 82 | } 83 | 84 | @Override 85 | public Array asArray() { 86 | return new Array<>(this.text.stream() 87 | .map(txt -> new TextCell(this.position, txt)) 88 | .collect(Collectors.toList()) 89 | ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/FormulaCellTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import java.io.IOException; 27 | import org.apache.poi.ss.usermodel.Cell; 28 | import org.apache.poi.ss.usermodel.Workbook; 29 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 30 | import org.hamcrest.MatcherAssert; 31 | import org.hamcrest.Matchers; 32 | import org.junit.Test; 33 | 34 | /** 35 | * Test case for {@link FormulaCell}. 36 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 37 | * @version $Id$ 38 | * @since 0.1 39 | * @checkstyle JavadocMethodCheck (500 lines) 40 | */ 41 | public final class FormulaCellTest { 42 | 43 | @Test 44 | public void addsCellWithFormulaValueToRow() throws IOException { 45 | try (final Workbook workbook = new XSSFWorkbook()) { 46 | final String formula = "A1+A2"; 47 | final Cell cell = new FormulaCell(formula).attachTo( 48 | workbook.createSheet().createRow(0) 49 | ); 50 | MatcherAssert.assertThat( 51 | cell.getCellFormula(), 52 | Matchers.containsString(formula) 53 | ); 54 | } 55 | } 56 | 57 | @Test 58 | public void addsCellWithFormulaValueInPosition() throws IOException { 59 | try (final Workbook workbook = new XSSFWorkbook()) { 60 | final int column = 2; 61 | final int expected = 1; 62 | final String formula = "B1+B2"; 63 | final Cell cell = new FormulaCell(column, formula).attachTo( 64 | workbook.createSheet().createRow(0) 65 | ); 66 | MatcherAssert.assertThat( 67 | cell.getColumnIndex(), 68 | Matchers.equalTo(expected) 69 | ); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/NumberCells.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import java.util.stream.Collectors; 29 | 30 | /** 31 | * Multiple cells that hold numeric values. 32 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.1 35 | */ 36 | public final class NumberCells extends AbstractStyleableCells { 37 | 38 | /** 39 | * Cell position. 40 | */ 41 | private final int position; 42 | 43 | /** 44 | * Array of numbers. 45 | */ 46 | private final Array numbers; 47 | 48 | /** 49 | * Ctor. 50 | * @param values Values 51 | */ 52 | public NumberCells(final Double... values) { 53 | this(new Array<>(values)); 54 | } 55 | 56 | /** 57 | * Ctor. 58 | * @param column Column 59 | * @param values Values 60 | */ 61 | public NumberCells(final int column, final Double... values) { 62 | this(column, new Array<>(values)); 63 | } 64 | 65 | /** 66 | * Ctor. 67 | * @param values Values 68 | */ 69 | public NumberCells(final Iterable values) { 70 | this(-1, new Array<>(values)); 71 | } 72 | 73 | /** 74 | * Ctor. 75 | * @param column Column 76 | * @param values Values 77 | */ 78 | public NumberCells(final int column, final Iterable values) { 79 | super(); 80 | this.position = column; 81 | this.numbers = new Array<>(values); 82 | } 83 | 84 | @Override 85 | public Array asArray() { 86 | return new Array<>(this.numbers.stream() 87 | .map(number -> new NumberCell(this.position, number)) 88 | .collect(Collectors.toList()) 89 | ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/DateCells.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import java.util.Date; 29 | import java.util.stream.Collectors; 30 | 31 | /** 32 | * Multiple cells with date values. 33 | * @author Vedran Vatavuk (123vgv@gmail.com) 34 | * @version $Id$ 35 | * @since 0.3 36 | */ 37 | public final class DateCells extends AbstractStyleableCells { 38 | 39 | /** 40 | * Cell position. 41 | */ 42 | private final int position; 43 | 44 | /** 45 | * Array of date values. 46 | */ 47 | private final Array dates; 48 | 49 | /** 50 | * Ctor. 51 | * @param values Values 52 | */ 53 | public DateCells(final Date... values) { 54 | this(new Array<>(values)); 55 | } 56 | 57 | /** 58 | * Ctor. 59 | * @param column Position of cells 60 | * @param values Values 61 | */ 62 | public DateCells(final int column, final Date... values) { 63 | this(column, new Array<>(values)); 64 | } 65 | 66 | /** 67 | * Ctor. 68 | * @param values Values 69 | */ 70 | public DateCells(final Iterable values) { 71 | this(-1, new Array<>(values)); 72 | } 73 | 74 | /** 75 | * Ctor. 76 | * @param column Position of cells 77 | * @param values Values 78 | */ 79 | public DateCells(final int column, final Iterable values) { 80 | super(); 81 | this.position = column; 82 | this.dates = new Array<>(values); 83 | } 84 | 85 | @Override 86 | public Array asArray() { 87 | return new Array<>(this.dates.stream() 88 | .map(date -> new DateCell(this.position, date)) 89 | .collect(Collectors.toList()) 90 | ); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/FormulaCells.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import java.util.stream.Collectors; 29 | 30 | /** 31 | * Multiples cells that hold formula values. 32 | * @author Vedran Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.3 35 | */ 36 | public final class FormulaCells extends AbstractStyleableCells { 37 | 38 | /** 39 | * Position of cells. 40 | */ 41 | private final int position; 42 | 43 | /** 44 | * Array of formula values. 45 | */ 46 | private final Array formulas; 47 | 48 | /** 49 | * Ctor. 50 | * @param values Values 51 | */ 52 | public FormulaCells(final String... values) { 53 | this(new Array<>(values)); 54 | } 55 | 56 | /** 57 | * Ctor. 58 | * @param column Column 59 | * @param values Values 60 | */ 61 | public FormulaCells(final int column, final String... values) { 62 | this(column, new Array<>(values)); 63 | } 64 | 65 | /** 66 | * Ctor. 67 | * @param values Values 68 | */ 69 | public FormulaCells(final Iterable values) { 70 | this(-1, new Array<>(values)); 71 | } 72 | 73 | /** 74 | * Ctor. 75 | * @param column Column 76 | * @param values Values 77 | */ 78 | public FormulaCells(final int column, final Iterable values) { 79 | super(); 80 | this.position = column; 81 | this.formulas = new Array<>(values); 82 | } 83 | 84 | @Override 85 | public Array asArray() { 86 | return new Array<>(this.formulas.stream() 87 | .map(formula -> new FormulaCell(this.position, formula)) 88 | .collect(Collectors.toList()) 89 | ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/com/vgv/excel/io/cells/CalendarCellTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import java.io.IOException; 27 | import java.util.Calendar; 28 | import org.apache.poi.ss.usermodel.Cell; 29 | import org.apache.poi.ss.usermodel.Workbook; 30 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 31 | import org.hamcrest.MatcherAssert; 32 | import org.hamcrest.Matchers; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Test case for {@link CalendarCell}. 37 | * @author Vedran Vatavuk (123vgv@gmail.com) 38 | * @version $Id$ 39 | * @since 0.3 40 | * @checkstyle JavadocMethodCheck (500 lines) 41 | */ 42 | public final class CalendarCellTest { 43 | 44 | @Test 45 | public void addsCellContainingCalendarToRow() throws IOException { 46 | try (final Workbook workbook = new XSSFWorkbook()) { 47 | final Calendar calendar = Calendar.getInstance(); 48 | final Cell cell = new CalendarCell(calendar).attachTo( 49 | workbook.createSheet().createRow(0) 50 | ); 51 | MatcherAssert.assertThat( 52 | cell.getDateCellValue(), 53 | Matchers.notNullValue() 54 | ); 55 | } 56 | } 57 | 58 | @Test 59 | public void addsCellContainingCalendarWithPositioning() throws IOException { 60 | try (final Workbook workbook = new XSSFWorkbook()) { 61 | final int position = 2; 62 | final int expected = 1; 63 | final Calendar calendar = Calendar.getInstance(); 64 | final Cell cell = new CalendarCell(position, calendar).attachTo( 65 | workbook.createSheet().createRow(0) 66 | ); 67 | MatcherAssert.assertThat( 68 | cell.getColumnIndex(), 69 | Matchers.equalTo(expected) 70 | ); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/EmptyCell.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.vgv.excel.io.ECell; 27 | import com.vgv.excel.io.Style; 28 | import org.apache.poi.ss.usermodel.Cell; 29 | import org.apache.poi.ss.usermodel.Row; 30 | 31 | /** 32 | * Empty cell. 33 | * @author Vedran Vatavuk (123vgv@gmail.com) 34 | * @version $Id$ 35 | * @since 1.0 36 | */ 37 | public final class EmptyCell implements ECell { 38 | 39 | /** 40 | * Cell position. 41 | */ 42 | private final int position; 43 | 44 | /** 45 | * Ctor. 46 | */ 47 | public EmptyCell() { 48 | this(-1); 49 | } 50 | 51 | /** 52 | * Ctor. 53 | * @param column Cell position 54 | */ 55 | public EmptyCell(final int column) { 56 | this.position = column; 57 | } 58 | 59 | @Override 60 | public Cell attachTo(final Row row) { 61 | Cell cell; 62 | if (this.position == -1) { 63 | cell = EmptyCell.createCell((int) row.getLastCellNum(), row); 64 | } else { 65 | cell = row.getCell(this.position - 1); 66 | if (cell == null) { 67 | cell = EmptyCell.createCell(this.position - 1, row); 68 | } 69 | } 70 | return cell; 71 | } 72 | 73 | @Override 74 | public ECell with(final Style style) { 75 | return new ECell.WithStyle(this, style); 76 | } 77 | 78 | /** 79 | * Create cell in given position. 80 | * @param position Position 81 | * @param row Row 82 | * @return Cell cell 83 | */ 84 | private static Cell createCell(final int position, final Row row) { 85 | final int index; 86 | if (position < 0) { 87 | index = 0; 88 | } else { 89 | index = position; 90 | } 91 | return row.createCell(index); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/cells/CalendarCells.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.cells; 25 | 26 | import com.jcabi.immutable.Array; 27 | import com.vgv.excel.io.ECell; 28 | import java.util.Calendar; 29 | import java.util.stream.Collectors; 30 | 31 | /** 32 | * Multiple cells containing Calendar values. 33 | * @author Vedran Vatavuk (123vgv@gmail.com) 34 | * @version $Id$ 35 | * @since 0.3 36 | */ 37 | public final class CalendarCells extends AbstractStyleableCells { 38 | 39 | /** 40 | * Position of cells. 41 | */ 42 | private final int position; 43 | 44 | /** 45 | * Array of calendar values. 46 | */ 47 | private final Array values; 48 | 49 | /** 50 | * Ctor. 51 | * @param cvalues Calendar values 52 | */ 53 | public CalendarCells(final Calendar... cvalues) { 54 | this(new Array<>(cvalues)); 55 | } 56 | 57 | /** 58 | * Ctor. 59 | * @param column Position of cells 60 | * @param cvalues Values 61 | */ 62 | public CalendarCells(final int column, final Calendar... cvalues) { 63 | this(column, new Array<>(cvalues)); 64 | } 65 | 66 | /** 67 | * Ctor. 68 | * @param cvalues Values 69 | */ 70 | public CalendarCells(final Iterable cvalues) { 71 | this(-1, new Array<>(cvalues)); 72 | } 73 | 74 | /** 75 | * Ctor. 76 | * @param column Position of cells 77 | * @param cvalues Values 78 | */ 79 | public CalendarCells(final int column, final Iterable cvalues) { 80 | super(); 81 | this.position = column; 82 | this.values = new Array<>(cvalues); 83 | } 84 | 85 | @Override 86 | public Array asArray() { 87 | return new Array<>(this.values.stream() 88 | .map(calendar -> new CalendarCell(this.position, calendar)) 89 | .collect(Collectors.toList()) 90 | ); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/templates/RowTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io.templates; 25 | 26 | import com.vgv.excel.io.ECell; 27 | import com.vgv.excel.io.ECells; 28 | import com.vgv.excel.io.ERow; 29 | import com.vgv.excel.io.Props; 30 | import com.vgv.excel.io.Style; 31 | import org.apache.poi.ss.usermodel.Row; 32 | import org.apache.poi.ss.usermodel.Sheet; 33 | 34 | /** 35 | * Template to build custom rows. 36 | * 37 | *

This is how you can use it:

38 | * 39 | *
 class MyGoldRow extends RowTemplate {
40 |  *      public MyGoldRow(final ERow row) {
41 |  *          super(row.with(
42 |  *              new XsStyle(
43 |  *                  new ForegroundColor(IndexedColors.GOLD.getIndex()),
44 |  *                  new FillPattern(FillPatternType.SOLID_FOREGROUND)
45 |  *              )
46 |  *          ));
47 |  *      }
48 |  *  }
49 |  * 
50 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 51 | * @version $Id$ 52 | * @since 0.1 53 | */ 54 | public class RowTemplate implements ERow { 55 | 56 | /** 57 | * Origin row. 58 | */ 59 | private final ERow origin; 60 | 61 | /** 62 | * Ctor. 63 | * @param row Row 64 | */ 65 | public RowTemplate(final ERow row) { 66 | this.origin = row; 67 | } 68 | 69 | @Override 70 | public final Row attachTo(final Sheet sheet) { 71 | return this.origin.attachTo(sheet); 72 | } 73 | 74 | @Override 75 | public final ERow with(final Style style) { 76 | return this.origin.with(style); 77 | } 78 | 79 | @Override 80 | public final ERow with(final ECell... cells) { 81 | return this.origin.with(cells); 82 | } 83 | 84 | @Override 85 | public final ERow with(final ECells cells) { 86 | return this.origin.with(cells); 87 | } 88 | 89 | @Override 90 | public final ERow with(final Props props) { 91 | return this.origin.with(props); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/vgv/excel/io/ECells.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2018 Vedran Grgo Vatavuk 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.vgv.excel.io; 25 | 26 | import com.jcabi.immutable.Array; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | /** 31 | * Cells. 32 | * @author Vedran Grgo Vatavuk (123vgv@gmail.com) 33 | * @version $Id$ 34 | * @since 0.1 35 | */ 36 | public interface ECells { 37 | 38 | /** 39 | * Describe object as array of cells. 40 | * @return Array of cells 41 | */ 42 | Array asArray(); 43 | 44 | /** 45 | * Add style to cells. 46 | * @param style Style 47 | * @return Cell 48 | */ 49 | ECells with(Style style); 50 | 51 | /** 52 | * Cells with specific style. 53 | */ 54 | final class WithStyle implements ECells { 55 | 56 | /** 57 | * Origin cell. 58 | */ 59 | private final ECells origin; 60 | 61 | /** 62 | * List of styles. 63 | */ 64 | private final Array