Skip to content

Commit a9617fb

Browse files
Examples 18.1
Examples for Aspose.Words for Java 18.1 have been added
1 parent 6f42ce8 commit a9617fb

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-4
lines changed

Examples/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
<dependency>
3838
<groupId>com.aspose</groupId>
3939
<artifactId>aspose-words</artifactId>
40-
<version>17.12</version>
40+
<version>18.1</version>
4141
<classifier>jdk16</classifier>
4242
</dependency>
4343
<dependency>
4444
<groupId>com.aspose</groupId>
4545
<artifactId>aspose-words</artifactId>
46-
<version>17.12</version>
46+
<version>18.1</version>
4747
<classifier>javadoc</classifier>
4848
</dependency>
4949
<dependency>

Examples/src/main/java/com/aspose/words/examples/mail_merge/HandleMailMergeSwitches.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void fieldMerging(FieldMergingArgs e) throws Exception {
3333

3434
if (e.getFieldName().startsWith("HTML")) {
3535
if (e.getField().getFieldCode().contains("\\b")) {
36-
FieldMergeField field = (FieldMergeField) e.getField();
36+
FieldMergeField field = e.getField();
3737

3838
DocumentBuilder builder = new DocumentBuilder(e.getDocument());
3939
builder.moveToMergeField(e.getDocumentFieldName(), true, false);

Examples/src/main/java/com/aspose/words/examples/programming_documents/charts/WorkingWithChartAxis.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static void main(String[] args) throws Exception {
1818
SetNumberFormatForAxis(dataDir);
1919
SetboundsOfAxis(dataDir);
2020
SetIntervalUnitBetweenLabelsOnAxis(dataDir);
21+
HideChartAxis(dataDir);
2122
}
2223

2324
public static void DefineXYAxisProperties(String dataDir) throws Exception {
@@ -96,7 +97,7 @@ public static void SetDateTimeValuesToAxis(String dataDir) throws Exception {
9697
xAxis.setMajorTickMark(AxisTickMark.CROSS);
9798
xAxis.setMinorTickMark(AxisTickMark.OUTSIDE);
9899

99-
dataDir = dataDir + "SetDateTimeValuesToAxis_out.pdf";
100+
dataDir = dataDir + "SetDateTimeValuesToAxis_out.docx";
100101
doc.save(dataDir);
101102
// ExEnd:SetDateTimeValuesToAxis
102103
System.out.println("\nDateTime values are set for chart axis successfully.\nFile saved at " + dataDir);
@@ -178,4 +179,31 @@ public static void SetIntervalUnitBetweenLabelsOnAxis(String dataDir) throws Exc
178179
// ExEnd:SetIntervalUnitBetweenLabelsOnAxis
179180
System.out.println("\nSet interval unit between labels on an axis successfully.\nFile saved at " + dataDir);
180181
}
182+
183+
public static void HideChartAxis(String dataDir) throws Exception
184+
{
185+
// ExStart:HideChartAxis
186+
Document doc = new Document();
187+
DocumentBuilder builder = new DocumentBuilder(doc);
188+
189+
// Insert chart.
190+
Shape shape = builder.insertChart(ChartType.COLUMN, 432, 252);
191+
Chart chart = shape.getChart();
192+
193+
// Clear demo data.
194+
chart.getSeries().clear();
195+
196+
// Fill data.
197+
chart.getSeries().add("AW Series 1",
198+
new String[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" },
199+
new double[] { 1.2, 0.3, 2.1, 2.9, 4.2 });
200+
201+
// Hide the Y axis.
202+
chart.getAxisY().setHidden(true);
203+
204+
dataDir = dataDir + "HideChartAxis_out.docx";
205+
doc.save(dataDir);
206+
// ExEnd:HideChartAxis
207+
System.out.println("\nY Axis of chart has been hidden successfully.\nFile saved at " + dataDir);
208+
}
181209
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.aspose.words.examples.programming_documents.find_replace;
2+
3+
import com.aspose.words.examples.Utils;
4+
import com.aspose.words.*;
5+
6+
/**
7+
* Created by awaishafeez on 1/3/2018.
8+
*/
9+
public class ReplaceHtmlTextWithMeta_Characters {
10+
public static void main(String[] args) throws Exception {
11+
// ExStart:ReplaceHtmlTextWithMetaCharacters
12+
// The path to the documents directory.
13+
String dataDir = Utils.getSharedDataDir(ReplaceTextWithField.class) + "FindAndReplace/";
14+
String html = "<p>&ldquo;Some Text&rdquo;</p>";
15+
16+
// Initialize a Document.
17+
Document doc = new Document();
18+
19+
// Use a document builder to add content to the document.
20+
DocumentBuilder builder = new DocumentBuilder(doc);
21+
builder.write("{PLACEHOLDER}");
22+
23+
FindReplaceOptions findReplaceOptions = new FindReplaceOptions();
24+
findReplaceOptions.setReplacingCallback(new FindAndInsertHtml());
25+
findReplaceOptions.setPreserveMetaCharacters(true);
26+
27+
doc.getRange().replace("{PLACEHOLDER}", html, findReplaceOptions);
28+
29+
dataDir = dataDir + "ReplaceHtmlTextWithMetaCharacters_out.doc";
30+
doc.save(dataDir);
31+
// ExEnd:ReplaceHtmlTextWithMetaCharacters
32+
System.out.println("\nText replaced with meta characters successfully.\nFile saved at " + dataDir);
33+
}
34+
35+
// ExStart:ReplaceHtmlFindAndInsertHtml
36+
static class FindAndInsertHtml implements IReplacingCallback {
37+
public int replacing(ReplacingArgs e) throws Exception {
38+
// This is a Run node that contains either the beginning or the complete match.
39+
Node currentNode = e.getMatchNode();
40+
// create Document Buidler and insert MergeField
41+
DocumentBuilder builder = new DocumentBuilder((Document) e.getMatchNode().getDocument());
42+
builder.moveTo(currentNode);
43+
builder.insertHtml(e.getReplacement());
44+
currentNode.remove();
45+
//Signal to the replace engine to do nothing because we have already done all what we wanted.
46+
return ReplaceAction.SKIP;
47+
}
48+
}
49+
// ExEnd:ReplaceHtmlFindAndInsertHtml
50+
}

0 commit comments

Comments
 (0)