Java (481)
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
Spire.Doc for Java supports embedding an external file (Word, Excel, PowerPoint, PDF, picture, video, etc.) in Word documents as an OLE object. This article gives you an example of how to insert a PDF file into a Word document.
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.OleObjectType;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.DocOleObject;
import com.spire.doc.fields.DocPicture;
public class InsertOLE {
public static void main(String[] args) {
//Create a Document object and load a Word document
Document doc = new Document();
doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\source.docx");
//Get the last section
Section section = doc.getLastSection();
//Add a paragraph
Paragraph par = section.addParagraph();
//Load an image which will be inserted to Word document representing the embedded file
DocPicture pdfIcon = new DocPicture(doc);
pdfIcon.loadImage("C:\\Users\\Administrator\\Desktop\\pdf-icon.jpg");
//Insert a PDF file to the Word document as an OLE object
par.appendOleObject("C:\\Users\\Administrator\\Desktop\\report.pdf", pdfIcon, OleObjectType.Adobe_Acrobat_Document);
//Save to another file
doc.saveToFile("EmbedDocument.docx", FileFormat.Docx_2013);
}
}

Published in
Others
Tagged under