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.
80 lines
1.7 KiB
C#
80 lines
1.7 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using ClosedXML.Excel;
|
|
|
|
namespace ClosedXML_Examples.Misc
|
|
{
|
|
public class AddingDataTableAsWorksheet : IXLExample
|
|
{
|
|
#region Variables
|
|
|
|
// Public
|
|
|
|
// Private
|
|
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
// Public
|
|
|
|
// Private
|
|
|
|
// Override
|
|
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
// Public
|
|
|
|
// Private
|
|
|
|
// Override
|
|
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
// Public
|
|
public void Create(String filePath)
|
|
{
|
|
var wb = new XLWorkbook();
|
|
|
|
var dataTable = GetTable("Information");
|
|
|
|
// Add a DataTable as a worksheet
|
|
wb.Worksheets.Add(dataTable);
|
|
wb.Worksheets.First().Columns().AdjustToContents();
|
|
|
|
wb.SaveAs(filePath);
|
|
}
|
|
|
|
// Private
|
|
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;
|
|
}
|
|
// Override
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|