Skip to content

Commit

Permalink
Fix #143
Browse files Browse the repository at this point in the history
  • Loading branch information
jferard committed Jun 8, 2019
1 parent 6b67427 commit 1548f42
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public void addAutofilter(final Table table, final int r1, final int c1, final i
this.commonOdsDocument.addAutofilter(table, r1, c1, r2, c2);
}

@Override
public void freezeCells(final Table table, final int rowCount, final int colCount) {
this.commonOdsDocument.freezeCells(table, rowCount, colCount);
}

/**
* Saves a file.
* Do not close the writer (see https://github.com/jferard/fastods/issues/138)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,9 @@ public void addAutofilter(final Table table, final int r1, final int c1, final i
final int c2) {
this.odsElements.addAutofilter(table, r1, c1, r2, c2);
}

@Override
public void freezeCells(final Table table, final int rowCount, final int colCount) {
this.odsElements.freezeCells(table, rowCount, colCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public void addAutofilter(final Table table, final int r1, final int c1, final i
this.commonOdsDocument.addAutofilter(table, r1, c1, r2, c2);
}

@Override
public void freezeCells(final Table table, final int rowCount, final int colCount) {
this.commonOdsDocument.freezeCells(table, rowCount, colCount);
}

/**
* Add a cell style for a given data type. Use only if you want to flush data before the end
* of the document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@ public interface OdsDocument {
* @param c2 the right column
*/
void addAutofilter(Table table, int r1, int c1, int r2, int c2);

void freezeCells(Table table, int rowCount, int colCount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.github.jferard.fastods;

import com.github.jferard.fastods.datastyle.DataStyles;
import com.github.jferard.fastods.odselement.OdsElements;
import com.github.jferard.fastods.odselement.StylesContainer;
import com.github.jferard.fastods.odselement.config.ConfigItem;
import com.github.jferard.fastods.odselement.config.ConfigItemMapEntry;
Expand Down Expand Up @@ -98,8 +99,8 @@ public static TableBuilder create(final PositionUtil positionUtil, final WriteUt
final ConfigItemMapEntrySet configEntry = ConfigItemMapEntrySet.createSet(name);
configEntry.add(new ConfigItem("CursorPositionX", "int", "0"));
configEntry.add(new ConfigItem("CursorPositionY", "int", "0"));
configEntry.add(new ConfigItem("HorizontalSplitMode", "short", "0"));
configEntry.add(new ConfigItem("VerticalSplitMode", "short", "0"));
configEntry.add(new ConfigItem("HorizontalSplitMode", "short", OdsElements.SC_SPLIT_NORMAL));
configEntry.add(new ConfigItem("VerticalSplitMode", "short", OdsElements.SC_SPLIT_NORMAL));
configEntry.add(new ConfigItem("HorizontalSplitPosition", "int", "0"));
configEntry.add(new ConfigItem("VerticalSplitPosition", "int", "0"));
configEntry.add(new ConfigItem("ActiveSplitRange", "short", "2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.github.jferard.fastods.TableCell;
import com.github.jferard.fastods.datastyle.DataStyle;
import com.github.jferard.fastods.datastyle.DataStyles;
import com.github.jferard.fastods.odselement.config.ConfigItem;
import com.github.jferard.fastods.odselement.config.ConfigItemMapEntry;
import com.github.jferard.fastods.style.MasterPageStyle;
import com.github.jferard.fastods.style.ObjectStyle;
import com.github.jferard.fastods.style.PageLayoutStyle;
Expand Down Expand Up @@ -59,6 +61,10 @@ public class OdsElements {
"Configurations2/popupmenu/", "Configurations2/progressbar/", "Configurations2/statusbar/",
"Configurations2/toolbar/"};

// LO only
public static final String SC_SPLIT_NORMAL = "0";
public static final String SC_SPLIT_FIX = "2";

/**
* @param positionUtil an util for cell addresses (e.g. "A1")
* @param xmlUtil an XML util
Expand Down Expand Up @@ -225,6 +231,21 @@ public Table addTableToContent(final String name, final int rowCapacity,
return table;
}

/**
* Freeze cells. See https://help.libreoffice.org/Calc/Freezing_Rows_or_Columns_as_Headers
*
* @param table the table to freeze
* @param rowCount the number of rows to freeze (e.g. 1 -> freeze the first row)
* @param colCount the number of cols to freeze.
*/
public void freezeCells(final Table table, final int rowCount, final int colCount) {
final ConfigItemMapEntry tableConfig = table.getConfigEntry();
tableConfig.put(new ConfigItem("HorizontalSplitMode", "short", SC_SPLIT_FIX));
tableConfig.put(new ConfigItem("VerticalSplitMode", "short", SC_SPLIT_FIX));
tableConfig.put(new ConfigItem("HorizontalSplitPosition", "int", String.valueOf(rowCount)));
tableConfig.put(new ConfigItem("VerticalSplitPosition", "int", String.valueOf(colCount)));
}

/**
* Create empty elements for package. Used on save or by the ImmutableElementsFlusher.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static SettingsElement create() {
}

/**
* Add a table config
* Add a table config.
* @param configEntry the config
*/
public void addTableConfig(final ConfigItemMapEntry configEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public interface ConfigItemMapEntry extends ConfigItemCollection<ConfigBlock> {
*/
boolean add(ConfigBlock block);

/**
* Put a block in this entry. Replace existing block with the same name.
* @param block the block to add to this entry. May throw
* @return the previous block or null.
* @throws UnsupportedOperationException if the entry is a singleton or a list
*/
ConfigBlock put(ConfigBlock block);

/**
* Add an ConfigItem to this entry. Shortcut for {@code add(new ConfigItem(name, type, value))}.
* @param name the name of the item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public boolean add(final ConfigBlock block) {
return this.blocks.add(block);
}

@Override
public ConfigBlock put(final ConfigBlock block) {
throw new UnsupportedOperationException();
}

/**
* Remove the block at a given index.
* @param i the index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ public boolean add(final ConfigBlock block) {
return true;
}

@Override
public ConfigBlock put(final ConfigBlock block) {
final String name = block.getName();
return this.blockByName.put(name, block);
}

/**
* @param o the block to remove
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public boolean add(final ConfigBlock block) {
throw new UnsupportedOperationException();
}

@Override
public ConfigBlock put(final ConfigBlock block) {
throw new UnsupportedOperationException();
}

/**
* @param name the name
* @return true if the unique ConfigBlock has that name
Expand Down

0 comments on commit 1548f42

Please sign in to comment.