Unplanned
Last Updated: 13 Feb 2023 14:21 by Maik
Maik
Created on: 13 Feb 2023 14:21
Category: SpreadProcessing
Type: Feature Request
0
SpreadProcessing: Implement API for DefinedNames to return formatted result

The Value property of DefinedName (implementing ISpreadsheetName) always returns a result with a General format, which is very impractical when the value is for example a date. There should be an option to get a formatted result as well.

A possible workaround for this missing functionality would be to parse the RefersTo value and find where it points in order to grab the format:

Workbook workbook = new Workbook();
Worksheet ws = workbook.Worksheets.Add();
ws.Cells[0, 1].SetValue("2/1/2013");

ws.Names.Add("MyField", "=Sheet1!$B$1", new CellIndex(0, 0), "My Field");

string value = ws.Names["MyField"].Value;

CellRange range;
bool success = NameConverter.TryConvertCellRangeNameToCellRange(ws.Names["MyField"].RefersTo, out range);

CellValueFormat format = ws.Cells[range].GetFormat().Value;
string result = ws.Cells[range].GetValue().Value.GetResultValueAsString(format);

0 comments