How to change the celltype on subscript

Posted by: unclechao on 8 September 2017, 2:56 pm EST

  • Posted 8 September 2017, 2:56 pm EST

    hello,

     i find a problem that how to set the cell's text with superscript and subscript

  • Replied 8 September 2017, 2:56 pm EST

    Hello,

    Using RichTextEditor Class' s SelectionCharOffset
    property, you should be able to set if you want the text to be appear as
    a subscript or superscript the same way it is done with RichTextBox. Here is a sample code that implements the same:

        Dim rtb As New System.Windows.Forms.RichTextBox
        rtb.Text = "e=mc2"
        rtb.SelectionStart = 4
        rtb.SelectionLength = 1
        rtb.SelectionCharOffset = Font.Height / 2
        rtb.SelectedText = "2"
        FpSpread1.ActiveSheet.Cells(0, 0).Renderer = New FarPoint.Win.Spread.CellType.RichTextCellType()

        FpSpread1.ActiveSheet..Cells(0, 0).Value = rtb.Rtf
        rtb.Dispose()

    Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 2:56 pm EST

    thank you,

    but if you double click the cell , it show some code like this 

    {\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fcharset134 \'cb\'ce\'cc\'e5;}}

    \viewkind4\uc1\pard\lang2052\f0\fs18 e=mc\dn10 2\up0\par

    }

  • Replied 8 September 2017, 2:56 pm EST

    Hello,

    You are setting the renderer for the cell, which only paints the value in the specified format into the cell, however the value of the cell is still the rich text assigned to it, and you see the same value when the cell enters the edit mode. You can set the celltype of the cell to RichTextCellType so that the cell displays and contains the same value. Below is the code for the same:

        Dim rtb As New System.Windows.Forms.RichTextBox
        rtb.Text = "e=mc2"
        rtb.SelectionStart = 4
        rtb.SelectionLength = 1
        rtb.SelectionCharOffset = -(Font.Height / 2)
        rtb.SelectedText = "2"
        FpSpread1.ActiveSheet.Cells(0, 0).CellType = New FarPoint.Win.Spread.CellType.RichTextCellType()

        FpSpread1.ActiveSheet..Cells(0, 0).Value = rtb.Rtf
        rtb.Dispose()

    The code posted in the last post is used to set the superscript while the code posted here is used to set the subscript, all you need to do is to provide a negative value to the CharOffset property. Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 2:56 pm EST

    thank you ,

    you still don't know what I mean,if i double click the cell,

    it show some other code,

    I only want it show the value with superscript or subscript

  • Replied 8 September 2017, 2:56 pm EST

    Hello,

    If you set the celltype of the cell to RichTextCellType, it would display the same value even on the double click. The code I provide to you in the last post sets the celltype, and hence displays the same value on double click. Kindly use the code posted in the last response to resolve your issue. Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels