Skip to content

Commit

Permalink
Merge pull request #84 from DDS-GmbH/feature/poi_5.1.0
Browse files Browse the repository at this point in the history
Upgrade to apache poi 5.1.0
  • Loading branch information
AntonOellerer authored Nov 2, 2021
2 parents c58f142 + fc9e459 commit 05f9e89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.docutools'
version = '1.2.10'
version = '1.2.11'

sourceCompatibility = 17
targetCompatibility = 17
Expand All @@ -24,7 +24,7 @@ repositories {
}
}

def apachePOIVersion = '5.0.0'
def apachePOIVersion = '5.1.0'

dependencies {
implementation('commons-beanutils:commons-beanutils:1.9.4')
Expand All @@ -44,7 +44,7 @@ dependencies {

testImplementation('org.junit.jupiter:junit-jupiter:5.8.1')
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("com.docutools:poipath:1.1.4")
testImplementation("com.docutools:poipath:1.1.5")
}

tasks.withType(Checkstyle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.apache.poi.xwpf.usermodel.IBodyElement;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

class WordGenerator {
private static final Logger logger = LogManager.getLogger();
Expand Down Expand Up @@ -70,10 +68,9 @@ private void transform(IBodyElement element, List<IBodyElement> remaining) {
private void transform(XWPFTable table) {
table.getRows()
.stream()
.map(XWPFTableRow::getTableCells)
.flatMap(List::stream)
.map(XWPFTableCell::getParagraphs)
.flatMap(List::stream)
.flatMap(xwpfTableRow -> xwpfTableRow.getTableCells().stream())
.flatMap(xwpfTableCell -> xwpfTableCell.getParagraphs().stream())
.filter(xwpfParagraph -> !xwpfParagraph.isEmpty())
.forEach(this::transform);
logger.debug("Transformed table {}", table);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ private static void cloneTable(XWPFTable original, XWPFTable clone) {
ctTcPr = ctTc.addNewTcPr();
}
ctTcPr.set(cell.getCTTc().getTcPr());
if (newCell.getParagraphs().size() > 0) {
// The new cell might be created with empty paragraphs which we do not need, so we remove them here
IntStream.range(0, newCell.getParagraphs().size()).forEach(value -> newCell.removeParagraph(0));
}
cell.getParagraphs()
.forEach(paragraph -> {
XWPFParagraph newParagraph = newCell.addParagraph();
Expand Down

0 comments on commit 05f9e89

Please sign in to comment.