|
|
@@ -17,10 +17,12 @@ |
|
|
|
|
|
|
|
package org.apache.poi.ss.util; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.BorderStyle; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
import org.apache.poi.ss.usermodel.Sheet; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.util.Removal; |
|
|
|
|
|
|
|
/** |
|
|
|
* Various utility functions that make working with a region of cells easier. |
|
|
@@ -47,32 +49,37 @@ public final class RegionUtil { |
|
|
|
|
|
|
|
|
|
|
|
public void setProperty(Row row, int column) { |
|
|
|
// create cell if it does not exist |
|
|
|
Cell cell = CellUtil.getCell(row, column); |
|
|
|
CellUtil.setCellStyleProperty(cell, _propertyName, _propertyValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sets the left border for a region of cells by manipulating the cell style of the individual |
|
|
|
* Sets the left border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the left |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param workbook The workbook that the region is on. |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBorderLeft(int, CellRangeAddress, Sheet)}. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBorderLeft(BorderStyle, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.17") |
|
|
|
public static void setBorderLeft(int border, CellRangeAddress region, Sheet sheet, Workbook workbook) { |
|
|
|
setBorderLeft(border, region, sheet); |
|
|
|
} |
|
|
|
/** |
|
|
|
* Sets the left border for a region of cells by manipulating the cell style of the individual |
|
|
|
* Sets the left border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the left |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.15 beta 2 |
|
|
|
* @deprecated 3.16 beta 1. Use {@link #setBorderLeft(BorderStyle, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.18") |
|
|
|
public static void setBorderLeft(int border, CellRangeAddress region, Sheet sheet) { |
|
|
|
int rowStart = region.getFirstRow(); |
|
|
|
int rowEnd = region.getLastRow(); |
|
|
@@ -83,6 +90,18 @@ public final class RegionUtil { |
|
|
|
cps.setProperty(CellUtil.getRow(i, sheet), column); |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* Sets the left border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the left |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.16 beta 1 |
|
|
|
*/ |
|
|
|
public static void setBorderLeft(BorderStyle border, CellRangeAddress region, Sheet sheet) { |
|
|
|
setBorderLeft(border.getCode(), region, sheet); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sets the left border color for a region of cells by manipulating the cell style of the individual |
|
|
@@ -94,6 +113,7 @@ public final class RegionUtil { |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setLeftBorderColor(int, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.17") |
|
|
|
public static void setLeftBorderColor(int color, CellRangeAddress region, Sheet sheet, Workbook workbook) { |
|
|
|
setLeftBorderColor(color, region, sheet); |
|
|
|
} |
|
|
@@ -104,6 +124,7 @@ public final class RegionUtil { |
|
|
|
* @param color The color of the border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.15 beta 2 |
|
|
|
*/ |
|
|
|
public static void setLeftBorderColor(int color, CellRangeAddress region, Sheet sheet) { |
|
|
|
int rowStart = region.getFirstRow(); |
|
|
@@ -117,26 +138,30 @@ public final class RegionUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sets the right border for a region of cells by manipulating the cell style of the individual |
|
|
|
* Sets the right border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the right |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param workbook The workbook that the region is on. |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBorderRight(int, CellRangeAddress, Sheet)}. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBorderRight(BorderStyle, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.17") |
|
|
|
public static void setBorderRight(int border, CellRangeAddress region, Sheet sheet, Workbook workbook) { |
|
|
|
setBorderRight(border, region, sheet); |
|
|
|
} |
|
|
|
/** |
|
|
|
* Sets the right border for a region of cells by manipulating the cell style of the individual |
|
|
|
* Sets the right border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the right |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.15 beta 2 |
|
|
|
* @deprecated POI 3.16 beta 1. Use {@link #setBorderRight(BorderStyle, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.18") |
|
|
|
public static void setBorderRight(int border, CellRangeAddress region, Sheet sheet) { |
|
|
|
int rowStart = region.getFirstRow(); |
|
|
|
int rowEnd = region.getLastRow(); |
|
|
@@ -147,6 +172,18 @@ public final class RegionUtil { |
|
|
|
cps.setProperty(CellUtil.getRow(i, sheet), column); |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* Sets the right border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the right |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.16 beta 1 |
|
|
|
*/ |
|
|
|
public static void setBorderRight(BorderStyle border, CellRangeAddress region, Sheet sheet) { |
|
|
|
setBorderRight(border.getCode(), region, sheet); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sets the right border color for a region of cells by manipulating the cell style of the individual |
|
|
@@ -158,6 +195,7 @@ public final class RegionUtil { |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setRightBorderColor(int, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.17") |
|
|
|
public static void setRightBorderColor(int color, CellRangeAddress region, Sheet sheet, Workbook workbook) { |
|
|
|
setRightBorderColor(color, region, sheet); |
|
|
|
} |
|
|
@@ -168,6 +206,7 @@ public final class RegionUtil { |
|
|
|
* @param color The color of the border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.15 beta 2 |
|
|
|
*/ |
|
|
|
public static void setRightBorderColor(int color, CellRangeAddress region, Sheet sheet) { |
|
|
|
int rowStart = region.getFirstRow(); |
|
|
@@ -181,26 +220,30 @@ public final class RegionUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sets the bottom border for a region of cells by manipulating the cell style of the individual |
|
|
|
* Sets the bottom border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the bottom |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param workbook The workbook that the region is on. |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBorderBottom(int, CellRangeAddress, Sheet)}. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBorderBottom(BorderStyle, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.17") |
|
|
|
public static void setBorderBottom(int border, CellRangeAddress region, Sheet sheet, Workbook workbook) { |
|
|
|
setBorderBottom(border, region, sheet); |
|
|
|
} |
|
|
|
/** |
|
|
|
* Sets the bottom border for a region of cells by manipulating the cell style of the individual |
|
|
|
* Sets the bottom border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the bottom |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.15 beta 2 |
|
|
|
* @deprecated POI 3.16 beta 1. Use {@link #setBorderBottom(BorderStyle, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.18") |
|
|
|
public static void setBorderBottom(int border, CellRangeAddress region, Sheet sheet) { |
|
|
|
int colStart = region.getFirstColumn(); |
|
|
|
int colEnd = region.getLastColumn(); |
|
|
@@ -211,6 +254,18 @@ public final class RegionUtil { |
|
|
|
cps.setProperty(row, i); |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* Sets the bottom border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the bottom |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.16 beta 1 |
|
|
|
*/ |
|
|
|
public static void setBorderBottom(BorderStyle border, CellRangeAddress region, Sheet sheet) { |
|
|
|
setBorderBottom(border.getCode(), region, sheet); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sets the bottom border color for a region of cells by manipulating the cell style of the individual |
|
|
@@ -222,6 +277,7 @@ public final class RegionUtil { |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBottomBorderColor(int, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.17") |
|
|
|
public static void setBottomBorderColor(int color, CellRangeAddress region, Sheet sheet, Workbook workbook) { |
|
|
|
setBottomBorderColor(color, region, sheet); |
|
|
|
} |
|
|
@@ -232,6 +288,7 @@ public final class RegionUtil { |
|
|
|
* @param color The color of the border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.15 beta 2 |
|
|
|
*/ |
|
|
|
public static void setBottomBorderColor(int color, CellRangeAddress region, Sheet sheet) { |
|
|
|
int colStart = region.getFirstColumn(); |
|
|
@@ -245,26 +302,30 @@ public final class RegionUtil { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sets the top border for a region of cells by manipulating the cell style of the individual |
|
|
|
* Sets the top border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the top |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param workbook The workbook that the region is on. |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBorderTop(int, CellRangeAddress, Sheet)}. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setBorderTop(BorderStyle, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.17") |
|
|
|
public static void setBorderTop(int border, CellRangeAddress region, Sheet sheet, Workbook workbook) { |
|
|
|
setBorderTop(border, region, sheet); |
|
|
|
} |
|
|
|
/** |
|
|
|
* Sets the top border for a region of cells by manipulating the cell style of the individual |
|
|
|
* Sets the top border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the top |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.15 beta 2 |
|
|
|
* @deprecated 3.16 beta 1. Use {@link #setBorderTop(BorderStyle, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.18") |
|
|
|
public static void setBorderTop(int border, CellRangeAddress region, Sheet sheet) { |
|
|
|
int colStart = region.getFirstColumn(); |
|
|
|
int colEnd = region.getLastColumn(); |
|
|
@@ -275,6 +336,18 @@ public final class RegionUtil { |
|
|
|
cps.setProperty(row, i); |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* Sets the top border style for a region of cells by manipulating the cell style of the individual |
|
|
|
* cells on the top |
|
|
|
* |
|
|
|
* @param border The new border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.16 beta 1 |
|
|
|
*/ |
|
|
|
public static void setBorderTop(BorderStyle border, CellRangeAddress region, Sheet sheet) { |
|
|
|
setBorderTop(border.getCode(), region, sheet); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Sets the top border color for a region of cells by manipulating the cell style of the individual |
|
|
@@ -286,6 +359,7 @@ public final class RegionUtil { |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @deprecated 3.15 beta 2. Use {@link #setTopBorderColor(int, CellRangeAddress, Sheet)}. |
|
|
|
*/ |
|
|
|
@Removal(version="3.17") |
|
|
|
public static void setTopBorderColor(int color, CellRangeAddress region, Sheet sheet, Workbook workbook) { |
|
|
|
setTopBorderColor(color, region, sheet); |
|
|
|
} |
|
|
@@ -296,6 +370,7 @@ public final class RegionUtil { |
|
|
|
* @param color The color of the border |
|
|
|
* @param region The region that should have the border |
|
|
|
* @param sheet The sheet that the region is on. |
|
|
|
* @since POI 3.15 beta 2 |
|
|
|
*/ |
|
|
|
public static void setTopBorderColor(int color, CellRangeAddress region, Sheet sheet) { |
|
|
|
int colStart = region.getFirstColumn(); |