This article will show you how to use Spire.Doc for Java to set the character spacing and paragraph spacing on Word.

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.TextRange;

import java.awt.*;
import java.io.*;

public class setSpacing {
    public static void main(String[] args)throws IOException {
        //Load the sample document
        Document document= new Document("Sample1.docx");

        //Add a new paragraph and append the text
        Paragraph para = new Paragraph(document);
        TextRange textRange1 = para.appendText("Newly added paragraph and set the paragraph spacing and character spacing");
        textRange1.getCharacterFormat().setTextColor(Color.blue);
        textRange1.getCharacterFormat().setFontSize(14);

        //Set the spacing before and after paragraph
        para.getFormat().setBeforeAutoSpacing(false);
        para.getFormat().setBeforeSpacing(10);
        para.getFormat().setAfterAutoSpacing(false);
        para.getFormat().setAfterSpacing(10);

        //Set the character spacing
        for (DocumentObject object :(Iterable<DocumentObject>)para.getChildObjects())
        {
            TextRange textRange= (TextRange) object;
            textRange.getCharacterFormat().setCharacterSpacing(3f);
        }

        //Insert the paragraph
        document.getSections().get(0).getParagraphs().insert(2, para);

        //Save the document to file
        document.saveToFile("Result.docx", FileFormat.Docx);

    }
}

Output:

Java set the character spacing and paragraph spacing on Word document

Add image comment to Excel in Java

2021-05-08 03:26:04 Written by Koohji

We have demonstrated how to add and read text comments in Excel in Java applications. This article will show you how to insert image comment to Excel with Spire.XLS for Java.

import com.spire.xls.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;

public class Test {
    public static void main(String[] args)throws IOException {
        //Load the sample Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Sample.xlsx");
        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //set the font
        ExcelFont font = workbook.createFont();
        font.setFontName("Arial");
        font.setSize(11);
        font.setKnownColor(ExcelColors.Orange);

        CellRange range = sheet.getCellRange("D1");
        //Add the commet
        ExcelComment comment = range.addComment();
        //Load the image
        BufferedImage bufferedImage = ImageIO.read(new File("Logo.jpg"));
        //Use the image to fill the comment
        comment.getFill().customPicture(bufferedImage, "Logo.jpg");

        //Set the height and width for the comment
        comment.setHeight(bufferedImage.getHeight());
        comment.setWidth(bufferedImage.getWidth());
        //Show the comment
        comment.setVisible(true);

        //Save the document to file
        workbook.saveToFile("output/setimageComment.xlsx", ExcelVersion.Version2013);

    }
}

Output:

Add image comment to Excel in Java

This article will show you how to replace the searched text with image in Excel worksheet by using Spire.XLS in Java applications.

Sample Excel:

Java replace the text with image in Excel worksheet

import com.spire.xls.*;
import java.io.IOException;

public class replaceTextwithImage {
    public static void main(String[] args) throws IOException {

        //Load the sample Excel document
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Sample.xlsx");
        //Get the first worksheet
        Worksheet worksheet = workbook.getWorksheets().get(0);

        //Find the text string {{Image}}
        CellRange[] ranges = worksheet.findAllString("{{Image}}", false, false);
        for (CellRange range : ranges) {
            //set the text as null
            range.setText("");

            //get the row and column of the searched range
            int row = range.getRow();
            int column = range.getColumn();
            //Add the image to the searched range
            worksheet.getPictures().add(row, column, "logo.jpg", ImageFormatType.Jpeg);

            //Save the document to file
            workbook.saveToFile("replaceTextwithImage.xlsx", ExcelVersion.Version2013);
            }
        }
    }

Output:

Java replace the text with image in Excel worksheet

page 32