We can format Word document in a multi-column newsletter layout by adding columns. This article demonstrates how to add multiple columns to a Word document and specify the column width and the spacing between columns using Spire.Doc for Java.
import com.spire.doc.*; import com.spire.doc.documents.*; public class CreateMutiColumnWordDocument { public static void main(String[] args){ //create a Document object Document document = new Document(); //add a section Section section = document.addSection(); //add 3 columns to the section section.addColumn(100, 20); section.addColumn(100, 20); section.addColumn(100, 20); //add a paragraph to the section Paragraph paragraph = section.addParagraph(); //add a paragraph to the section paragraph = section.addParagraph(); String text = "Spire.Doc for Java is a professional Java Word API that enables Java applications " +"to create, convert, manipulate and print Word documents without using Microsoft Office."; //add text to the paragraph paragraph.appendText(text); //add column break to the paragraph paragraph.appendBreak(BreakType.Column_Break); //add a paragraph to the section paragraph = section.addParagraph(); //add text to the paragraph paragraph.appendText(text); //add column break to the paragraph paragraph.appendBreak(BreakType.Column_Break); //add a paragraph to the section paragraph = section.addParagraph(); //add text to the paragraph paragraph.appendText(text); //add line between columns section.getPageSetup().setColumnsLineBetween(true); //save the resultant document document.saveToFile("Muti-Column Document.docx", FileFormat.Docx_2013); } }
Output: