1. Προϊόντα
  2.   Aspose.Cells
  3.   Cells FOSS for Java

Aspose.Cells FOSS για Java

Ανοιχτού κώδικα βιβλιοθήκη Java 17 για δημιουργία, φόρτωση, τροποποίηση και αποθήκευση βιβλίων εργασίας Excel .xlsx.

Aspose.Cells FOSS — Ανοιχτή Πηγή Java Βιβλιοθήκη Φύλλων Εργασίας

Το Aspose.Cells FOSS for Java είναι μια καθαρά Java 17 βιβλιοθήκη που επιτρέπει στους προγραμματιστές να δημιουργούν, να φορτώνουν, να τροποποιούν και να αποθηκεύουν βιβλία εργασίας Excel .xlsx χωρίς καμία εμπορική εξάρτηση χρόνου εκτέλεσης Aspose. Παρέχει ένα καθαρό δημόσιο API στο πακέτο com.aspose.cells_foss και κυκλοφορεί υπό την άδεια MIT.

Η βιβλιοθήκη καλύπτει το βασικό μοντέλο αντικειμένων λογιστικού φύλλου: βιβλία εργασίας, φύλλα εργασίας, κελιά, στυλ και συλλογές. Οι υποστηριζόμενες δυνατότητες περιλαμβάνουν τιμές κελιών (συμβολοσειρά, αριθμός, boolean, ημερομηνία/ώρα και τύπος), μορφοποίηση κελιών (γραμματοσειρές, περιγράμματα, γεμίσματα, στοίχιση και μορφές αριθμών), AutoFilters, επικύρωση δεδομένων, υπό συνθήκη μορφοποίηση, υπερσυνδέσμους, συγχωνευμένα κελιά, ορισμένα ονόματα, ρύθμιση σελίδας και προστασία φύλλου εργασίας.

Το Aspose.Cells FOSS for Java δημιουργείται με Maven 3.9+ και στοχεύει Java 17+. Προσθέστε το στο έργο σας μέσω μιας μόνο εξάρτησης Maven. Η αποθήκευση αυτή τη στιγμή περιορίζεται στη μορφή .xlsx.

Workbook and Worksheet Management

  • Create new workbooks with new Workbook() using the try-with-resources pattern
  • Access worksheets via getWorksheets().get(index) or by name
  • Rename worksheets with setName(), add and remove sheets, set the active sheet
  • Control worksheet visibility and tab colour via WorksheetViewModel

Who Uses This Feature

  • Generating report workbooks in server-side Java applications
  • Automating multi-sheet Excel document creation in batch pipelines
  • Building template-based spreadsheet generation workflows
  • Splitting or merging workbooks programmatically without Excel installed

Cell Values and Formulas

  • Set cell values with cell.putValue() for String, int, double, boolean, and LocalDateTime
  • Read the value type via CellValueType: STRING, NUMBER, BOOLEAN, DATE_TIME, or FORMULA
  • Store formula strings with cell.setFormula(); value type becomes FORMULA
  • Access a string representation of any cell value via cell.getStringValue()

Who Uses This Feature

  • Populating data tables and financial models in server-generated spreadsheets
  • Writing calculated fields that Excel will re-evaluate on open
  • Reading and converting cell data for downstream processing
  • Building typed data exports from Java domain objects

Cell Formatting and Styles

  • Apply fonts, borders, and fills via the Style class from cell.getStyle()
  • Control alignment via HorizontalAlignment (LEFT, CENTER, RIGHT) and AlignmentValue
  • Set number formats using style.setCustom() or built-in NumberFormat patterns
  • Adjust row height and column width with getRows().get(n).setHeight() and getColumns().get(n).setWidth()

Who Uses This Feature

  • Producing professionally formatted reports without Excel on the server
  • Highlighting data with bold fonts and custom number formats
  • Ensuring column widths fit exported data without manual adjustment
  • Applying consistent branding styles across generated worksheets

AutoFilter, Validation, and Conditional Formatting

  • Set an AutoFilter range with ws.getAutoFilter().setRange()
  • Add filter columns and custom filter criteria via FilterColumn and AutoFilterCustomFilter
  • Define data validation rules using ValidationType and OperatorType with sheet.getValidations().add()
  • Apply conditional formatting via FormatConditionCollection and FormatCondition

