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:

Remove Blank Lines in Word Document in Java

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);
    }
}

Remove Blank Lines in Word Document in Java

Link to a Specific Slide in Java

2020-11-24 06:14:58 Written by Koohji

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);
    }
}

Link to a Specific Slide in Java

This article will show you how to add lines to Excel worksheets through two points. We could set the point’s location via relative location and Absolute location in pixels.

C#
using Spire.Xls;
using Spire.Xls.Core.Spreadsheet.Shapes;
using System.Drawing;

namespace Word
{
    class Program
    {
        static void Main(string[] args)

        {
            //Initiate a Workbook object and get the first worksheet
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];
            //Add a line with relative location
            XlsLineShape line = worksheet.TypedLines.AddLine() as XlsLineShape;

            //set the column index of the starting point
            line.LeftColumn = 2;
            line.LeftColumnOffset = 2;
            line.TopRow = 5;
            line.TopRowOffset = 10;

            //set the column index of the end point
            line.RightColumn = 10;
            line.RightColumnOffset = 10;
            line.BottomRow =5;
            line.BottomRowOffset = 10; 

            //Set the color
            line.Color = Color.Red;


            //Add a line with Absolute location in pixels
            XlsLineShape line1 = worksheet.TypedLines.AddLine() as XlsLineShape;
            //Set the start point and end point
            line1.StartPoint = new Point(20, 30);
            line1.EndPoint = new Point(200, 30);

            //Set the color
            line1.Color = Color.Blue;
            
            workbook.SaveToFile("Addlines.xlsx", ExcelVersion.Version2013);
            workbook.Dispose();
        }
    }
 }
VB.NET
Imports Spire.Xls
Imports Spire.Xls.Core.Spreadsheet.Shapes
Imports System.Drawing

Namespace Word
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            'Initiate a Workbook object and get the first worksheet
            Dim workbook As Workbook = New Workbook
            Dim worksheet As Worksheet = workbook.Worksheets(0)
            'Add a line with relative location
            Dim line As XlsLineShape = CType(worksheet.TypedLines.AddLine,XlsLineShape)
            'set the column index of the starting point
            line.LeftColumn = 2
            line.LeftColumnOffset = 2
            line.TopRow = 5
            line.TopRowOffset = 10
            'set the column index of the end point
            line.RightColumn = 10
            line.RightColumnOffset = 10
            line.BottomRow = 5
            line.BottomRowOffset = 10
            'Set the color
            line.Color = Color.Red
            'Add a line with Absolute location in pixels
            Dim line1 As XlsLineShape = CType(worksheet.TypedLines.AddLine,XlsLineShape)
            'Set the start point and end point
            line1.StartPoint = New Point(20, 30)
            line1.EndPoint = New Point(200, 30)
            'Set the color
            line1.Color = Color.Blue
            workbook.SaveToFile("Addlines.xlsx", ExcelVersion.Version2013)
            workbook.Dispose
        End Sub 
    End Class
End Namespace

Effective screenshot:

C#/VB.NET Add lines to Excel worksheets through two points

page 123