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

Aspose.Cells FOSS για .NET

Δημιουργήστε, τροποποιήστε και αποθηκεύστε βιβλία εργασίας Excel .xlsx από .NET — δωρεάν και ανοιχτού κώδικα, χωρίς εξάρτηση από το Microsoft Office.

Ανοιχτού Κώδικα .NET Βιβλιοθήκη για Λογιστικά Φύλλα Excel

Το Aspose.Cells FOSS for .NET είναι μια δωρεάν, ανοιχτού κώδικα βιβλιοθήκη με άδεια MIT για εργασία με αρχεία λογιστικών φύλλων Excel σε εφαρμογές .NET. Εγκαταστήστε το με μία εντολή dotnet add package Aspose.Cells_FOSS και αρχίστε να δημιουργείτε βιβλία εργασίας, να διαβάζετε κελιά, να εφαρμόζετε στυλ, να προσθέτετε μορφοποίηση υπό όρους, υπερσυνδέσμους, επικύρωση δεδομένων και αυτόματα φίλτρα — όλα χωρίς να απαιτείται το Microsoft Excel ή οποιαδήποτε εγγενής βιβλιοθήκη Office.

Η βιβλιοθήκη εκθέτει ένα καθαρό API που βασίζεται στα Workbook, Worksheet, Cells και Cell — τα γνωστά αντικείμενα που γνωρίζει κάθε προγραμματιστής λογιστικών φύλλων. Δημιουργήστε ένα Workbook για να φορτώσετε ένα υπάρχον αρχείο .xlsx ή για να δημιουργήσετε ένα κενό, αποκτήστε πρόσβαση στα φύλλα εργασίας μέσω της συλλογής Worksheets, διαβάστε και γράψτε τιμές κελιών με PutValue και εφαρμόστε στυλ μέσω GetStyle()/SetStyle(). Οι τύποι αποθηκεύονται ακριβώς ως συμβολοσειρές και αξιολογούνται από τον προβολέα κατά το άνοιγμα, όχι από τη βιβλιοθήκη κατά το χρόνο εκτέλεσης.

Επειδή η βιβλιοθήκη είναι καθαρά διαχειριζόμενος κώδικας .NET χωρίς εγγενείς εξαρτήσεις, λειτουργεί με τον ίδιο τρόπο σε Windows, macOS, Linux, κοντέινερ Docker και περιβάλλοντα serverless όπως Azure Functions και AWS Lambda. Η άδεια MIT επιτρέπει απεριόριστη εμπορική χρήση χωρίς δικαιώματα, άδειες θέσεων ή χρεώσεις ανά ανάπτυξη.

Read and Write Excel Files

  • XLSX read/write: Open and save workbooks with full round-trip fidelity using Workbook(fileName) and Save(fileName).
  • Cell values: Write string, int, bool, decimal, and DateTime values with Cell.PutValue(value).
  • Cell access: Read values with Cell.StringValue, Cell.Value, and Cell.IntValue.
  • Formulas: Store formula strings via Cell.Formula — evaluated by Excel on open.
  • Worksheet navigation: Access sheets by index or name via Workbook.Worksheets.

Where Aspose.Cells FOSS for .NET Can Be Used

  • Report generation: Build branded Excel reports in .NET server applications.
  • Data export: Write database query results directly to .xlsx without Office.
  • CI/CD automation: Generate test-result workbooks inside Docker or Linux CI.
  • ETL workflows: Read input sheets, transform data, and write output workbooks.
  • Serverless functions: Run inside Azure Functions or AWS Lambda without dependencies.

Cell Styling and Conditional Formatting

  • Font styling: Apply bold, italic, font size, and color via CellStyle.Font.
  • Fill patterns: Set background colors with CellStyle.ForegroundColor and FillPattern.Solid.
  • Conditional formatting: Add FormatConditionType.CellValue, Expression, ColorScale, DataBar, and IconSet rules via Worksheet.ConditionalFormattings.
  • Style normalization: Use StyleRepository.Normalize(style) for consistent style application.
  • Number formats: Assign custom number format strings per cell.

Formatting Use Cases

  • Dashboard reports: Apply color scales and data bars to highlight KPI ranges.
  • Status sheets: Use icon sets to visually categorize row states.
  • Financial workbooks: Format currency and date columns with built-in number formats.
  • Header styling: Bold and color header rows to distinguish them from data rows.

