-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow per-cell custom placeholders (#253)
* Allow per-cell custom placeholders & ranged placeholders in same row as custom placeholders Up until now, it was not possible to have a ranged placeholder (e.g. {{quotes}}) in the same row as another placeholder. To make this possible, custom excel placeholders now return an object containing information about any offsets and/or column skips resulting from their application. Additionally, the custom excel placeholders now only get passed the cell of the first relevant placeholder, instead of the full row.
- Loading branch information
1 parent
ec1b351
commit 34dc258
Showing
14 changed files
with
186 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ plugins { | |
} | ||
|
||
group 'com.docutools' | ||
version = '2.0.3' | ||
version = '3.0.0' | ||
|
||
java { | ||
toolchain { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/docutools/jocument/impl/excel/interfaces/ExcelPlaceholderData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.docutools.jocument.impl.excel.interfaces; | ||
|
||
import com.docutools.jocument.GenerationOptions; | ||
import com.docutools.jocument.PlaceholderData; | ||
import com.docutools.jocument.impl.excel.util.ModificationInformation; | ||
import java.util.Locale; | ||
import java.util.Optional; | ||
import org.apache.poi.ss.usermodel.Cell; | ||
|
||
/** | ||
* An interface which is used by custom placeholders for Excel reports resolving single cells. | ||
*/ | ||
public interface ExcelPlaceholderData extends PlaceholderData { | ||
/** | ||
* Transformation method for {@link PlaceholderData} needing to insert into excel. Since xlsx generation generates the document newly, as opposed to | ||
* working on a copy (like word generation) we need the possibility to write to the document for some custom placeholders. | ||
* | ||
* @param cell The cell containing the placeholder | ||
* @param excelWriter The {@link ExcelWriter} to write to the excel document | ||
* @param offset any offset that should be regarded when inserting a new cell (caused by e.g. ranged placeholders in the row) | ||
* @param locale the {@link Locale} | ||
* @param options the {@link GenerationOptions} | ||
* @return Modification information specifying the last column number which has been modified by this placeholder (or {@link Optional#empty()} if it | ||
* just modified the passed cell) and whether the custom placeholder application resulted in any offsets in the rows columns. | ||
*/ | ||
ModificationInformation transform(Cell cell, ExcelWriter excelWriter, int offset, Locale locale, GenerationOptions options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/docutools/jocument/impl/excel/util/ModificationInformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.docutools.jocument.impl.excel.util; | ||
|
||
import java.util.Optional; | ||
|
||
public record ModificationInformation(Optional<Integer> skipUntil, int offset) { | ||
|
||
public static ModificationInformation empty() { | ||
return new ModificationInformation(Optional.empty(), 0); | ||
} | ||
|
||
public ModificationInformation merge(ModificationInformation newModificationInformation) { | ||
return new ModificationInformation(newModificationInformation.skipUntil(), offset + newModificationInformation.offset()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.