I try to create a word document with the free version of Spire.DOC.
When I create the document, the exception "Spire.Doc free version is limited to 500 paragraphs" appears. But when I count the number of paragraphs, I count only 311 paragraphs.
Maybe is because every new lign ("\n") is count as a new paragraph?
Can you tell me how you define a paragraph?
I join my code and the console to this post.
Sincerely,
Vancia COLLEONI
- Code: Select all
int nbPara = 0;
Document doc = new Document();
Section section = doc.addSection();
Paragraph para1 = section.addParagraph();
Paragraph para2 = section.addParagraph();
ParagraphStyle style1 = new ParagraphStyle(doc);
style1.setName("titleStyle");
style1.getCharacterFormat().setBold(true);
style1.getCharacterFormat().setTextColor(Color.BLUE);
style1.getCharacterFormat().setFontName("Arial");
style1.getCharacterFormat().setFontSize(20f);
doc.getStyles().add(style1);
para1.applyStyle("titleStyle");
para1.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
ParagraphStyle style2 = new ParagraphStyle(doc);
style2.setName("title2Style");
style2.getCharacterFormat().setBold(true);
style2.getCharacterFormat().setTextColor(Color.BLUE);
style2.getCharacterFormat().setFontName("Arial");
style2.getCharacterFormat().setFontSize(18f);
doc.getStyles().add(style2);
para2.applyStyle("title2Style");
para1.appendText("Résumé des modifications");
nbPara += 1;
try {
for (int i = 0; i < diffs.size(); i ++) {
para2.appendText("\n \n " + textes.get(i + 1).getName() + "\n\n").applyCharacterFormat(style2.getCharacterFormat());
para2.appendText("Dans le fichier " + textes.get(i + 1).getName() + ", on trouve les différences suivantes: \n").applyCharacterFormat(style3.getCharacterFormat());
nbPara += 2;
List<String> diffLign = Arrays.asList(diffs.get(i).getContenu().split("\n"));
for (int j = diffLign.size() - 1; j >= 0; j --) {
para2.appendText("\nLigne: " + diffLign.get(j).substring(diffLign.get(j).indexOf("position revised: ") + 18,
diffLign.get(j).indexOf(", lines: ")) + "\n").applyCharacterFormat(style3.getCharacterFormat());
nbPara += 1;
if (diffLign.get(j).toString().startsWith("[ChangeDelta")) {
para2.appendText("Type: Modification \nAvant: \n" + diffLign.get(j).substring(diffLign.get(j).indexOf("], lines original: [") + 20,
diffLign.get(j).indexOf("], size revised: ")).replaceAll("retourligne", "\r\n") + "\nAprès: \n" +
diffLign.get(j).substring(diffLign.get(j).indexOf(", lines: [") + 10, diffLign.get(j).indexOf("], lines original: ")).replaceAll("retourligne", "\r\n") +
"\n").applyCharacterFormat(style3.getCharacterFormat());
nbPara += 1;
} else if (diffLign.get(j).toString().startsWith("[InsertDelta")) {
para2.appendText("Type: Insertion \nLignes: \n" + diffLign.get(j).substring(diffLign.get(j).indexOf(", lines: [") + 10,
diffLign.get(j).indexOf("], size: ")).replaceAll("retourligne", "\r\n") + "\n").applyCharacterFormat(style3.getCharacterFormat());
nbPara += 1;
} else if (diffLign.get(j).toString().startsWith("[DeleteDelta")) {
para2.appendText("Type: Suppression \nLignes: \n" + diffLign.get(j).substring(diffLign.get(j).indexOf(", lines: ") + 9,
diffLign.get(j).indexOf(", size: ")).replaceAll("retourligne", "\r\n") + "\n").applyCharacterFormat(style3.getCharacterFormat());
nbPara += 1;
}
}
}
System.out.println("nbPara: " + nbPara);
doc.saveToFile(Export, FileFormat.Docx);