177 lines
4.2 KiB
C#
177 lines
4.2 KiB
C#
![]() |
using System;
|
|||
|
using System.Text;
|
|||
|
using CPF.ReoGrid.Formula;
|
|||
|
|
|||
|
namespace CPF.ReoGrid.Utility
|
|||
|
{
|
|||
|
public static class CellUtility
|
|||
|
{
|
|||
|
public static void CopyCell(Cell toCell, Cell fromCell)
|
|||
|
{
|
|||
|
toCell.InternalPos = fromCell.InternalPos;
|
|||
|
toCell.Rowspan = fromCell.Rowspan;
|
|||
|
toCell.Colspan = fromCell.Colspan;
|
|||
|
toCell.MergeStartPos = fromCell.MergeStartPos;
|
|||
|
toCell.MergeEndPos = fromCell.MergeEndPos;
|
|||
|
toCell.Bounds = fromCell.Bounds;
|
|||
|
CellUtility.CopyCellContent(toCell, fromCell);
|
|||
|
}
|
|||
|
|
|||
|
public static void CopyCellContent(Cell toCell, Cell fromCell)
|
|||
|
{
|
|||
|
toCell.InnerStyle = new WorksheetRangeStyle(fromCell.InnerStyle);
|
|||
|
toCell.StyleParentKind = fromCell.StyleParentKind;
|
|||
|
toCell.TextBounds = fromCell.TextBounds;
|
|||
|
toCell.RenderHorAlign = fromCell.RenderHorAlign;
|
|||
|
toCell.RenderColor = fromCell.RenderColor;
|
|||
|
toCell.DistributedIndentSpacing = fromCell.DistributedIndentSpacing;
|
|||
|
toCell.DataFormat = fromCell.DataFormat;
|
|||
|
toCell.DataFormatArgs = fromCell.DataFormatArgs;
|
|||
|
toCell.Body = ((fromCell.body == null) ? null : fromCell.body.Clone());
|
|||
|
toCell.InnerData = fromCell.InnerData;
|
|||
|
toCell.InnerDisplay = fromCell.DisplayText;
|
|||
|
toCell.Formula = fromCell.Formula;
|
|||
|
bool flag = fromCell.formulaTree != null;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
toCell.formulaTree = (STNode)fromCell.formulaTree.Clone();
|
|||
|
}
|
|||
|
toCell.FontDirty = fromCell.FontDirty;
|
|||
|
toCell.IsReadOnly = fromCell.IsReadOnly;
|
|||
|
toCell.Tag = fromCell.Tag;
|
|||
|
}
|
|||
|
|
|||
|
public static bool IsNumberData(Cell cell)
|
|||
|
{
|
|||
|
object innerData = cell.InnerData;
|
|||
|
return innerData is double || innerData is int || innerData is float || innerData is long || innerData is byte || innerData is decimal;
|
|||
|
}
|
|||
|
|
|||
|
public static bool IsNumberData(object data)
|
|||
|
{
|
|||
|
return data is double || data is int || data is float || data is long || data is byte || data is decimal;
|
|||
|
}
|
|||
|
|
|||
|
public static bool TryGetNumberData(Cell cell, out double value)
|
|||
|
{
|
|||
|
return CellUtility.TryGetNumberData(cell.InnerData, out value);
|
|||
|
}
|
|||
|
|
|||
|
public static bool TryGetNumberData(object data, out double value)
|
|||
|
{
|
|||
|
bool flag = data is double;
|
|||
|
bool result;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
value = (double)data;
|
|||
|
result = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
bool flag2 = data is int || data is long || data is float || data is byte || data is decimal;
|
|||
|
if (flag2)
|
|||
|
{
|
|||
|
value = (double)Convert.ChangeType(data, typeof(double));
|
|||
|
result = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
bool flag3 = data is string;
|
|||
|
if (flag3)
|
|||
|
{
|
|||
|
result = double.TryParse((string)data, out value);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
value = 0.0;
|
|||
|
result = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public static T ConvertData<T>(object data)
|
|||
|
{
|
|||
|
T result;
|
|||
|
CellUtility.ConvertData<T>(data, out result);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public static bool ConvertData<T>(object data, out T value)
|
|||
|
{
|
|||
|
bool flag = data == null;
|
|||
|
bool result;
|
|||
|
if (flag)
|
|||
|
{
|
|||
|
value = default(T);
|
|||
|
result = false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Type typeFromHandle = typeof(T);
|
|||
|
bool flag2 = data is string;
|
|||
|
if (flag2)
|
|||
|
{
|
|||
|
bool flag3 = typeFromHandle == typeof(string);
|
|||
|
if (flag3)
|
|||
|
{
|
|||
|
value = (T)((object)data);
|
|||
|
return true;
|
|||
|
}
|
|||
|
double num;
|
|||
|
bool flag4 = !double.TryParse((string)data, out num);
|
|||
|
if (flag4)
|
|||
|
{
|
|||
|
value = default(T);
|
|||
|
return false;
|
|||
|
}
|
|||
|
data = num;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
bool flag5 = data is StringBuilder;
|
|||
|
if (flag5)
|
|||
|
{
|
|||
|
bool flag6 = typeFromHandle == typeof(StringBuilder);
|
|||
|
if (flag6)
|
|||
|
{
|
|||
|
value = (T)((object)data);
|
|||
|
return true;
|
|||
|
}
|
|||
|
double num2;
|
|||
|
bool flag7 = !double.TryParse(((StringBuilder)data).ToString(), out num2);
|
|||
|
if (flag7)
|
|||
|
{
|
|||
|
value = default(T);
|
|||
|
return false;
|
|||
|
}
|
|||
|
data = num2;
|
|||
|
}
|
|||
|
}
|
|||
|
bool flag8 = typeFromHandle != typeof(string) && (data is string || data is StringBuilder);
|
|||
|
if (flag8)
|
|||
|
{
|
|||
|
value = default(T);
|
|||
|
result = false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
bool flag9 = typeFromHandle == typeof(double);
|
|||
|
if (flag9)
|
|||
|
{
|
|||
|
bool flag10 = data is char;
|
|||
|
if (flag10)
|
|||
|
{
|
|||
|
data = (int)((char)data);
|
|||
|
}
|
|||
|
}
|
|||
|
value = (T)((object)Convert.ChangeType(data, typeof(T)));
|
|||
|
result = true;
|
|||
|
}
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|