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.
57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using ClosedXML.Excel;
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace ClosedXML_Examples.Ranges
|
|
{
|
|
public class AddingRowToTables : IXLExample
|
|
{
|
|
#region Methods
|
|
|
|
// Public
|
|
public void Create(String filePath)
|
|
{
|
|
string tempFile = ExampleHelper.GetTempFilePath(filePath);
|
|
try
|
|
{
|
|
new BasicTable().Create(tempFile);
|
|
var wb = new XLWorkbook(tempFile);
|
|
var ws = wb.Worksheets.First();
|
|
|
|
var firstCell = ws.FirstCellUsed();
|
|
var lastCell = ws.LastCellUsed();
|
|
var range = ws.Range(firstCell.Address, lastCell.Address);
|
|
range.FirstRow().Delete(); // Deleting the "Contacts" header (we don't need it for our purposes)
|
|
|
|
// We want to use a theme for table, not the hard coded format of the BasicTable
|
|
range.Clear(XLClearOptions.AllFormats);
|
|
// Put back the date and number formats
|
|
range.Column(4).Style.NumberFormat.NumberFormatId = 15;
|
|
range.Column(5).Style.NumberFormat.Format = "$ #,##0";
|
|
|
|
var table = range.CreateTable(); // You can also use range.AsTable() if you want to
|
|
|
|
ws.Cell("Q6000").Value = "dummy value";
|
|
|
|
var row = table.DataRange.InsertRowsBelow(1).First();
|
|
|
|
wb.SaveAs(filePath);
|
|
}
|
|
finally
|
|
{
|
|
if (File.Exists(tempFile))
|
|
{
|
|
File.Delete(tempFile);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Private
|
|
|
|
// Override
|
|
|
|
#endregion Methods
|
|
}
|
|
}
|