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 2015/12/09 07:03:42 UTC
svn commit: r1718764 - in /poi/site: publish/spreadsheet/quick-guide.html
src/documentation/content/xdocs/spreadsheet/quick-guide.xml
Author: onealj
Date: Wed Dec 9 06:03:41 2015
New Revision: 1718764
URL: http://svn.apache.org/viewvc?rev=1718764&view=rev
Log:
update spreadsheet quickguide for bug 57450
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=1718764&r1=1718763&r2=1718764&view=diff
==============================================================================
--- poi/site/publish/spreadsheet/quick-guide.html (original)
+++ poi/site/publish/spreadsheet/quick-guide.html Wed Dec 9 06:03:41 2015
@@ -2091,6 +2091,38 @@ Examples:
</pre>
<p>
+ For SXSSFWorkbooks only, because the random access window is likely to exclude most of the rows
+ in the worksheet, which are needed for computing the best-fit width of a column, the columns must
+ be tracked for auto-sizing prior to flushing any rows.
+ </p>
+
+<pre class="code">
+ SXSSFWorkbook worbook = new SXSSFWorkbook();
+ SXSSFSheet sheet = workbook.createSheet();
+ sheet.trackColumnForAutoSizing(0);
+ sheet.trackColumnForAutoSizing(1);
+ // If you have a Collection of column indices, see SXSSFSheet#trackColumnForAutoSizing(Collection<Integer>)
+ // or roll your own for-loop.
+ // Alternatively, use SXSSFSheet#trackAllColumnsForAutoSizing() if the columns that will be auto-sized aren't
+ // known in advance or you are upgrading existing code and are trying to minimize changes. Keep in mind
+ // that tracking all columns will require more memory and CPU cycles, as the best-fit width is calculated
+ // on all tracked columns on every row that is flushed.
+
+ // create some cells
+ for (int r=0; r < 10; r++) {
+ Row row = sheet.createRow(r);
+ for (int c; c < 10; c++) {
+ Cell cell = row.createCell(c);
+ cell.setCellValue("Cell " + c.getAddress().formatAsString());
+ }
+ }
+
+ // Auto-size the columns.
+ sheet.autoSizeColumn(0);
+ sheet.autoSizeColumn(1);
+ </pre>
+
+<p>
Note, that Sheet#autoSizeColumn() does not evaluate formula cells,
the width of formula cells is calculated based on the cached formula result.
If your workbook has many formulas then it is a good idea to evaluate them before auto-sizing.
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=1718764&r1=1718763&r2=1718764&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/spreadsheet/quick-guide.xml (original)
+++ poi/site/src/documentation/content/xdocs/spreadsheet/quick-guide.xml Wed Dec 9 06:03:41 2015
@@ -1482,6 +1482,36 @@ Examples:
sheet.autoSizeColumn(1); //adjust width of the second column
</source>
<p>
+ For SXSSFWorkbooks only, because the random access window is likely to exclude most of the rows
+ in the worksheet, which are needed for computing the best-fit width of a column, the columns must
+ be tracked for auto-sizing prior to flushing any rows.
+ </p>
+ <source>
+ SXSSFWorkbook worbook = new SXSSFWorkbook();
+ SXSSFSheet sheet = workbook.createSheet();
+ sheet.trackColumnForAutoSizing(0);
+ sheet.trackColumnForAutoSizing(1);
+ // If you have a Collection of column indices, see SXSSFSheet#trackColumnForAutoSizing(Collection<Integer>)
+ // or roll your own for-loop.
+ // Alternatively, use SXSSFSheet#trackAllColumnsForAutoSizing() if the columns that will be auto-sized aren't
+ // known in advance or you are upgrading existing code and are trying to minimize changes. Keep in mind
+ // that tracking all columns will require more memory and CPU cycles, as the best-fit width is calculated
+ // on all tracked columns on every row that is flushed.
+
+ // create some cells
+ for (int r=0; r < 10; r++) {
+ Row row = sheet.createRow(r);
+ for (int c; c < 10; c++) {
+ Cell cell = row.createCell(c);
+ cell.setCellValue("Cell " + c.getAddress().formatAsString());
+ }
+ }
+
+ // Auto-size the columns.
+ sheet.autoSizeColumn(0);
+ sheet.autoSizeColumn(1);
+ </source>
+ <p>
Note, that Sheet#autoSizeColumn() does not evaluate formula cells,
the width of formula cells is calculated based on the cached formula result.
If your workbook has many formulas then it is a good idea to evaluate them before auto-sizing.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org