Java (482)
Worksheets with a lot of complex and detailed information are difficult to read and analyze. To create a more compact and understandable spreadsheet view, you can organize data in groups and collapse the rows with similar content.
This article demonstrates how to programmatically group or ungroup rows and columns in Excel using Spire.XLS for Java.
Install Spire.XLS for Java
First of all, you're required to add the Spire.Xls.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.xls</artifactId>
<version>16.3.2</version>
</dependency>
</dependencies>
Group Rows and Columns in Java
The following are the steps to group rows and columns using Spire.XLS for Java.
- Create a Workbook object.
- Load a sample Excel file using Workbook.loadFromFile() method.
- Get the specific sheet using Workbook.getWorksheets().get() method.
- Group rows using Worksheet.groupByRows() method.
- Group columns using Worksheet.groupByColumns() method.
- Save the result to another Excel file using Workbook.saveToFile() method.
- Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
public class GroupRowsAndColumns {
public static void main(String[] args) {
//Create a Workbook object
Workbook workbook = new Workbook();
//Load a sample Excel file
workbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
//Group rows
sheet.groupByRows(2, 5, false);
sheet.groupByRows(7, 10, false);
//Group columns
sheet.groupByColumns(5, 6, false);
//Save to another Excel file
workbook.saveToFile("GroupRowsAndColumns.xlsx", ExcelVersion.Version2016);
}
}

Ungroup Rows and Columns in Java
The following are the steps to ungroup rows and columns using Spire.XLS for Java.
- Create a Workbook object.
- Load a sample Excel file using Workbook.loadFromFile() method.
- Get the specific sheet using Workbook.getWorksheets().get() method.
- Ungroup rows using Worksheet.ungroupByRows() method.
- Ungroup columns using Worksheet.ungroupByColumns() method.
- Save the result to another Excel file using Workbook.saveToFile() method.
- Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
public class UngroupRowsAndColumns {
public static void main(String[] args) {
//Create a Workbook object
Workbook workbook = new Workbook();
//Load a sample Excel file
workbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\ample.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
//Ungroup rows
sheet.ungroupByRows(2, 5);
sheet.ungroupByRows(7, 10);
//Ungroup columns
sheet.ungroupByColumns(5, 6);
//Save to a different Excel file
workbook.saveToFile("UngroupRowsAndColumns.xlsx", ExcelVersion.Version2016);
}
}

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.
The Tagged Image File Format (TIFF) is a relatively flexible image format which has the advantages of not requiring specific hardware, as well as being portable. Spire.PDF for Java supports converting TIFF to PDF and vice versa. This article will show you how to programmatically convert PDF to TIFF using it from the two aspects below.
Install Spire.PDF for Java
First of all, you're required to add the Spire.Pdf.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.pdf</artifactId>
<version>12.4.4</version>
</dependency>
</dependencies>
Convert All Pages of a PDF File to TIFF
The following steps show you how to convert all pages of a PDF file to a TIFF file.
- Create a PdfDocument instance.
- Load a PDF sample document using PdfDocument.loadFromFile() method.
- Save all pages of the document to a TIFF file using PdfDocument.saveToTiff(String tiffFilename) method.
- Java
import com.spire.compression.TiffCompressionTypes;
import com.spire.pdf.PdfDocument;
public class PDFToTIFF {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a PDF sample document
pdf.loadFromFile("sample.pdf");
//Save all pages of the document to Tiff
pdf.saveToTiff("output/PDFtoTiff.tiff");
}
}

Convert Some Specified Pages of a PDF File to TIFF
The following steps are to convert specified pages of a PDF document to a TIFF file.
- Create a PdfDocument instance.
- Load a PDF sample document using PdfDocument.loadFromFile() method.
- Save specified pages of the document to a TIFF file using PdfDocument.saveToTiff(String tiffFilename, int startPage, int endPage, int dpix, int dpiy) method.
- Java
import com.spire.pdf.PdfDocument;
public class PDFToTIFF {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a PDF sample document
pdf.loadFromFile("sample.pdf");
//Save specified pages of the document to TIFF and set horizontal and vertical resolution
pdf.saveToTiff("output/ToTiff2.tiff",0,1,400,600);
}
}

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.
TIFF or TIF files are image files saved in the tagged image file format. They are often used for storing high-quality color images. Sometimes, you may wish to convert TIFF files to PDF so you can share them more easily. In this article, you will learn how to achieve this task programmatically in Java using Spire.PDF for Java library.
Install Spire.PDF for Java
First of all, you're required to add the Spire.Pdf.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.pdf</artifactId>
<version>12.4.4</version>
</dependency>
</dependencies>
Convert TIFF to PDF in Java
The following are the steps to convert a TIFF file to PDF:
- Create an instance of PdfDocument class.
- Add a page to the PDF using PdfDocument.getPages().add() method.
- Create a PdfImage object from the TIFF image using PdfImage.fromFile() method.
- Draw the image onto the page using PdfPageBase.getCanvas().drawImage() method.
- Save the result file using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.graphics.PdfImage;
public class ConvertTiffToPdf {
public static void main(String[] args){
//Create a PdfDocument instance
PdfDocument doc = new PdfDocument();
//Add a page
PdfPageBase page = doc.getPages().add();
//Create a PdfImage object from the TIFF image
PdfImage tiff = PdfImage.fromFile("Input.tiff");
//Draw the image to the page
page.getCanvas().drawImage(tiff, 20, 0, 450, 450);
//Save the result file
doc.saveToFile("TiffToPdf.pdf", FileFormat.PDF);
}
}

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.