Aspose.Words XLSX File Processor for .NET
The Aspose.Words XLSX File Processor for .NET lets you create, open, modify, and save XLSX workbooks entirely in managed code. Built on a streamlined subset of the Aspose.Cells engine and designed to integrate with the Aspose.Words conversion pipeline, it provides high‑performance Excel generation/editing for server apps, desktop tools, and cloud services—without Office automation.
Focused on XLSX: worksheets, cells, styles, formulas, charts, data import/export, validation, and protection.
Installation and Setup
- Install the NuGet package Aspose.Words (and the XLSX File Processor plugin package, if distributed separately).
- Apply your license at application startup to remove evaluation limits: see Metered Licensing .
- For framework targets and deployment guidance, see Installation .
This plugin uses a trimmed Excel engine internally and does not require Microsoft Excel.
Supported Platforms: Windows, Linux, macOS (.NET Framework, .NET Core, .NET 5/6+, Mono). Runtime: x64/x86; server and desktop environments.
Quick Start: Create and Save an XLSX
using Aspose.Cells; // Engine behind the plugin
// 1) Create a workbook with one worksheet
var wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
sheet.Name = "Report";
// 2) Populate header + data
sheet.Cells["A1"].PutValue("Product");
sheet.Cells["B1"].PutValue("Qty");
sheet.Cells["C1"].PutValue("Price");
sheet.Cells["D1"].PutValue("Total");
sheet.Cells["A2"].PutValue("Keyboard");
sheet.Cells["B2"].PutValue(12);
sheet.Cells["C2"].PutValue(39.99);
sheet.Cells["D2"].Formula = "=B2*C2";
// 3) Style header
var style = wb.CreateStyle();
style.Font.IsBold = true;
style.ForegroundColor = System.Drawing.Color.AliceBlue;
style.Pattern = BackgroundType.Solid;
var flags = new StyleFlag { FontBold = true, CellShading = true };
sheet.Cells.CreateRange("A1", "D1").ApplyStyle(style, flags);
// 4) Auto-fit and save
sheet.AutoFitColumns();
wb.Save("Report.xlsx", SaveFormat.Xlsx);
Load, Edit, and Recalculate
using Aspose.Cells;
var load = new LoadOptions(LoadFormat.Xlsx);
using var fs = File.OpenRead("Input.xlsx");
var wb = new Workbook(fs, load);
// Update a value and a formula
Worksheet ws = wb.Worksheets["Summary"] ?? wb.Worksheets[0];
ws.Cells["B5"].PutValue(1250); // new revenue
ws.Cells["B6"].Formula = "=B5*0.18"; // tax 18%
// Calculate formulas only for this sheet to save time
var calcOpts = new CalculationOptions { CalcStackSize = 2000 };
wb.CalculateFormula(calcOpts);
wb.Save("Updated.xlsx", SaveFormat.Xlsx);
Import Data (DataTable → Worksheet)
using System.Data;
using Aspose.Cells;
DataTable dt = GetData(); // your source
var wb = new Workbook();
var ws = wb.Worksheets[0];
ws.Cells.ImportDataTable(dt, isFieldNameShown: true, firstRow: 0, firstColumn: 0, insertRows: true);
ws.AutoFitColumns();
wb.Save("DataImport.xlsx", SaveFormat.Xlsx);
Insert a Chart (Bound to Data)
var wb = new Workbook();
var ws = wb.Worksheets[0];
// Sample data
ws.Cells["A1"].PutValue("Month");
ws.Cells["B1"].PutValue("Sales");
string[] months = {"Jan","Feb","Mar","Apr"};
int[] sales = {120, 150, 170, 190};
for (int i = 0; i < months.Length; i++) { ws.Cells[i+1,0].PutValue(months[i]); ws.Cells[i+1,1].PutValue(sales[i]); }
// Add chart
int idx = ws.Charts.Add(ChartType.Column, 6, 0, 20, 8);
Chart chart = ws.Charts[idx];
chart.Title.Text = "Monthly Sales";
chart.NSeries.Add("B2:B5", true);
chart.NSeries.CategoryData = "A2:A5";
wb.Save("Chart.xlsx", SaveFormat.Xlsx);
Add Data Validation & Protect a Sheet
var wb = new Workbook();
var ws = wb.Worksheets[0];
// Allow only whole numbers between 1 and 100 in B2:B100
Validation v = ws.Validations[ws.Validations.Add()];
v.Type = ValidationType.WholeNumber;
v.Operator = OperatorType.Between;
v.Formula1 = "1";
v.Formula2 = "100";
CellArea area = CellArea.CreateCellArea("B2", "B100");
v.AddArea(area);
// Protect sheet but allow editing unlocked cells
ws.Protection = new Protection { AllowEditingContent = true };
wb.Save("Validated.xlsx", SaveFormat.Xlsx);
Features and Functionality
Workbook Creation & Loading
- New workbooks with default sheets and styles.
- Load XLSX from file/stream/byte[] with robust error reporting.
- Detect password‑protected packages and invalid structures.
Worksheet Management
- Add/clone/delete/move worksheets; hide/unhide tabs.
- Address by index or name.
Cells & Ranges
- Read/write strings, numbers, dates, booleans.
- Bulk operations over ranges for high throughput.
- Sparse data supported without bloating file size.
Styling & Formatting
- Number formats and custom date/time masks.
- Fonts, fills, borders; named styles for reuse.
- Conditional formatting rules.
Formulas & Recalculation
- All common Excel functions (SUM, AVERAGE, VLOOKUP, IF, etc.).
- Sheet‑scoped or full‑workbook recalculation for performance.
- Access cached and freshly calculated values.
Charts & Graphics
- Column/Bar/Line/Pie/Area/Scatter charts.
- Configure titles, axes, legends, series styles.
- Insert images (PNG/JPEG/BMP) with position and size control.
Data Import/Export
- Import from DataTable, arrays, or
IEnumerable<T>
. - Export ranges back to DataTable/collections.
- Save CSV for lightweight data exchange.
Validation & Protection
- List/number/date/custom validation rules.
- Worksheet protection with selective locks and password.
Performance & Memory
- Streamed writes, batched updates, predictable memory.
- Manual calc mode during bulk operations.
- Dispose promptly (use
using
) to free resources.
Tips & Best Practices
- Batch writes to contiguous ranges; avoid cell‑by‑cell loops when possible.
- Reuse named styles to reduce style duplication overhead.
- Set calculation mode to Manual during large imports, recalc once at the end.
- Validate inputs before writing to avoid exceptions.
- Compress large images before insertion to keep files lean.
- Close/dispose workbooks to flush and free resources.
- When you only need values, prefer cached results to skip recalculation.
FAQ
Do I need Excel installed? No. The engine is fully managed and headless.
Which formats can I read/write? This processor focuses on XLSX. For broader Excel formats (XLS, ODS) use the full Aspose.Cells product.
Can I calculate formulas server‑side?
Yes. Use Workbook.CalculateFormula
with options for performance.
What are the Excel limits? XLSX supports up to 1,048,576 rows × 16,384 columns per worksheet.
How does this relate to Aspose.Words? It integrates into Words‑centric pipelines (e.g., convert Word→XLSX or attach XLSX outputs) while relying on a trimmed Excel engine internally.