News Category

Create Filter in Excel in Java

2020-02-10 09:35:14 Written by  support iceblue
Rate this item
(0 votes)

This article demonstrates how to create filter in an Excel file using Spire.XLS for Java.

import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class CreateFilter {
    public static void main(String[] args){
        //Load an Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Example.xlsx.xlsx");
        
        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Create filter
        sheet.getAutoFilters().setRange(sheet.getCellRange("A1:J1"));

        //Save the result file
        workbook.saveToFile("CreateFilter.xlsx", ExcelVersion.Version2010);
    }
}

Output:

Create Filter in Excel in Java

Additional Info

  • tutorial_title:
Last modified on Wednesday, 01 September 2021 02:34