Format text as real text in Excel export

3 posts, 1 answers
  1. Thomas
    Thomas avatar
    17 posts
    Member since:
    Jan 2011

    Posted 20 Aug 2014 Link to this post

    Hi,
    I'm using the example http://demos.telerik.com/silverlight/#SpreadProcessing/RadGridViewIntegration to implement an Excel export for my RadGridView.

    How can I format a string to a text column in Excel? I have a value of "001" and if I use

    worksheet.Cells[currentRowIndex, currentColumnIndex].SetValue((string)value);

    it uses a NumberCellValue internally (because it thinks that "001" is a number") and formats the cell as a number instead of text and puts "1" instead of "001" into the Excel file.

    Since the constructor of TextCellValue is internal (I have no clue why) I can't even create an instance of this type. CellValueFactory creates a NumberCellValue, too. So I'm basically stuck here. Is there any way for FORCING my cell to use the string as it is and format it as text in Excel so that I can have the "001" as the cell value?
  2. Answer
    Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    103 posts

    Posted 21 Aug 2014 Link to this post

    Hello Thomas,

    All it needs to be done so the cell is formatted as text is to set the NumberFormat of the cell to be text. It can be achieved using the following line of code:
    worksheet.Cells[currentRowIndex, currentColumnIndex].SetFormat(new CellValueFormat("@"));

    I suggest you to set the format on the whole range that will be formatted as text, because it will work faster compared to setting each cell the same format.

    This article describes how to use the Number Formatting.

    If you have any further questions, please do not hesitate to contact us again.

    Regards,
    Nikolay Demirev
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. Thomas
    Thomas avatar
    17 posts
    Member since:
    Jan 2011

    Posted 22 Aug 2014 in reply to Nikolay Demirev Link to this post

    Thanks, that was just what I needed :-).
Back to Top