Who Uses This Feature

  • Building interactive data tables where end users apply filters in Excel
  • Enforcing numeric or list-based input constraints in shared spreadsheets
  • Highlighting out-of-range values automatically with conditional colour rules
  • Generating audit-ready worksheets with visible data-quality rules

Page Setup and Worksheet Protection

  • Configure print settings with PageSetup: paper size, orientation, fit-to-page, print area
  • Toggle gridlines and headings for printing via PrintOptionsModel
  • Protect worksheets and fine-tune permissions using WorksheetProtectionModel
  • Store hyperlinks in worksheets via Hyperlink and HyperlinkCollection

Who Uses This Feature

  • Generating print-ready invoices and reports from Java back-end services
  • Locking formula cells while allowing data entry in unprotected ranges
  • Embedding navigation links between sheets in generated workbooks
  • Creating standardised output that prints correctly without manual page setup

Create a Workbook, Write Values, and Save

Create a workbook, set cell values and styles, adjust row and column dimensions, and save to an .xlsx file using Workbook.save().

import com.aspose.cells_foss.Cell;
import com.aspose.cells_foss.Style;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

public class Main {
    public static void main(String[] args) {
        try (Workbook workbook = new Workbook()) {
            Worksheet sheet = workbook.getWorksheets().get(0);
            sheet.setName("Report");
            sheet.getCells().get("A1").putValue("Revenue");
            sheet.getCells().get("B1").putValue(12500.75);
            Cell total = sheet.getCells().get("B1");
            Style style = total.getStyle();
            style.getFont().setBold(true);
            style.setCustom("#,##0.00");
            total.setStyle(style);
            sheet.getCells().getRows().get(0).setHeight(22.0);
            sheet.getCells().getColumns().get(1).setWidth(14.5);
            workbook.save("report.xlsx");
        }
    }
}

Load a Workbook with Diagnostics

Load an existing .xlsx file using LoadOptions to enable repair mode, then inspect load diagnostics before saving the modified workbook.

import com.aspose.cells_foss.LoadIssue;
import com.aspose.cells_foss.LoadOptions;
import com.aspose.cells_foss.Workbook;

public class LoadWorkbook {
    public static void main(String[] args) {
        LoadOptions options = new LoadOptions();
        options.setStrictMode(false);
        options.setTryRepairPackage(true);
        options.setTryRepairXml(true);
        try (Workbook workbook = new Workbook("input.xlsx", options)) {
            if (workbook.getLoadDiagnostics().hasRepairs()) {
                for (LoadIssue issue : workbook.getLoadDiagnostics().getIssues()) {
                    System.out.println(issue.getMessage());
                }
            }
            workbook.getDocumentProperties().setAuthor("cells-foss");
            workbook.save("output.xlsx");
        }
    }
}

Data Validation and Conditional Formatting

Add a whole-number validation rule and highlight qualifying cells with bold conditional formatting in a single workbook.

import com.aspose.cells_foss.CellArea;
import com.aspose.cells_foss.FormatCondition;
import com.aspose.cells_foss.FormatConditionCollection;
import com.aspose.cells_foss.FormatConditionType;
import com.aspose.cells_foss.OperatorType;
import com.aspose.cells_foss.Style;
import com.aspose.cells_foss.Validation;
import com.aspose.cells_foss.ValidationType;
import com.aspose.cells_foss.Workbook;
import com.aspose.cells_foss.Worksheet;

public class RulesExample {
    public static void main(String[] args) {
        try (Workbook workbook = new Workbook()) {
            Worksheet sheet = workbook.getWorksheets().get(0);
            int vi = sheet.getValidations().add(new CellArea(1, 0, 10, 1));
            Validation validation = sheet.getValidations().get(vi);
            validation.setType(ValidationType.WHOLE_NUMBER);
            validation.setOperator(OperatorType.BETWEEN);
            validation.setFormula1("1");
            validation.setFormula2("100");
            int cfIndex = sheet.getConditionalFormattings().add();
            FormatConditionCollection conditions = sheet.getConditionalFormattings().get(cfIndex);
            conditions.addArea(CellArea.createCellArea("B2", "B11"));
            int condIndex = conditions.addCondition(
                FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "1", "100");
            FormatCondition condition = conditions.get(condIndex);
            Style style = condition.getStyle();
            style.getFont().setBold(true);
            condition.setStyle(style);
            workbook.save("rules.xlsx");
        }
    }
}
  

Υποστήριξη και Πόροι Μάθησης

 Ελληνικά