EXCELXLSX 1.0.0.3
dotnet add package EXCELXLSX --version 1.0.0.3
NuGet\Install-Package EXCELXLSX -Version 1.0.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EXCELXLSX" Version="1.0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EXCELXLSX" Version="1.0.0.3" />
<PackageReference Include="EXCELXLSX" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EXCELXLSX --version 1.0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EXCELXLSX, 1.0.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EXCELXLSX@1.0.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EXCELXLSX&version=1.0.0.3
#tool nuget:?package=EXCELXLSX&version=1.0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Excel.XLSX
Excel package
This package is used to simplify working excel files. OpenXML has been utilized to process Excel file. It leverages all functionalities of openXML and provide them into a simple interface.
Code snippets
- Read Excel
using (ExcelPackage pck = new ExcelPackage())
{
// Open the Excel file and load it to the ExcelPackage
using (var stream = System.IO.File.OpenRead(FileName))
{
pck.Load(stream);
foreach (ExcelWorkSheet ws in pck.Workbook.Worksheets)
{
}
}
}
- Write Excel
FileInfo file = new FileInfo(FileName);
using (ExcelPackage pck = new ExcelPackage(file))
{
// Add a new worksheet to the empty workbook
ExcelWorkSheet ws = pck.Workbook.Worksheets.Add(sheetName);
// Load data from DataTable to the worksheet
ws.Cells ["A1"].LoadFromDataTable(Data, true);
ws.Cells.AutoFitColumns();
// Add some styling
using (ExcelRange rng = ws.Cells[1, 1, 1, Data.Columns.Count])
{
rng.Style.Font.Bold = false;
rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
rng.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(200, 129, 189));
rng.Style.Font.Color.SetColor(System.Drawing.Color.White);
}
// Save the new workbook
pck.Save();
}
- Access Cells
var file = @"TestSource\marks.xlsx";
using (ExcelPackage pck = new ExcelPackage())
{
// Open the Excel file and load it to the ExcelPackage
using (var stream = System.IO.File.OpenRead(file))
{
pck.Load(stream);
ExcelWorkSheet ws = pck.Workbook.Worksheets["Sheet1"];
using(var rng = ws.Cells[1,1,4,3])
{
foreach(var c in rng)
{
var x = c.Text;
}
}
}
}
- Read Sheet information to DataTable
using (SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(fileName, false))
{
res = new DataTable();
res.Columns.Add("Attribute", typeof(string));
res.Columns.Add("Value", typeof(string));
S sheets = mySpreadsheet.WorkbookPart.Workbook.Sheets;
// For each sheet, display the sheet information.
foreach (E sheet in sheets)
{
foreach (A attr in sheet.GetAttributes())
{
DataRow r = res.NewRow();
r["Attribute"] = attr.LocalName;
r["Value"] = attr.Value;
res.Rows.Add(r);
}
}
}
- Create file with some data validations in cell range
//Assume Data has been set into DataTable called Data
sting file = @"\Testfile.xlsx";
string cellRange = "C3:C100";
string optionsList = "Option1,Option2,Option3"
using (ExcelPackage pck = new ExcelPackage(file))
{
// Add a new worksheet to the empty workbook
ExcelWorkSheet ws = pck.Workbook.Worksheets.Add(sheetName);
// Load data from DataTable to the worksheet
ws.Cells["A1"].LoadFromDataTable(Data, true);
ws.Cells.AutoFitColumns();
//Add data options as list in drop down box
IExcelDataValidationList values = ws.DataValidations.AddListValidation(cellRange);
values.ShowErrorMessage = true;
values.ErrorStyle = ExcelDataValidationWarningStyle.stop;
values.ErrorTitle = "An invalid value was entered";
values.Error = "Select a value from the list";
values.Formula.ExcelFormula = optionsList;
// Add some styling
using (ExcelRange rng = ws.Cells[1, 1, 1, Data.Columns.Count])
{
rng.Style.Font.Bold = true;
rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
rng.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(79, 129, 189));
rng.Style.Font.Color.SetColor(System.Drawing.Color.White);
}
// Save the new workbook
pck.Save();
}
- Iterator Example
// Assume DataTable Data has been loaded into work sheet ws. Then Iterating the worksheet ws to do some operations with the cells
for (int i = 1; i <= Data.Rows.Count; i++)
{
using (ExcelRange rng = ws.Cells[i + 1,1, i + 1, Data.Columns.Count])
{
rng.Style.Font.Bold = true;
rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
foreach (var cell in rng)
{
Console.WriteLine(cell.Text) ;
}
}
}
*** promo Promotions can raise awareness of an important concept.
License
Free to use and to distribute. Just mention it in your code distribution, web site.
Package Name: EXCELXLSX
Author: Amr M. Gody
Email: amr.m.gody@gmail.com
Release Notes
Features | Version | Implemented? |
---|---|---|
Enhanced write speed of huge files | 1.0.0.3 | Yes |
Enhanced Read speed of huge files | 1.0.0.2 | Yes |
Fixed helper.Write functions of multi sheets | 1.0.0.2 | Yes |
Fixed helper.Write functions of adding new sheet in existing file | 1.0.0.2 | Yes |
Enumerate Cells | 1.0.0.1 | Yes |
Read to DataTable | 1.0.0.0 | Yes |
Write from DataTable | 1.0.0.0 | Yes |
OpenXML SDK | 1.0.0.0 | Yes |
Report Bugs or feedback
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- DocumentFormat.OpenXml (>= 2.13.0)
- System.Drawing.Common (>= 5.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.