mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-05 05:51:34 -05:00
feat: add ColumnAttribute and CellExtensions for BOM parsing
This commit is contained in:
1 parent
45dea4ec2b
commit
094b522644
2 files changed
+38
No files matched your search
@@ -0,0 +1,23 @@
|
||||
using ClosedXML.Excel;
|
||||
|
||||
namespace OpenNest.IO.Bom
|
||||
{
|
||||
public static class CellExtensions
|
||||
{
|
||||
public static int? ToIntOrNull(this IXLCell cell)
|
||||
{
|
||||
if (cell.IsEmpty()) return null;
|
||||
if (cell.DataType == XLDataType.Number) return (int)cell.GetDouble();
|
||||
if (int.TryParse(cell.GetString(), out var i)) return i;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static double? ToDoubleOrNull(this IXLCell cell)
|
||||
{
|
||||
if (cell.IsEmpty()) return null;
|
||||
if (cell.DataType == XLDataType.Number) return cell.GetDouble();
|
||||
if (double.TryParse(cell.GetString(), out var result)) return result;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace OpenNest.IO.Bom
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ColumnAttribute : Attribute
|
||||
{
|
||||
public ColumnAttribute(params string[] names)
|
||||
{
|
||||
Names = names;
|
||||
}
|
||||
|
||||
public string[] Names { get; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user