Data Validation and Auto-Filters

  • Validation rules: Add whole-number, decimal, list, and date validations via ValidationCollection.Add().
  • Operators: Use OperatorType.Between, GreaterThan, LessThan, and others.
  • Validation type: Set ValidationType.WholeNumber, Decimal, List, Date, or Custom.
  • Auto-filters: Apply column filters on a range with AutoFilter and AutoFilter.FilterColumns.
  • Cell areas: Define validation ranges using CellArea.CreateCellArea(start, end).

Validation Use Cases

  • Data entry forms: Restrict input to valid ranges before the workbook is shared.
  • Budget templates: Enforce whole-number budget cells with min/max bounds.
  • Reporting pipelines: Validate output data before delivering to stakeholders.
  • List constraints: Lock cells to a pre-defined dropdown list of allowed values.

Hyperlinks, Named Ranges, and Protection

  • Hyperlinks: Add external URLs, internal cell references, and mailto links via HyperlinkCollection.Add().
  • Named ranges: Define global and sheet-scoped named ranges with DefinedNameCollection.Add().
  • Workbook protection: Lock workbook structure using WorkbookProtection.
  • Worksheet protection: Protect individual sheets with Worksheet.Protect().
  • Load diagnostics: Inspect malformed input using LoadDiagnostics and LoadIssue.

Governance and Collaboration Use Cases

  • Template distribution: Protect sheets to prevent accidental formula overwrite.
  • Shared workbooks: Use named ranges to create stable cross-sheet references.
  • Audit trails: Link cells to external documentation URLs via hyperlinks.
  • Input validation: Combine protection with validation to enforce data governance.

Create a Workbook and Write Cells

Install the NuGet package, then create a Workbook, access the first Worksheet, and write values to cells using PutValue. The example demonstrates writing multiple value types and performing a save-and-reload round trip.

dotnet add package Aspose.Cells_FOSS
using Aspose.Cells_FOSS;

var outputPath = "cell-data-roundtrip.xlsx";
var workbook = new Workbook();
var sheet = workbook.Worksheets[0];

sheet.Cells["A1"].PutValue("Hello");
sheet.Cells["B1"].PutValue(123);
sheet.Cells["C1"].PutValue(true);
sheet.Cells["D1"].PutValue(12.5m);
sheet.Cells["F1"].PutValue(10);
sheet.Cells["G1"].Formula = "=F1*2";
workbook.Save(outputPath);

var loaded = new Workbook(outputPath);
var loadedSheet = loaded.Worksheets[0];
Console.WriteLine(loadedSheet.Cells["A1"].StringValue);
Console.WriteLine(loadedSheet.Cells["G1"].Formula);

Apply Conditional Formatting

Add conditional formatting rules to highlight cell ranges. The example applies a between-value rule with a solid fill, an expression rule, a color scale, a data bar, and an icon set.

using Aspose.Cells_FOSS;

var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
sheet.Name = "Conditional Formatting";

for (var i = 0; i < 10; i++)
    sheet.Cells[i, 0].PutValue(i + 1);

var cfCol = sheet.ConditionalFormattings[sheet.ConditionalFormattings.Add()];
cfCol.AddArea(CellArea.CreateCellArea("A1", "A10"));
var rule = cfCol[cfCol.AddCondition(FormatConditionType.CellValue,
    OperatorType.Between, "3", "7")];
var style = rule.Style;
style.Pattern = FillPattern.Solid;
style.ForegroundColor = Color.FromArgb(255, 255, 199, 206);
style.Font.Bold = true;
rule.Style = style;

workbook.Save("conditional-formatting.xlsx");

Add Hyperlinks and Named Ranges

Create external and internal hyperlinks, then define named ranges scoped to the workbook or a specific sheet.

using Aspose.Cells_FOSS;

var workbook = new Workbook();
var sheet = workbook.Worksheets[0];
sheet.Name = "Links";

sheet.Cells["A1"].PutValue("Docs");
var link = sheet.Hyperlinks[sheet.Hyperlinks.Add("A1", 1, 1, "https://example.com/docs")];
link.TextToDisplay = "Docs";
link.ScreenTip = "External docs";

var name = workbook.DefinedNames[workbook.DefinedNames.Add("GlobalRange", "='Links'!$A$1:$D$5")];
name.Comment = "Primary sample range";

workbook.Save("hyperlinks-and-names.xlsx");
  

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

 Ελληνικά