|
@@ -13,12 +13,14 @@ using NFont = NPOI.SS.UserModel.IFont;
|
|
|
using NSheet = NPOI.SS.UserModel.ISheet;
|
|
|
using NDataFormat = NPOI.SS.UserModel.IDataFormat;
|
|
|
using NCellStyle = NPOI.SS.UserModel.ICellStyle;
|
|
|
+using NCellType = NPOI.SS.UserModel.CellType;
|
|
|
using NPOI.SS.Util;
|
|
|
using NPOI.OpenXmlFormats.Spreadsheet;
|
|
|
using System.Security.Policy;
|
|
|
using System.Drawing;
|
|
|
using NPOI.HSSF.Util;
|
|
|
using NPOI.HSSF.UserModel;
|
|
|
+using NPOI.XWPF.UserModel;
|
|
|
|
|
|
namespace InABox.Scripting
|
|
|
{
|
|
@@ -164,7 +166,7 @@ namespace InABox.Scripting
|
|
|
{
|
|
|
var result = "";
|
|
|
var cell = _row.GetCell(column, MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
|
|
- if (cell.CellType == CellType.Numeric)
|
|
|
+ if (cell.CellType == NCellType.Numeric)
|
|
|
result = cell.NumericCellValue.ToString();
|
|
|
else
|
|
|
result = cell.StringCellValue;
|
|
@@ -206,9 +208,9 @@ namespace InABox.Scripting
|
|
|
{
|
|
|
double result = 0.0F;
|
|
|
var cell = _row.GetCell(column, MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
|
|
- if (cell.CellType == CellType.Numeric || cell.CellType == CellType.Formula)
|
|
|
+ if (cell.CellType == NCellType.Numeric || cell.CellType == NCellType.Formula)
|
|
|
result = cell.NumericCellValue;
|
|
|
- else if (cell.CellType == CellType.String)
|
|
|
+ else if (cell.CellType == NCellType.String)
|
|
|
result = double.Parse(cell.StringCellValue);
|
|
|
return result;
|
|
|
}
|
|
@@ -279,11 +281,38 @@ namespace InABox.Scripting
|
|
|
Row = row;
|
|
|
}
|
|
|
|
|
|
+ private CellType ConvertCellType(NCellType type)
|
|
|
+ {
|
|
|
+ return type switch
|
|
|
+ {
|
|
|
+ NCellType.Formula => CellType.Numeric,
|
|
|
+ NCellType.Numeric => CellType.Numeric,
|
|
|
+ NCellType.Error => CellType.Error,
|
|
|
+ NCellType.String => CellType.String,
|
|
|
+ NCellType.Boolean => CellType.Boolean,
|
|
|
+ NCellType.Blank => CellType.Blank,
|
|
|
+ _ or NCellType.Unknown => CellType.Unknown
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ public CellType GetCellType()
|
|
|
+ {
|
|
|
+ if (_cell.CellType == NCellType.Formula)
|
|
|
+ {
|
|
|
+ return ConvertCellType(_cell.CachedFormulaResultType);
|
|
|
+ }
|
|
|
+ else if(_cell.CellType == NCellType.Numeric && DateUtil.IsCellDateFormatted(_cell))
|
|
|
+ {
|
|
|
+ return CellType.Date;
|
|
|
+ }
|
|
|
+ return ConvertCellType(_cell.CellType);
|
|
|
+ }
|
|
|
+
|
|
|
public string GetValue()
|
|
|
{
|
|
|
- if (_cell.CellType == CellType.Formula)
|
|
|
+ if (_cell.CellType == NCellType.Formula)
|
|
|
{
|
|
|
- if (_cell.CachedFormulaResultType == CellType.Numeric)
|
|
|
+ if (_cell.CachedFormulaResultType == NCellType.Numeric)
|
|
|
return string.Format("{0:F}", _cell.NumericCellValue.ToString());
|
|
|
return _cell.StringCellValue;
|
|
|
}
|
|
@@ -295,7 +324,7 @@ namespace InABox.Scripting
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- if (_cell.CellType == CellType.Boolean)
|
|
|
+ if (_cell.CellType == NCellType.Boolean)
|
|
|
return _cell.BooleanCellValue;
|
|
|
return null;
|
|
|
}
|
|
@@ -310,9 +339,9 @@ namespace InABox.Scripting
|
|
|
try
|
|
|
{
|
|
|
double result = 0.0F;
|
|
|
- if (_cell.CellType == CellType.Numeric || _cell.CellType == CellType.Formula)
|
|
|
+ if (_cell.CellType == NCellType.Numeric || _cell.CellType == NCellType.Formula)
|
|
|
result = _cell.NumericCellValue;
|
|
|
- else if (_cell.CellType == CellType.String)
|
|
|
+ else if (_cell.CellType == NCellType.String)
|
|
|
result = double.Parse(_cell.StringCellValue);
|
|
|
return result;
|
|
|
}
|
|
@@ -343,9 +372,9 @@ namespace InABox.Scripting
|
|
|
try
|
|
|
{
|
|
|
byte result = 0;
|
|
|
- if (_cell.CellType == CellType.Numeric || _cell.CellType == CellType.Formula)
|
|
|
+ if (_cell.CellType == NCellType.Numeric || _cell.CellType == NCellType.Formula)
|
|
|
result = (byte)_cell.NumericCellValue;
|
|
|
- else if (_cell.CellType == CellType.String)
|
|
|
+ else if (_cell.CellType == NCellType.String)
|
|
|
result = byte.Parse(_cell.StringCellValue);
|
|
|
return result;
|
|
|
}
|
|
@@ -604,7 +633,7 @@ namespace InABox.Scripting
|
|
|
|
|
|
public Spreadsheet(string fileName) : this(WorkbookFactory.Create(fileName)) { }
|
|
|
|
|
|
- public Spreadsheet(FileStream file) : this(WorkbookFactory.Create(file)) { }
|
|
|
+ public Spreadsheet(Stream file) : this(WorkbookFactory.Create(file)) { }
|
|
|
|
|
|
public Spreadsheet() : this(new XSSFWorkbook()) { }
|
|
|
|