Skip to content

Commit 70f3c5e

Browse files
VedranVedran
Vedran
authored and
Vedran
committed
sheet props
1 parent c1278ef commit 70f3c5e

14 files changed

+400
-5
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.xls;
25+
26+
import java.util.function.Consumer;
27+
import org.apache.poi.ss.usermodel.Sheet;
28+
29+
/**
30+
* Sheet property.
31+
* @author Vedran Vatavuk (123vgv@gmail.com)
32+
* @version $Id$
33+
* @since 1.0
34+
*/
35+
public interface SheetProp extends Consumer<Sheet> {
36+
}

src/main/java/com/vgv/xls/props/Height.java src/main/java/com/vgv/xls/props/row/Height.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.vgv.xls.props;
24+
package com.vgv.xls.props.row;
2525

2626
import com.vgv.xls.RowProp;
2727
import org.apache.poi.ss.usermodel.Row;

src/main/java/com/vgv/xls/props/HeightInPoints.java src/main/java/com/vgv/xls/props/row/HeightInPoints.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.vgv.xls.props;
24+
package com.vgv.xls.props.row;
2525

2626
import com.vgv.xls.RowProp;
2727
import org.apache.poi.ss.usermodel.Row;

src/main/java/com/vgv/xls/props/ZeroHeight.java src/main/java/com/vgv/xls/props/row/ZeroHeight.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.vgv.xls.props;
24+
package com.vgv.xls.props.row;
2525

2626
import com.vgv.xls.RowProp;
2727
import org.apache.poi.ss.usermodel.Row;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 1.0
31+
*/
32+
package com.vgv.xls.props.row;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.xls.props.sheet;
25+
26+
import com.vgv.xls.SheetProp;
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 1.0
34+
*/
35+
public final class ColumnWidth implements SheetProp {
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.xls.props.sheet;
25+
26+
import com.vgv.xls.SheetProp;
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 1.0
34+
*/
35+
public final class DefaultColumnWidth implements SheetProp {
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 1.0
31+
*/
32+
package com.vgv.xls.props.sheet;

src/test/java/com/vgv/xls/XsRowTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
package com.vgv.xls;
2525

26-
import com.vgv.xls.props.HeightInPoints;
26+
import com.vgv.xls.props.row.HeightInPoints;
2727
import com.vgv.xls.styles.ForegroundColor;
2828
import java.io.IOException;
2929
import org.apache.poi.ss.usermodel.IndexedColors;

src/test/java/com/vgv/xls/props/RowPropsTest.java src/test/java/com/vgv/xls/props/row/RowPropsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.vgv.xls.props;
24+
package com.vgv.xls.props.row;
2525

2626
import java.io.IOException;
2727
import org.apache.poi.ss.usermodel.Row;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 1.0
31+
*/
32+
package com.vgv.xls.props.row;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.xls.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 1.0
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+
}

0 commit comments

Comments
 (0)