You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/01/16 08:11:01 UTC
svn commit: r1724929 - in /poi/site: publish/spreadsheet/quick-guide.html
src/documentation/content/xdocs/spreadsheet/quick-guide.xml
Author: onealj
Date: Sat Jan 16 07:11:01 2016
New Revision: 1724929
URL: http://svn.apache.org/viewvc?rev=1724929&view=rev
Log:
bug 58633: add CellProperties section to spreadsheet quick guide. Contributed by Mark Murphy
Modified:
poi/site/publish/spreadsheet/quick-guide.html
poi/site/src/documentation/content/xdocs/spreadsheet/quick-guide.xml
Modified: poi/site/publish/spreadsheet/quick-guide.html
URL: http://svn.apache.org/viewvc/poi/site/publish/spreadsheet/quick-guide.html?rev=1724929&r1=1724928&r2=1724929&view=diff
==============================================================================
--- poi/site/publish/spreadsheet/quick-guide.html (original)
+++ poi/site/publish/spreadsheet/quick-guide.html Sat Jan 16 07:11:01 2016
@@ -365,6 +365,10 @@ if (VERSION > 3) {
<li>
<a href="#Hiding">Hiding and Un-Hiding Rows</a>
</li>
+
+<li>
+<a href="#CellProperties">Setting Cell Properties</a>
+</li>
</ul>
@@ -1737,7 +1741,7 @@ Examples:
<a name="Outlining"></a>
- <a name="Outlining-N103DD"></a>
+ <a name="Outlining-N103E2"></a>
<div class="h2">
<h2>Outlining</h2>
</div>
@@ -1784,7 +1788,7 @@ Examples:
<a name="Images"></a>
- <a name="Images-N103FA"></a>
+ <a name="Images-N103FF"></a>
<div class="h3">
<h3>Images</h3>
</div>
@@ -2949,7 +2953,63 @@ the data to populate another drop down l
method and passing the boolean value 'false'. Secondly, it ilustrates how to test whther a row is hidden or not.
Simply call the getZeroHeight() method and it will return 'true' if the row is hidden, 'false' otherwise.
</p>
-
+
+
+<a name="CellProperties"></a>
+ <a name="Setting+Cell+Properties"></a>
+<div class="h3">
+<h3>Setting Cell Properties</h3>
+</div>
+
+<p>
+ Sometimes it is easier or more efficient to create a spreadsheet with basic styles and then apply special styles to certain cells
+ such as drawing borders around a range of cells or setting fills for a region. CellUtil.setCellProperties lets you do that without creating
+ a bunch of unnecessary intermediate styles in your spreadsheet.
+ </p>
+
+<p>
+ Properties are created as a Map and applied to a cell in the following manner.
+ </p>
+
+<pre class="code">
+ Workbook workbook = new XSSFWorkbook(); // OR new HSSFWorkbook()
+ Sheet sheet = workbook.createSheet("Sheet1");
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ // border around a cell
+ properties.put(CellUtil.BORDER_TOP, CellStyle.BORDER_MEDIUM);
+ properties.put(CellUtil.BORDER_BOTTOM, CellStyle.BORDER_MEDIUM);
+ properties.put(CellUtil.BORDER_LEFT, CellStyle.BORDER_MEDIUM);
+ properties.put(CellUtil.BORDER_RIGHT, CellStyle.BORDER_MEDIUM);
+
+ // Give it a color (RED)
+ properties.put(CellUtil.TOP_BORDER_COLOR, IndexedColors.RED.getIndex());
+ properties.put(CellUtil.BOTTOM_BORDER_COLOR, IndexedColors.RED.getIndex());
+ properties.put(CellUtil.LEFT_BORDER_COLOR, IndexedColors.RED.getIndex());
+ properties.put(CellUtil.RIGHT_BORDER_COLOR, IndexedColors.RED.getIndex());
+
+ // Apply the borders to the cell at B2
+ Row row = sheet.createRow(1);
+ Cell cell = row.createCell(1);
+ CellUtil.setCellStyleProperties(cell, properties);
+
+ // Apply the borders to a 3x3 region starting at D4
+ for (int ix=3; ix <= 5; ix++) {
+ row = sheet.createRow(ix);
+ for (int iy = 3; iy <= 5; iy++) {
+ cell = row.createCell(iy);
+ CellUtil.setCellStyleProperties(cell, properties);
+ }
+ }
+ </pre>
+
+
+<p>
+ NOTE: This does not replace the properties of the cell, it merges the properties you have put into the Map with the
+ cell's existing style properties. If a property already exists, it is replaced with the new property. If a property does not
+ exist, it is added. This method will not remove CellStyle properties.
+ </p>
+
</div>
Modified: poi/site/src/documentation/content/xdocs/spreadsheet/quick-guide.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/spreadsheet/quick-guide.xml?rev=1724929&r1=1724928&r2=1724929&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/spreadsheet/quick-guide.xml (original)
+++ poi/site/src/documentation/content/xdocs/spreadsheet/quick-guide.xml Sat Jan 16 07:11:01 2016
@@ -74,6 +74,7 @@
<li><link href="#Autofilter">Autofilters</link></li>
<li><link href="#ConditionalFormatting">Conditional Formatting</link></li>
<li><link href="#Hiding">Hiding and Un-Hiding Rows</link></li>
+ <li><link href="#CellProperties">Setting Cell Properties</link></li>
</ul>
</section>
<section><title>Features</title>
@@ -2153,6 +2154,54 @@ the data to populate another drop down l
method and passing the boolean value 'false'. Secondly, it ilustrates how to test whther a row is hidden or not.
Simply call the getZeroHeight() method and it will return 'true' if the row is hidden, 'false' otherwise.
</p>
- </section>
+ </section>
+ <anchor id="CellProperties"/>
+ <section><title>Setting Cell Properties</title>
+ <p>
+ Sometimes it is easier or more efficient to create a spreadsheet with basic styles and then apply special styles to certain cells
+ such as drawing borders around a range of cells or setting fills for a region. CellUtil.setCellProperties lets you do that without creating
+ a bunch of unnecessary intermediate styles in your spreadsheet.
+ </p>
+ <p>
+ Properties are created as a Map and applied to a cell in the following manner.
+ </p>
+ <source>
+ Workbook workbook = new XSSFWorkbook(); // OR new HSSFWorkbook()
+ Sheet sheet = workbook.createSheet("Sheet1");
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ // border around a cell
+ properties.put(CellUtil.BORDER_TOP, CellStyle.BORDER_MEDIUM);
+ properties.put(CellUtil.BORDER_BOTTOM, CellStyle.BORDER_MEDIUM);
+ properties.put(CellUtil.BORDER_LEFT, CellStyle.BORDER_MEDIUM);
+ properties.put(CellUtil.BORDER_RIGHT, CellStyle.BORDER_MEDIUM);
+
+ // Give it a color (RED)
+ properties.put(CellUtil.TOP_BORDER_COLOR, IndexedColors.RED.getIndex());
+ properties.put(CellUtil.BOTTOM_BORDER_COLOR, IndexedColors.RED.getIndex());
+ properties.put(CellUtil.LEFT_BORDER_COLOR, IndexedColors.RED.getIndex());
+ properties.put(CellUtil.RIGHT_BORDER_COLOR, IndexedColors.RED.getIndex());
+
+ // Apply the borders to the cell at B2
+ Row row = sheet.createRow(1);
+ Cell cell = row.createCell(1);
+ CellUtil.setCellStyleProperties(cell, properties);
+
+ // Apply the borders to a 3x3 region starting at D4
+ for (int ix=3; ix <= 5; ix++) {
+ row = sheet.createRow(ix);
+ for (int iy = 3; iy <= 5; iy++) {
+ cell = row.createCell(iy);
+ CellUtil.setCellStyleProperties(cell, properties);
+ }
+ }
+ </source>
+
+ <p>
+ NOTE: This does not replace the properties of the cell, it merges the properties you have put into the Map with the
+ cell's existing style properties. If a property already exists, it is replaced with the new property. If a property does not
+ exist, it is added. This method will not remove CellStyle properties.
+ </p>
+ </section>
</body>
</document>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org