Transfer Excel Range formatting to word Table formatting

okay, so here is the code I use-
var range = namedRange.GetRange();

if (range != null)
{
if (range.RowCount == 1 && range.ColumnCount == 1)
{
var cell = range[0, 0];
var value = cell.Value;
if (value != null)
{
return Encoding.UTF8.GetBytes(value.ToString());
}
return Array.Empty();
}

here is the sheet I want the values from-
type sheet.zip (6.5 KB)

Say I have a currency value $300 or a short date like 12-02-2021, and i get it using the above code. I want it to return $300 and 12-02-2021 which it is currently not. for any date it return dd-mm-yy hh-mm-ss, and currency is not being passed on.

@Adhirath
Cell.Value returns the original value of the cell, not the display value.
Please try Cell.StringValue or cell.GetStringValue() method

 Workbook sourceWorkbook = new Workbook(dir + "type sheet.xlsx");
  Cells cells = sourceWorkbook.Worksheets[0].Cells;
 
  for(int i = 4; i < 9; i++)
  {
      Cell cell = cells[i,6];
      Console.WriteLine(cell.StringValue + "  : " + cell.GetStringValue(CellValueFormatStrategy.DisplayStyle));

  }

That helps, facing an issue with currency. instead of rupee 300 I am getting this ₹ 300.00 when using the above code. What could be the issue?

It is happening because of the base64encoding i do after I get the value. It doesnt recognize the rupee symbol. Is there a fix for that?

nvm ,got it. Thank you soo much for the help!

@Adhirath
You are welcome. If you have any questions, please feel free to contact us at any time.

1 Like

The issues you have found earlier (filed as CELLSNET-57903,CELLSNET-57925) have been fixed in this update. This message was posted using Bugs notification tool by leoluo

1 Like