Initial commit of the ClosedXML library
Establishes the foundational structure, core Excel functionality, and tooling. - Implements base components for cells, ranges, columns, and rows. - Integrates a custom calculation engine with a wide range of Excel functions. - Adds comprehensive support for styling, conditional formatting, data validation, comments, pictures, and charts. - Configures build setup, project metadata (NuGet), and developer guidelines. - Includes editor and Git attributes for consistent code style and line endings.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using ClosedXML.Excel;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
|
||||
namespace ClosedXML_Examples.Misc
|
||||
{
|
||||
public class AddingDataSet : IXLExample
|
||||
{
|
||||
public void Create(String filePath)
|
||||
{
|
||||
var wb = new XLWorkbook();
|
||||
|
||||
var dataSet = GetDataSet();
|
||||
|
||||
// Add all DataTables in the DataSet as a worksheets
|
||||
wb.Worksheets.Add(dataSet);
|
||||
|
||||
foreach (var ws in wb.Worksheets)
|
||||
ws.Columns().AdjustToContents();
|
||||
|
||||
wb.SaveAs(filePath);
|
||||
}
|
||||
|
||||
private DataSet GetDataSet()
|
||||
{
|
||||
var ds = new DataSet();
|
||||
ds.Tables.Add(GetTable("Patients"));
|
||||
ds.Tables.Add(GetTable("Employees"));
|
||||
ds.Tables.Add(GetTable("Information"));
|
||||
return ds;
|
||||
}
|
||||
|
||||
private DataTable GetTable(String tableName)
|
||||
{
|
||||
DataTable table = new DataTable();
|
||||
table.TableName = tableName;
|
||||
table.Columns.Add("Dosage", typeof(int));
|
||||
table.Columns.Add("Drug", typeof(string));
|
||||
table.Columns.Add("Patient", typeof(string));
|
||||
table.Columns.Add("Date", typeof(DateTime));
|
||||
|
||||
table.Rows.Add(25, "Indocin", "David", new DateTime(2000, 1, 1));
|
||||
table.Rows.Add(50, "Enebrel", "Sam", new DateTime(2000, 1, 2));
|
||||
table.Rows.Add(10, "Hydralazine", "Christoff", new DateTime(2000, 1, 3));
|
||||
table.Rows.Add(21, "Combivent", "Janet", new DateTime(2000, 1, 4));
|
||||
table.Rows.Add(100, "Dilantin", "Melanie", new DateTime(2000, 1, 5));
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user