Unplanned
Last Updated: 10 Feb 2025 11:09 by ADMIN
Rekha
Created on: 20 Mar 2023 14:32
Category: SpreadStreamProcessing
Type: Feature Request
3
SpreadStreamProcessing: Implement an equivalent of cellValue.GetValueAsString(format)

SpreadProcessing has a method,  cellValue.GetValueAsString(format), which allows the user to apply excel format on a value and get the result. While in SpreadStreamProcessing one could get the format and the value, there is no way to get their result and this is very inconvenient when the values in question are dates.

Workaround:

foreach (ICellImporter cell in rowImporter.Cells)
{
    string value = cell.Value;
    var format = cell.Format.NumberFormat;

    var cellValueFormat = new CellValueFormat(format);
   
    ICellValue cellValue;
    CellValueFormat valueFormat;

    CellValueFactory.Create(
        value,
        worksheet,
        new CellIndex(0, 0),
        cellValueFormat,
        out cellValue,
        out valueFormat);

    var formattedValue = cellValue.GetResultValueAsString(cellValueFormat);
}
2 comments
ADMIN
Yoan
Posted on: 10 Feb 2025 11:09

Hi Kendrick,

Thank you for your thoughtful feedback! We’re grateful for your support and engagement. We truly appreciate the time and effort you put into sharing your insights and I can assure you they do not go unnoticed.

Regards,
Yoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Kendrick
Posted on: 06 Feb 2025 15:54

A possible drop-in solution...

namespace App.Extension;
using Telerik.Documents.SpreadsheetStreaming;
using Telerik.Windows.Documents.Spreadsheet.Model;

public static class CellImporter
{
private static readonly Workbook Workbook = new();
private static readonly Worksheet Worksheet;

static CellImporter()
{
Workbook.Worksheets.Add();
Worksheet = Workbook.ActiveWorksheet;
}

/// <summary>
/// Gets the formatted value of a cell.
/// </summary>
/// <param name="cell"></param>
/// <returns></returns>
public static string GetFormattedValue(this ICellImporter cell)
{
var cellValueFormat = new CellValueFormat(cell.Format.NumberFormat);

CellValueFactory.Create(
cell.Value,
Worksheet,
cell.RowIndex,
cell.ColumnIndex,
cellValueFormat,
out ICellValue cellValue,
out CellValueFormat newFormat);

return cellValue.GetResultValueAsString(cellValueFormat);
}
}