aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorShawn Laubach <slaubach@apache.org>2006-01-21 16:36:18 +0000
committerShawn Laubach <slaubach@apache.org>2006-01-21 16:36:18 +0000
commit315e9657d8687c3b1b9ab466573856bb58584d34 (patch)
tree16665d559f76430f2fe16d97df10e3680afa9017 /src/java/org
parent33484b31f980955de0b791ac448c77fe36a6c0a8 (diff)
downloadpoi-315e9657d8687c3b1b9ab466573856bb58584d34.tar.gz
poi-315e9657d8687c3b1b9ab466573856bb58584d34.zip
Added the ability to set the default style for an individual column in a sheet.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@371080 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/poi/hssf/model/Sheet.java13
-rw-r--r--src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java23
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java10
3 files changed, 33 insertions, 13 deletions
diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java
index d173ec4350..1ee2bb8fd2 100644
--- a/src/java/org/apache/poi/hssf/model/Sheet.java
+++ b/src/java/org/apache/poi/hssf/model/Sheet.java
@@ -44,7 +44,7 @@ import java.util.List; // normally I don't do this, buy we literally mean ALL
* <P>
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Glen Stampoultzis (glens at apache.org)
- * @author Shawn Laubach (slaubach at apache dot org) Gridlines, Headers, Footers, and PrintSetup
+ * @author Shawn Laubach (slaubach at apache dot org) Gridlines, Headers, Footers, PrintSetup, and Setting Default Column Styles
* @author Jason Height (jheight at chariot dot net dot au) Clone support. DBCell & Index Record writing support
* @author Brian Sanders (kestrel at burdell dot org) Active Cell support
*
@@ -1848,9 +1848,18 @@ public class Sheet implements Model
if (columns == null)
columns = new ColumnInfoRecordsAggregate();
- columns.setColumn( column, width, level, hidden, collapsed );
+ columns.setColumn( column, null, width, level, hidden, collapsed );
}
+ public void setColumn(short column, Short xfStyle, Short width, Integer level, Boolean hidden, Boolean collapsed)
+ {
+ if (columns == null)
+ columns = new ColumnInfoRecordsAggregate();
+
+ columns.setColumn( column, xfStyle, width, level, hidden, collapsed );
+ }
+
+
/**
* Creates an outline group for the specified columns.
* @param fromColumn group from this column (inclusive)
diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java
index 1486db41dc..517ea4a115 100644
--- a/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java
+++ b/src/java/org/apache/poi/hssf/record/aggregates/ColumnInfoRecordsAggregate.java
@@ -269,7 +269,7 @@ public class ColumnInfoRecordsAggregate
columnInfo = writeHidden( columnInfo, idx, true );
// Write collapse field
- setColumn( (short) ( columnInfo.getLastColumn() + 1 ), null, null, null, Boolean.TRUE);
+ setColumn( (short) ( columnInfo.getLastColumn() + 1 ), null, null, null, null, Boolean.TRUE);
}
public void expandColumn( short columnNumber )
@@ -307,7 +307,7 @@ public class ColumnInfoRecordsAggregate
}
// Write collapse field
- setColumn( (short) ( columnInfo.getLastColumn() + 1 ), null, null, null, Boolean.FALSE);
+ setColumn( (short) ( columnInfo.getLastColumn() + 1 ), null, null, null, null, Boolean.FALSE);
}
/**
@@ -327,7 +327,7 @@ public class ColumnInfoRecordsAggregate
}
- public void setColumn(short column, Short width, Integer level, Boolean hidden, Boolean collapsed)
+ public void setColumn(short column, Short xfIndex, Short width, Integer level, Boolean hidden, Boolean collapsed)
{
ColumnInfoRecord ci = null;
int k = 0;
@@ -345,11 +345,12 @@ public class ColumnInfoRecordsAggregate
if (ci != null)
{
+ boolean styleChanged = xfIndex != null && ci.getXFIndex() != xfIndex.shortValue();
boolean widthChanged = width != null && ci.getColumnWidth() != width.shortValue();
boolean levelChanged = level != null && ci.getOutlineLevel() != level.intValue();
boolean hiddenChanged = hidden != null && ci.getHidden() != hidden.booleanValue();
boolean collapsedChanged = collapsed != null && ci.getCollapsed() != collapsed.booleanValue();
- boolean columnChanged = widthChanged || levelChanged || hiddenChanged || collapsedChanged;
+ boolean columnChanged = styleChanged || widthChanged || levelChanged || hiddenChanged || collapsedChanged;
if (!columnChanged)
{
// do nothing...nothing changed.
@@ -357,7 +358,7 @@ public class ColumnInfoRecordsAggregate
else if ((ci.getFirstColumn() == column)
&& (ci.getLastColumn() == column))
{ // if its only for this cell then
- setColumnInfoFields( ci, width, level, hidden, collapsed );
+ setColumnInfoFields( ci, xfIndex, width, level, hidden, collapsed );
}
else if ((ci.getFirstColumn() == column)
|| (ci.getLastColumn() == column))
@@ -378,7 +379,7 @@ public class ColumnInfoRecordsAggregate
nci.setLastColumn(column);
nci.setOptions(ci.getOptions());
nci.setXFIndex(ci.getXFIndex());
- setColumnInfoFields( nci, width, level, hidden, collapsed );
+ setColumnInfoFields( nci, xfIndex, width, level, hidden, collapsed );
insertColumn(k, nci);
}
@@ -393,7 +394,7 @@ public class ColumnInfoRecordsAggregate
nci.setLastColumn(column);
nci.setOptions(ci.getOptions());
nci.setXFIndex(ci.getXFIndex());
- setColumnInfoFields( nci, width, level, hidden, collapsed );
+ setColumnInfoFields( nci, xfIndex, width, level, hidden, collapsed );
insertColumn(++k, nci);
nci = ( ColumnInfoRecord ) createColInfo();
@@ -413,7 +414,7 @@ public class ColumnInfoRecordsAggregate
nci.setFirstColumn(column);
nci.setLastColumn(column);
- setColumnInfoFields( nci, width, level, hidden, collapsed );
+ setColumnInfoFields( nci, xfIndex, width, level, hidden, collapsed );
insertColumn(k, nci);
}
}
@@ -421,8 +422,10 @@ public class ColumnInfoRecordsAggregate
/**
* Sets all non null fields into the <code>ci</code> parameter.
*/
- private void setColumnInfoFields( ColumnInfoRecord ci, Short width, Integer level, Boolean hidden, Boolean collapsed )
+ private void setColumnInfoFields( ColumnInfoRecord ci, Short xfStyle, Short width, Integer level, Boolean hidden, Boolean collapsed )
{
+ if (xfStyle != null)
+ ci.setXFIndex(xfStyle.shortValue());
if (width != null)
ci.setColumnWidth(width.shortValue());
if (level != null)
@@ -500,7 +503,7 @@ public class ColumnInfoRecordsAggregate
level = Math.min(7, level);
fromIdx = columnIdx - 1; // subtract 1 just in case this column is collapsed later.
}
- setColumn((short)i, null, new Integer(level), null, null);
+ setColumn((short)i, null, null, new Integer(level), null, null);
columnIdx = findColumnIdx( i, Math.max(0, fromIdx ) );
collapseColInfoRecords( columnIdx );
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
index 7cf9ac6ede..fa207870f1 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
@@ -1331,5 +1331,13 @@ public class HSSFSheet
sheet.setRowGroupCollapsed( row, collapse );
}
-
+ /**
+ * Sets the default column style for a given column. POI will only apply this style to new cells added to the sheet.
+ *
+ * @param fromCol the starting column index
+ * @param column the column index
+ */
+ public void setDefaultColumnStyle(short column, HSSFCellStyle style) {
+ sheet.setColumn(column, new Short(style.getIndex()), null, null, null, null);
+ }
}