Java (482)
This article demonstrates how to remove blank lines/empty paragraphs in a Word document by using Spire.Doc for Java.
Below is the sample document which contains many blank lines:

import com.spire.doc.*;
import com.spire.doc.documents.*;
public class removeBlankLines {
public static void main(String[] args) {
//Load the sample document
Document document = new Document();
document.loadFromFile("sample.docx");
//Traverse every section in the word document and remove the null and empty paragraphs
for (Object sectionObj : document.getSections()) {
Section section=(Section)sectionObj;
for (int i = 0; i < section.getBody().getChildObjects().getCount(); i++) {
if ((section.getBody().getChildObjects().get(i).getDocumentObjectType().equals(DocumentObjectType.Paragraph) )) {
String s= ((Paragraph)(section.getBody().getChildObjects().get(i))).getText().trim();
if (s.isEmpty()) {
section.getBody().getChildObjects().remove(section.getBody().getChildObjects().get(i));
i--;
}
}
}
}
//Save the document to file
String result = "removeBlankLines.docx";
document.saveToFile(result, FileFormat.Docx_2013);
}
}

Published in
Paragraph
Tagged under
This article demonstrates how to add a hyperlink that links to a specific slide within the presentation by using Spire.Presnetation for Java.
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.geom.Rectangle2D;
public class LinkToSpecificSlide {
public static void main(String[] args) throws Exception {
//Create a Presentation object
Presentation presentation = new Presentation();
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//Append a slide to it (there are two slides in the presentation including the default one)
presentation.getSlides().append();
//Get the first slide
ISlide firstSlide = presentation.getSlides().get(0);
//Add a shape to it
IAutoShape shape = firstSlide.getShapes().appendShape(ShapeType.RECTANGLE,new Rectangle2D.Float(10, 50, 200, 50));
shape.getFill().setFillType(FillFormatType.NONE);
shape.getLine().setFillType(FillFormatType.NONE);
//Add text to shape
shape.getTextFrame().setText("Jump to the second slide");
//Set a hyperlink for the shape, linking to the second slide
ClickHyperlink hyperlink = new ClickHyperlink(presentation.getSlides().get(1));
shape.setClick(hyperlink);
shape.getTextFrame().getTextRange().setClickAction(hyperlink);
//Save to another file
presentation.saveToFile("LinkToSlide.pptx", FileFormat.PPTX_2013);
}
}

Published in
Hyperlink
Tagged under
Add Trendline to Chart and Read Trendline Equation in Excel in Java
2020-11-17 08:12:33 Written by KoohjiThis article demonstrates how to add Trendline to an Excel chart and read the equation of the Trendline using Spire.XLS for Java.
Add Trendline
import com.spire.xls.*;
import com.spire.xls.core.IChartTrendLine;
import java.awt.*;
public class AddTrendline {
public static void main(String[] args){
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load the Excel file
workbook.loadFromFile("test.xlsx");
//Get the first chart in the first worksheet
Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);
//Add a Trendline to the first series of the chart
IChartTrendLine trendLine = chart.getSeries().get(0).getTrendLines().add(TrendLineType.Linear);
//Set Trendline name
trendLine.setName("Linear(Series1)");
//Set line type and color
trendLine.getBorder().setPattern(ChartLinePatternType.DashDot);
trendLine.getBorder().setColor(Color.blue);
//Set forward and backward value
trendLine.setForward(0.5);
trendLine.setBackward(0.5);
//Set intercept value
trendLine.setIntercept(5);
//Display equation on chart
trendLine.setDisplayEquation(true);
//Display R-Squared value on chart
trendLine.setDisplayRSquared(true);
//Save the result file
workbook.saveToFile("AddTrendline.xlsx", ExcelVersion.Version2013);
}
}

Read Trendline equation
import com.spire.xls.Chart;
import com.spire.xls.Workbook;
import com.spire.xls.core.IChartTrendLine;
public class ReadEquationOfTrendline {
public static void main(String[] args){
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load the Excel file
workbook.loadFromFile("AddTrendline.xlsx");
//Get the first chart in the first worksheet
Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);
//Read the equation of the first series of the chart
IChartTrendLine trendLine = chart.getSeries().get(0).getTrendLines().get(0);
String equation = trendLine.getFormula();
System.out.println("The equation is: " + equation);
}
}

Published in
Chart
Tagged under