本文整理汇总了C#中ICell.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ICell.ToString方法的具体用法?C# ICell.ToString怎么用?C# ICell.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICell
的用法示例。
在下文中一共展示了ICell.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCellValue
/// <summary>
/// 根据Excel列类型获取列的值
/// </summary>
/// <param name="cell">Excel列</param>
/// <returns></returns>
private static string GetCellValue(ICell cell)
{
if (cell == null)
return string.Empty;
switch (cell.CellType)
{
case CellType.BLANK:
return string.Empty;
case CellType.BOOLEAN:
return cell.BooleanCellValue.ToString();
case CellType.ERROR:
return cell.ErrorCellValue.ToString();
case CellType.NUMERIC:
case CellType.Unknown:
default:
return cell.ToString();//This is a trick to get the correct value of the cell. NumericCellValue will return a numeric value no matter the cell value is a date or a number
case CellType.STRING:
return cell.StringCellValue;
case CellType.FORMULA:
try
{
HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook);
e.EvaluateInCell(cell);
return cell.ToString();
}
catch
{
return cell.NumericCellValue.ToString();
}
}
}
示例2: GetTemplate
string GetTemplate(ICell cell)
{
if (cell == null)
return null;
var expr = cell.ToString().Trim();
if (string.IsNullOrEmpty(expr))
return null;
var match = REG_Template.Match(expr);
if (!match.Success)
return null;
var template = match.Groups[1].Value;
return template;
}
示例3: ReSizeColumnWidth
/// <summary>
/// 根据单元格内容重新设置列宽
/// </summary>
/// <param name="sheet"></param>
/// <param name="cell"></param>
public static void ReSizeColumnWidth(ISheet sheet, ICell cell)
{
int cellLength = (Encoding.Default.GetBytes(cell.ToString()).Length + 5) * 256;
const int maxLength = 255 * 256;
if (cellLength > maxLength)
{
cellLength = maxLength;
}
int colWidth = sheet.GetColumnWidth(cell.ColumnIndex);
if (colWidth < cellLength)
{
sheet.SetColumnWidth(cell.ColumnIndex, cellLength);
}
}
示例4: CellValueTyper
private object CellValueTyper(ICell cell)
{
if (cell.CellType == CellType.Blank)
return string.Empty;
if (cell.CellType == CellType.Boolean)
return cell.BooleanCellValue;
if (cell.CellType == CellType.Numeric)
return cell.NumericCellValue;
if (cell.CellType == CellType.String)
return cell.StringCellValue;
return cell.ToString();
}
示例5: ReadCell
/// <summary>
/// 读取单元格数据
/// </summary>
/// <param name="cell">要读取数据的单元格</param>
public object ReadCell(ICell cell, CellDataType cellDataType)
{
if (cellDataType == CellDataType.Boolean)
{
return cell.BooleanCellValue;
}
else if (cellDataType == CellDataType.Date)
{
return cell.DateCellValue;
}
else if (cellDataType == CellDataType.DateTime)
{
return cell.DateCellValue;
}
else if (cellDataType == CellDataType.Double)
{
return cell.NumericCellValue;
}
else if (cellDataType == CellDataType.Formula)
{
return cell.CellFormula;
}
else if (cellDataType == CellDataType.Int)
{
return (int)cell.NumericCellValue;
}
else if (cellDataType == CellDataType.RichText)
{
return cell.RichStringCellValue;
}
else if (cellDataType == CellDataType.Text)
{
return cell.ToString();
}
else if (cellDataType == CellDataType.None)
{
return string.Empty;
}
else if (cellDataType == CellDataType.Null)
{
return null;
}
return null;
}
示例6: GetCellValue
public void GetCellValue(ICell cell, JToken token)
{
if (cell == null) return;
var str = cell.ToString().Trim();
token[Bind] = str;
}
示例7: GetCellValue
/// <summary>
/// 根据Excel列类型获取列的值
/// </summary>
/// <param name="cell">Excel列</param>
/// <returns></returns>
private static string GetCellValue(ICell cell)
{
if (cell == null)
return string.Empty;
switch (cell.CellType)
{
case CellType.Blank:
return string.Empty;
case CellType.Boolean:
return cell.BooleanCellValue.ToString();
case CellType.Error:
return cell.ErrorCellValue.ToString();
default:
return cell.ToString();//This is a trick to get the correct value of the cell. NumericCellValue will return a numeric value no matter the cell value is a date or a number
case CellType.String:
return cell.StringCellValue;
case CellType.Formula:
try
{
HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook);
e.EvaluateInCell(cell);
return cell.ToString();
}
catch
{
return cell.NumericCellValue.ToString();
}
}
}