Knowledgebase (2300)
The slide size is one of the important aspects of the visual design of PowerPoint presentations. It influences the aspect ratio and dimensions of the presentation and can have a significant impact on the overall appearance and atmosphere of the presentation. If the default slide size does not meet the visual design requirements or does not match the size of the screen showing the presentation, it is necessary to change the size of the slides to another preset size or customize a slide size. This article will demonstrate how to change the slide size of PowerPoint presentations through Java programs using Spire.Presentation for Java.
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>10.11.4</version>
</dependency>
</dependencies>
Change the Slide Size to a Preset Size
Spire.Presentation for Java provides the Presentation.getSlideSize().setType() method to change the slide size to a preset size. The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Change the slide type of the presentation using Presentation.getSlideSize().setType() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSizeType;
public class changeSlideSizePreset {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation pt = new Presentation();
//Load a presentation file
pt.loadFromFile("Sample.pptx");
//Change the slide size of the presentation to A4
pt.getSlideSize().setType(SlideSizeType.A4);
//Save the presentation file
pt.saveToFile("A4Size.pptx", FileFormat.AUTO);
pt.dispose();
}
}

Change the Slide Size to a Custom Size
Customizing the size of slides requires changing the slide size type to custom. After that, the Presentation.getSlideSize().setSize() method can be used to customize the slide size. The detailed steps are as follows:
- Create an object of Presentation class.
- Load a PowerPoint presentation using Presentation.loadFromFile() method.
- Change the slide size type to custom using Presentation.getSlideSize().setType() method.
- Customize the slide size using Presentation.getSlideSize().setSize() method.
- Save the presentation using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
import com.spire.presentation.SlideSize;
import com.spire.presentation.SlideSizeType;
import java.awt.*;
public class changeSlideSizeCustom {
public static void main(String[] args) throws Exception {
//Create an object of Presentation class
Presentation pt = new Presentation();
//Load a PowerPoint presentation
pt.loadFromFile("Sample.pptx");
//Change the slide size type to custom
pt.getSlideSize().setType(SlideSizeType.CUSTOM);
//Set the slide size
pt.getSlideSize().setSize(new Dimension(600, 600));
//Save the presentation file
pt.saveToFile("CustomSize.pptx", FileFormat.AUTO);
pt.dispose();
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Spire.XLS for Java provides the getStyle() method and setStyle() method under the IXLSRange interface to get or set the style of a specific cell range. To copy formatting from one cell to another, get the style first and then apply it to another cell.
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
public class CopyCellFormatting {
public static void main(String[] args) {
//Create a Workbook object
Workbook workbook = new Workbook();
//Load the sample Excel file
workbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
//Get the number of rows used
int rowCount = sheet.getRows().length;
//Loop through the rows
for (int i = 1; i < rowCount + 1; i++)
{
//Copy the formatting from a certain cell to another
sheet.getRange().get(String.format("C%d",i)).setStyle(sheet.getRange().get(String.format("A%d",i)).getStyle());
}
//Save the result to file
workbook.saveToFile("output/CopyFormatting.xlsx", ExcelVersion.Version2016);
}
}

Spire.XLS for Java provides you with the ability to shrink text to fit in a cell by using the setShrinkToFit method of the CellStyleObject class. The setShrinkToFit method accepts the following parameter:
boolean: specify whether to shrink text to fit in a cell.
The following example shows how to shrink text to fit in a cell in Excel using Spire.XLS for Java.
import com.spire.xls.*;
public class ShrinkTextToFitInACell {
public static void main(String []args) throws Exception {
//Create a workbook instance
Workbook workbook = new Workbook();
//Load the Excel file
workbook.loadFromFile("Sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
//Get the cell range to shrink text
CellRange cell = sheet.getRange().get("B2:B3");
//Enable “shrink to fit”
cell.getCellStyle().setShrinkToFit(true);
//Save the file
workbook.saveToFile("ShrinkTextToFitInACell.xlsx", ExcelVersion.Version2013);
}
}
The input Excel:

The output Excel:
