diff options
author | Martin Maher <mmaher@openoffice.org> | 2003-03-04 10:10:38 +0000 |
---|---|---|
committer | Martin Maher <mmaher@openoffice.org> | 2003-03-04 10:10:38 +0000 |
commit | 24096ec9fe2637c32257ad409d42086ea0addcb0 (patch) | |
tree | 50ac097526c936bbd04f2e3a5c2c8c88069423e0 /xmerge | |
parent | 7f3227613748eb62b1648e54e1082854c1a6dda6 (diff) |
Added support for default style formatting in columns
Diffstat (limited to 'xmerge')
7 files changed, 109 insertions, 56 deletions
diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeConstants.java b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeConstants.java index f396f4f95059..de6253f67dae 100644 --- a/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeConstants.java +++ b/xmerge/java/org/openoffice/xmerge/converter/xml/OfficeConstants.java @@ -276,8 +276,15 @@ public interface OfficeConstants { public final static String ATTRIBUTE_TABLE_VALUE_TYPE = "table:value-type"; /** + * Attribute tag for <i>table:default-cell-style-name</i> + * of element <i>table:table-column</i>. + */ + public final static String ATTRIBUTE_DEFAULT_CELL_STYLE = + "table:default-cell-style-name"; + + /** * Attribute tag for <i>table:number-columns-repeated</i> - * of element <i>table:table-cell</i>. + * of element <i>table:table-column</i>. */ public final static String ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED = "table:number-columns-repeated"; diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SheetSettings.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SheetSettings.java index 3bb4f4ff4ce4..311c161cb621 100644 --- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SheetSettings.java +++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SheetSettings.java @@ -86,7 +86,7 @@ public class SheetSettings implements OfficeConstants { private int posRight = 0; private int posBottom = 0; private int posTop = 0; - private int paneNumber = 0; + private int paneNumber = 2; final public static int NONE = 0x00; final public static int SPLIT = 0x01; diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentSerializer.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentSerializer.java index cf3d0c2313cd..a9229e8e74cd 100644 --- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentSerializer.java +++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/SxcDocumentSerializer.java @@ -64,6 +64,7 @@ import org.w3c.dom.Element; import java.io.IOException; import java.util.Vector; +import java.util.Enumeration; import org.openoffice.xmerge.Document; import org.openoffice.xmerge.ConvertData; @@ -527,13 +528,38 @@ public abstract class SxcDocumentSerializer implements OfficeConstants, Debug.log(Debug.TRACE, "traverseColumn() : "); NamedNodeMap cellAtt = node.getAttributes(); Node tableStyleNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_STYLE_NAME); - Node tableNumColRepeatingNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED); + Node tableDefaultCellStyle = cellAtt.getNamedItem(ATTRIBUTE_DEFAULT_CELL_STYLE); + int repeatedColumns = 1; + int columnWidth = 0; + ColumnRowInfo col = new ColumnRowInfo(ColumnRowInfo.COLUMN); if(tableNumColRepeatingNode!=null) { Debug.log(Debug.TRACE, "traverseColumn() repeated-cols : " + tableNumColRepeatingNode.getNodeValue()); repeatedColumns = Integer.parseInt(tableNumColRepeatingNode.getNodeValue()); + col.setRepeated(repeatedColumns); + } + + String cellStyleName = new String(""); + + if(tableDefaultCellStyle!=null) { + cellStyleName = tableDefaultCellStyle.getNodeValue(); + + Debug.log(Debug.TRACE, "traverseColumn() default-cell-style : " + cellStyleName); + } + + if(cellStyleName.equalsIgnoreCase("Default") || cellStyleName.length()==0) { + + Debug.log(Debug.TRACE, "No default cell Style Attribute was found"); + + } else { + + CellStyle cellStyle = (CellStyle)styleCat.lookup(cellStyleName, + SxcConstants.TABLE_CELL_STYLE_FAMILY, null, + CellStyle.class); + Format defaultFmt = new Format(cellStyle.getFormat()); + col.setFormat(defaultFmt); } String styleName = new String(""); @@ -552,17 +578,12 @@ public abstract class SxcDocumentSerializer implements OfficeConstants, SxcConstants.COLUMN_STYLE_FAMILY, null, ColumnStyle.class); - int columnWidth = cStyle.getColWidth(); - + columnWidth = cStyle.getColWidth(); + col.setSize(columnWidth); Debug.log(Debug.TRACE, "traverseColumn() Column Width : " + columnWidth); - ColumnRowInfo col = new ColumnRowInfo( columnWidth, - repeatedColumns, ColumnRowInfo.COLUMN); - ColumnRowList.add(col); - } - - + ColumnRowList.add(col); } /** @@ -613,10 +634,24 @@ public abstract class SxcDocumentSerializer implements OfficeConstants, styleName = tableStyleNode.getNodeValue(); } - if(styleName.equalsIgnoreCase("Default") || styleName.length()==0) { + if(styleName.equalsIgnoreCase("Default")) { Debug.log(Debug.TRACE, "No defined Style Attribute was found"); + // if there is no style we need to check to see if there is a default + // cell style defined in the table-column + } else if (styleName.length()==0) { + int index = 1; + for(Enumeration e = ColumnRowList.elements();e.hasMoreElements();) { + ColumnRowInfo cri = (ColumnRowInfo) e.nextElement(); + if(cri.isColumn()) { + if(colID>=index && colID<(index+cri.getRepeated())) { + fmt = new Format(cri.getFormat()); + } + index += cri.getRepeated(); + } + } + } else { CellStyle cStyle = (CellStyle)styleCat.lookup(styleName, diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/ColInfo.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/ColInfo.java index c9b9cc94ee84..b2fa5b8cd646 100644 --- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/ColInfo.java +++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/ColInfo.java @@ -86,13 +86,13 @@ public class ColInfo implements BIFFRecord { * @param coldx column width * @param grbit options flags */ - public ColInfo(int colFirst, int colLast, int colDX, byte grbit) { + public ColInfo(int colFirst, int colLast, int colDX, int ixfe) { this.colFirst = EndianConverter.writeShort((short)colFirst); this.colLast = EndianConverter.writeShort((short)colLast); colDX *= scale; this.colDX = EndianConverter.writeShort((short)colDX); - this.ixfe = EndianConverter.writeShort((short)0); - this.grbit = grbit; + this.ixfe = EndianConverter.writeShort((short)ixfe); + this.grbit = 0x00; } /** diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Pane.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Pane.java index 62799e0163c4..e8f2035840dc 100644 --- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Pane.java +++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Pane.java @@ -82,7 +82,7 @@ public class Pane implements BIFFRecord { * Default Constructor */ public Pane() { - + pnnAcct = (byte) 0x02; // Default setting } /** diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Workbook.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Workbook.java index e9edb914a385..3201b0c469b4 100644 --- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Workbook.java +++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Workbook.java @@ -69,7 +69,7 @@ import org.openoffice.xmerge.converter.xml.sxc.SheetSettings; import org.openoffice.xmerge.util.Debug; import org.openoffice.xmerge.util.IntArrayList; import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelConstants; - +import org.openoffice.xmerge.converter.xml.sxc.ColumnRowInfo; /** * This class is used by <code> PxlDocument</code> to maintain pexcel @@ -271,7 +271,11 @@ OfficeConstants { * * @param f the font recrod to add */ - public int addExtendedFormat(ExtendedFormat xf) { + public int addExtendedFormat(Format fmt) throws IOException { + + FontDescription fd = new FontDescription(fmt); + int ixfnt = addFont(fd); + ExtendedFormat xf = new ExtendedFormat(ixfnt, fmt); boolean alreadyExists = false; int i = 0; @@ -407,10 +411,7 @@ OfficeConstants { throws IOException { Worksheet currentWS = (Worksheet) worksheets.elementAt(worksheets.size()-1); - FontDescription fd = new FontDescription(fmt); - int ixfnt = addFont(fd); - ExtendedFormat xf = new ExtendedFormat(ixfnt, fmt); - int ixfe = addExtendedFormat(xf); + int ixfe = addExtendedFormat(fmt); String category = fmt.getCategory(); @@ -453,11 +454,41 @@ OfficeConstants { * Will create a number of ColInfo recrods based on the column widths * based in. * - * @param an integer list representing the column widths + * @param columnRows <code>Vector</code> of <code>ColumnRowInfo</code> */ - public void addColInfo(Vector columnRows) { + public void addColInfo(Vector columnRows) throws IOException { + Worksheet currentWS = (Worksheet) worksheets.elementAt(worksheets.size()-1); - currentWS.addColRows(columnRows); + + int nCols = 0; + int nRows = 0; + + Debug.log(Debug.TRACE,"Worksheet: addColInfo : " + columnRows); + for(Enumeration e = columnRows.elements();e.hasMoreElements();) { + ColumnRowInfo cri =(ColumnRowInfo) e.nextElement(); + int ixfe = 0; + int size = cri.getSize(); + int repeated = cri.getRepeated(); + if(cri.isColumn()) { + Debug.log(Debug.TRACE,"Worksheet: adding ColInfo width = " + size); + ColInfo newColInfo = new ColInfo( nCols, + nCols+repeated, + size, ixfe); + currentWS.addCol(newColInfo); + nCols += repeated; + } else if(cri.isRow()) { + Debug.log(Debug.TRACE,"Worksheet: adding Row Height = " + size); + if(size!=255) { + for(int i=0;i<repeated;i++) { + Row newRow = new Row(nRows++, size); + currentWS.addRow(newRow); + } + } else { + // If it is the Default Row we don't need to add it + nRows += repeated; + } + } + } } /** diff --git a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Worksheet.java b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Worksheet.java index 7351faf53f7f..7b4e904ea25e 100644 --- a/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Worksheet.java +++ b/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/pexcel/records/Worksheet.java @@ -65,7 +65,6 @@ import java.awt.Point; import org.openoffice.xmerge.util.IntArrayList; import org.openoffice.xmerge.util.Debug; import org.openoffice.xmerge.converter.xml.sxc.SheetSettings; -import org.openoffice.xmerge.converter.xml.sxc.ColumnRowInfo; import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelConstants; @@ -275,39 +274,20 @@ public class Worksheet { * * @param list of column widths */ - public void addColRows(Vector columnWidths) { - - int nCols = 0; - int nRows = 0; - - Debug.log(Debug.TRACE,"Worksheet: addColInfo : " + columnWidths); - for(Enumeration e = columnWidths.elements();e.hasMoreElements();) { - ColumnRowInfo cri =(ColumnRowInfo) e.nextElement(); - int size = cri.getSize(); - int repeated = cri.getRepeated(); - if(cri.isColumn()) { - Debug.log(Debug.TRACE,"Worksheet: adding ColInfo width = " + size); - ColInfo newColInfo = new ColInfo( nCols, - nCols+repeated, - size, (byte) 2); - colInfo.add(newColInfo); - nCols += repeated; - } else if(cri.isRow()) { - Debug.log(Debug.TRACE,"Worksheet: adding Row Height = " + size); - if(size!=255) { - for(int i=0;i<repeated;i++) { - Row newRow = new Row(nRows++, size); - rows.add(newRow); - } - } else { - // If it is the Default Row we don't need to add it - nRows += repeated; - } - } - } + public void addRow(Row r) { + rows.add(r); } /** + * Adds a number of ColInfo Records to the worksheet base on a list of + * clumnwidths passed in + * + * @param list of column widths + */ + public void addCol(ColInfo c) { + colInfo.add(c); + } + /** * Returns an <code>Enumeration</code> to the ColInfo's for this worksheet * * @return an <code>Enumeration</code> to the ColInfo's |