The Excel gridlines run between the columns and row of the spreadsheet, allowing you to see where each individual cell is located. This article will share how to use a free Java API to hide or show gridlines in a Excel worksheet programmatically.
Installation (2 Method)
1# Download the free API (Free Spire.XLS for Java)and unzip it, then add the Spire.Xls.jar file to your project as dependency.
2# You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls.free</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
Sample code
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
public class HideOrShowGridlines {
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\\input.xlsx");
//Get the fisrt worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
//Hide gridlines
worksheet.setGridLinesVisible(false);
//Show gridlines
//worksheet.setGridLinesVisible(true);
//Save the document
workbook.saveToFile("HideGridlines.xlsx", ExcelVersion.Version2016);
}
}
Top comments (0)