DEV Community


Posted on

Hide or Show Gridlines in Excel in Java

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.

Enter fullscreen mode Exit fullscreen mode

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

        //Get the fisrt worksheet
        Worksheet worksheet = workbook.getWorksheets().get(0);

        //Hide gridlines

        //Show gridlines

        //Save the document
        workbook.saveToFile("HideGridlines.xlsx", ExcelVersion.Version2016);
Enter fullscreen mode Exit fullscreen mode


Top comments (0)