[{"id":"29a4ab0f-edd1-45e1-87df-0b8b4bb068b3","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"64b61a79-5817-4746-b591-28d4d5462c0a","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"6edef660-641f-4cd8-84f6-571130f37ae2","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"89a3ee5c-06c4-49c4-ac61-8325ba4bcca1","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"1e898427-e706-440e-9077-b35c7a5b8f46","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"4266ec12-a87a-444b-a8af-beff39a7defe","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"fd867fe6-72e0-4e45-bbac-edc72e608b08","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"fad338cd-7c96-48b9-a12d-1b979ba886b2","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"6fb42249-b832-4656-9137-35d9948bea1c","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"6e353a93-c1d4-4387-bad5-4a07fd18ed3a","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"acbe820e-65b4-4bd6-bcf3-a9d5b16163da","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"167a076a-6a93-49f6-8bf8-adee9abd9817","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"7fb1e240-d39d-4391-986f-c2d40adfb011","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"09cc5e9f-99c9-4258-b69c-ca5bb09a6b16","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"0b4ea8fb-4e7b-4028-9393-d1177a68ec17","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"35b8ea08-9ca6-49eb-a021-0c806de4ff96","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"7bace066-1638-4034-82eb-0db8c15f5bd1","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"7ec5ea8e-419f-40aa-b67d-301fa3e7b025","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"38f78942-4ca0-4631-a2d8-32dcfd6157a6","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"fc1d5e2a-5d1c-4479-ac87-c726c03d49aa","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"dd70702b-48a7-4896-b92d-db78ff9e52b0","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"cda2a866-9746-4790-9942-13c450ece8a1","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"3239f53b-81be-4d67-ae63-7ca0d6ce0f91","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"74c2daa1-efb0-4d3e-bd0c-8d11b297c92d","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"a4268f67-693d-4933-9e22-a77d68880a13","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"9f17896b-55b4-4627-8b6d-b01fdabdffe7","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"e45c5458-c148-4de7-a471-e2e3808d841e","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"ac44f25f-d7e5-46a3-a247-33e23e20e956","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"feb10296-b21e-4506-8d7e-567ed4dda994","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"ebba2e23-2c8d-4948-8cca-91ce71b3183d","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"ebdc80a9-26fc-4420-af7f-e576e4f12820","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"2cb68b65-34df-4322-911c-ead14627af13","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"0f2df6ef-74f6-42d5-a6ff-fb830bac6bc1","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"1feb74f5-775b-4809-80bb-1757ff6070f9","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"d8afaaaf-0174-4a14-8ba1-59043a985e91","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"7fd72fd2-933b-4816-81d1-b9e9d86b7c2c","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"9cf8d438-a37d-4dea-b0dd-e15d187e19ed","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"01561aea-2cd9-4883-a29a-1a7b9df2e432","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"ec2f2f29-d5a6-4fa0-aa61-353d48af9d1b","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"efb477ff-7d55-4163-a55e-a3c64415f6a4","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"c2302058-2cde-443c-a67f-e77cfd399c2e","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"a61a4e1a-eaea-4814-a424-e3c1ca6e3818","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"cb0d722f-fb48-45b5-a612-ff2df9b2e56e","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"50d0749d-1dde-4d8d-8963-e605f3a89b7a","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"900c820c-2909-4065-be81-72d3ca7733de","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"fac7dd69-11b1-42ee-8c1e-a41c97f4c3ee","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"9a357d48-c648-4ddb-8c79-2dc97bea6bc9","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"d5de4b91-714d-4c4c-8619-4b88fae85046","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"3741b662-b556-4859-8720-4c79fd48d48a","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"72db3e84-44c5-4d07-86b1-5f866a897e83","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"2a701ccf-5692-4ff9-9e44-62d6ec379397","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"d2087e5d-f90d-4827-a383-ff828bd65c69","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"bbf41a2c-98d3-4b54-82fb-a51c8441957e","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"477eb38f-0505-42fc-85ee-7456d81833e8","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"d9f37084-fcee-49d5-a192-8c41ee5615ed","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"067eb4be-9082-4153-8754-3bd0106a16ef","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"e943752e-d665-4133-ab1e-b6089d61b68a","tags":[{"product":null,"links":null,"id":"c3c0ef13-c7a9-4649-9fcb-23b3abec175d","name":"New","color":"Red","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]},{"id":"d573ae98-998d-4070-b089-620789e0738b","tags":[{"product":null,"links":null,"id":"2f377cfe-f512-431a-895b-f89af32041ce","name":"Upd","color":"Blue","productId":"c15646e4-63d8-4965-8d62-7549a2986e99"}]}]
        
(Showing Draft Content)

Rich Text

SpreadJS supports rich text formatting in the cells by allowing users to style the text displayed in the row header, column header, and the viewport area in a worksheet. Rich text formatting enables users to enhance the aesthetic appearance of a spreadsheet and manipulate data in an effective way.

The styling options available while using RichText in SpreadJS are as follows:

  • font: Add various font styles, font sizes, and font families to the text in a single spreadsheet cell.

  • foreColor: Add multiple colors to the text in the spreadsheet cell.

  • vertAlign: Add superscripts and subscripts to the text in a spreadsheet cell. This is highly useful in adding scientific and mathematical formulas to spreadsheets.

  • textDecoration: Add different text-decoration styling types such as underline, doubleUnderline, lineThrough, overline, etc. to the text in the spreadsheet cell.

  • listType: Add ordered and unordered list to the text in a spreadsheet cell.

Apply Formatting

After rich text format is applied to a cell, it will convert the cell value to normal. By default, when you enter textual information in a cell, the alphabets in the viewport area of the worksheet are displayed without any formatting style as shown in cell A1 below. However, when you apply rich text formatting in a cell, the alphabets are displayed as shown in cell A3 in the screenshot shared below.




Users can apply rich text formatting to the column header and row header as shown in the image below.



Apply Styling

Users can also apply superscript, subscript and text-decoration styling to the texts in the cells as shown below:

richtext-vertalign-textdecoration.png

Applying rich text formatting to cells not only facilitates users in rendering different text styles like text alignment, text in the vertical direction, word wrap, text-indent, etc. but also enables them to enhance the visual appearance of a spreadsheet. Some of the built-in features including JSON serialization and deserialization, excel I/O, shrink to fit, auto fit, etc. are also supported.



The Rich Text Data supports the following JSON Schema:

{
    "RichText": {
        "items": {
            "description": "Specifies a rich text.",
            "properties": {
                "style": {
                    "properties": {
                        "font": {
                            "type": "string"
                        },
                        "foreColor": {
                            "type": "string"
                        },
                        "textDecoration": {
                            "anyOf": [
                                {
                                    "$ref": "#/definitions/TextDecorationType"
                                },
                                {
                                    "type": "null"
                                }
                            ],
                            "default": 0
                        },
                        "vertAlign": {
                            "$ref": "#/definitions/VertAlign"
                        }
                    },
                    "type": "object"
                },
                "text": {
                    "type": "string"
                }
            },
            "type": "object"
        },
        "title": "RichText",
        "type": "array"
    },
    "SheetModel": {
        "description": "Represent a data model for worksheet.",
        "properties": {
            "dataTable": {
                "patternProperties": {
                    "[0-9]+": {
                        "patternProperties": {
                            "[0-9]+": {
                                "properties": {
                                    "value": {
                                        "properties": {
                                            "richText": {
                                                "$ref": "#/definitions/RichText"
                                            },
                                            "text": {
                                                "type": "string"
                                            }
                                        },
                                        "type": [
                                            "array",
                                            "boolean",
                                            "number",
                                            "null",
                                            "object",
                                            "string"
                                        ]
                                    }
                                },
                                "type": "object"
                            }
                        },
                        "type": "object"
                    }
                },
                "type": "object"
            }
        },
        "title": "SheetModel",
        "type": "object"
    },
    "VertAlign": {
        "description": "Specifies a subscript text or a superscript text. Normal: 0, superscript: 1, subscript: 2.",
        "enum": [
            0,
            1,
            2
        ],
        "title": "VertAlign"
    }
}

The following code sample sets the rich text with different styling options in a column header cell, a row header cell, and a cell in the viewport area of the worksheet using the setValue method.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <!--jquery refrence-->
    <script src="https://code.jquery.com/jquery-2.2.4.min.js" type="text/javascript"></script>
    <!--CSS files-->
    <link href="css/gc.spread.sheets.excel2013white.x.x.x.css" rel="stylesheet" />
    <!--Script files-->
    <script type="text/javascript" src="scripts/gc.spread.sheets.all.x.x.x.min.js"></script>
    <script>
        window.onload = function () {
            // Configure Workbook and Worksheet
            var spread = new GC.Spread.Sheets.Workbook("ss");
            var sheet = spread.getActiveSheet();
            var SpreadJS =
            {
                richText: [{
                    style: {
                        font: "bold 36px Calibri",
                        foreColor: "rgb(78,133,242)"

                    },
                    text: "S"
                },
                {
                    style: {
                        font: "bold 36px Calibri",
                        foreColor: "rgb(228,65,52)"

                    },
                    text: "p"
                },
                {
                    style: {
                        font: "bold 36px Calibri",
                        foreColor: "rgb(247,188,32)"

                    },
                    text: "r"
                },
                {
                    style: {
                        font: "bold 36px Calibri",
                        foreColor: "rgb(78,133,242)"

                    },
                    text: "e"
                },
                {
                    style: {
                        font: "bold 36px Calibri",
                        foreColor: "rgb(65,168,87)"

                    },
                    text: "a"
                },
                {
                    style: {
                        font: "bold 36px Calibri",
                        foreColor: "rgb(228,65,54)"

                    },
                    text: "d"
                }
                ]
            };
            var sJS =
            {
                richText: [
                    {
                        style: {
                            font: "bold 24px Calibri",
                            foreColor: "rgb(78,133,242)"
                        },
                        text: "S"
                    },
                    {
                        style: {
                            font: "bold 24px Calibri",
                            foreColor: "rgb(65,168,87)"
                        },
                        text: "p"
                    },
                    {
                        style: {
                            font: "bold 24px Calibri",
                            foreColor: "rgb(247,188,32)"
                        },
                        text: "r"
                    },
                    {
                        style: {
                            font: "bold 24px Calibri",
                            foreColor: "rgb(78,133,242)"
                        },
                        text: "e"
                    },
                    {
                        style: {
                            font: "bold 24px Calibri",
                            foreColor: "rgb(65,168,87)"
                        },
                        text: "a"
                    },
                    {
                        style: {
                            font: "bold 24px Calibri",
                            foreColor: "rgb(228,65,54)"
                        },
                        text: "d"
                    }
                ]
            };

            var lawOfUniversalGravitation = {
                richText: [
                    {
                        style: {
                            font: "normal 24px Calibri"
                        },
                        text: "F = (G * M"
                    },
                    {
                        style: {
                            font: "normal 24px Calibri",
                            vertAlign: 2
                        },
                        text: "1"
                    },
                    {
                        style: {
                            font: "normal 24px Calibri"
                        },
                        text: " * M"
                    },
                    {
                        style: {
                            font: "normal 24px Calibri",
                            vertAlign: 2
                        },
                        text: "2"
                    },
                    {
                        style: {
                            font: "normal 24px Calibri"
                        },
                        text: ") / R"
                    },
                    {
                        style: {
                            font: "normal 24px Calibri",
                            vertAlign: 1
                        },
                        text: "2"
                    }
                ]
            };

            // Apply rich text in a cell in the viewport
            sheet.setValue(2, 0, SpreadJS, GC.Spread.Sheets.SheetArea.viewport);
            // Apply rich text to the column header cell
            sheet.setValue(0, 4, { richText: [{ style: { font: 'bold 36px Arial ', foreColor: 'blue' }, text: 'Spread' }] }, GC.Spread.Sheets.SheetArea.colHeader);
            sheet.setValue(0, 1, SpreadJS, GC.Spread.Sheets.SheetArea.colHeader);

            // Apply rich text to a cell in the row header
            sheet.setValue(2, 0, sJS, GC.Spread.Sheets.SheetArea.rowHeader);
            sheet.setValue(0, 1, 'Law of universal gravitation:', 3);
            sheet.setValue(1, 1, lawOfUniversalGravitation, 3);
            sheet.setValue(4, 4, { richText: [{ style: { font: 'bold 36px Arial ', foreColor: 'purple', textDecoration: '1' }, text: 'Spread' }] }, GC.Spread.Sheets.SheetArea.viewport);
        }
    </script>
</head>
<body>
    <div id="ss" style="width:100%; height:700px;border: 1px solid gray;"></div>
</body>
</html>

Note: While working with rich text in a cell, the following points should be taken care of:

  • SpreadJS does not support rich text formatting in the editing mode.

  • Rich text format cannot be applied to checkbox celltype and hyperlink celltype

  • The line height of the rich text will be rendered on the basis of the largest font size of the line.

  • When the rich text is formatted in vertical direction, text decoration will have no effect. Also, using superscript and subscript when the rich text is displayed in the vertical direction will reduce the font size.

Create Bullet List

SpreadJS allows you to create unordered (bulleted) and ordered (numbered) lists in rich text formatting.

In the rich text, the list items are represented by the following attributes:

  • type: Indicates the list style of the list item.

  • level: Indicates the indent level of the list item ((level + 1) * 4 space char “ “).

  • richText: Indicates the textual content of the list item.

Note:

  • The nested lists can be simulated using the level attribute.

  • Lists, in rich text formatting, only work if the wordWrap property of the cell's text style is set to true.

Use GC.Spread.Sheets.ListType enumeration to create both numbered and bulleted lists.

The following code sample creates a multilevel list that contains both bullet points and numberings.

   let sheet = spread.getActiveSheet();
   let style = new GC.Spread.Sheets.Style();
   style.wordWrap = true;
   sheet.setStyle(0, 0, style);
   let richText = [{
       type: GC.Spread.Sheets.ListType.disc, // represents the rich text item is a list item, and its symbol is disc
       level: 0, // represent the level of list item
       richText: [{ // represent the text content of current list item, in this case it represent the "disc1"
           text: "disc"
       }, {
           text: "1",
           style: {
               font: "24px Arial",
               foreColor: "red"
           }
       }]
   }, {
       type: GC.Spread.Sheets.ListType.lowerAlpha, // represents the rich text item is a list item, and its symbol is lowerAlpha
       level: 1, // represent the level of list item
       richText: [{  // represent the text content of current list item, in this case it represent the "lowerAlpha1"
           text: "lowerAlpha1"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.lowerRoman, // represents the rich text item is a list item, and its symbol is lowerRoman
       level: 2, // represent the level of list item
       richText: [{  // represent the text content of current list item, in this case it represent the "lowerRoman1"
           text: "lowerRoman1"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.lowerRoman, // represents the rich text item is a list item, and its symbol is lowerRoman
       level: 2, // represent the level of list item
       richText: [{  // represent the text content of current list item, in this case it represent the "lowerRoman2"
           text: "lowerRoman2"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.lowerAlpha, // represents the rich text item is a list item, and its symbol is lowerRoman
       level: 1, // represent the level of list item
       richText: [{  // represent the text content of current list item, in this case it represent the "lowerAlpha2"
           text: "lowerAlpha2"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.disc, // represents the rich text item is a list item, and its symbol is disc
       level: 0, // represent the level of list item
       richText: [{ // represent the text content of current list item, in this case it represent the "disc2"
           text: "disc2"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.circle, // represents the rich text item is a list item, and its symbol is circle
       level: 1, // represent the level of list item
       richText: [{ // represent the text content of current list item, in this case it represent the "circle1"
           text: "circle1"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.circle, // represents the rich text item is a list item, and its symbol is circle
       level: 1, // represent the level of list item
       richText: [{ // represent the text content of current list item, in this case it represent the "disc1"
           text: "circle2"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.square, // represents the rich text item is a list item, and its symbol is square
       level: 2, // represent the level of list item
       richText: [{ // represent the text content of current list item, in this case it represent the "square1"
           text: "square1"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.square, // represents the rich text item is a list item, and its symbol is square
       level: 2, // represent the level of list item
       richText: [{ // represent the text content of current list item, in this case it represent the "square2"
           text: "square2"
       }]
   }, {
       type: GC.Spread.Sheets.ListType.disc, // represents the rich text item is a list item, and its symbol is disc
       level: 0, // represent the level of list item
       richText: [{ // represent the text content of current list item, in this case it represent the "disc3"
           text: "disc3"
       }]
   }];
   sheet.setValue(0, 0, {
       richText: richText
   });
   sheet.setColumnWidth(0, 200);
   sheet.setRowHeight(0, 250);

The below output will be generated.

RichTextLists

Limitations

  • List items do not support line breaks.

  • Lists are always left-aligned.

  • If you set the text alignment to center or right, list indentation may not appear correctly.

  • When exporting to Excel, list items will be converted to normal rich text which may look different from SpreadJS.

  • A list item cannot contain another list.

Using Designer

You can also apply rich text formatting using the SpreadJS Designer Component by following the steps given below:

  1. Right-click on the active cell to open the context menu.


    RichTextOption


  2. Select the Rich Text... option.

    The Rich Text Dialog appears.


    RichTextDialog


  3. Apply rich text formatting as required.

Shortcut Keys

You can use the following shortcut keys while formatting rich text using Rich Text Dialog.

Shortcut Key

Action

Ctrl/Cmd+Z

Undo

Ctrl/Cmd+Y or Ctrl/Cmd+Shift+Z

Redo

Ctrl/Cmd+I

Italic

Ctrl/Cmd+B

Bold

Ctrl/Cmd+U

Underline

Ctrl/Cmd+K

Strike out

Ctrl/Cmd+↑

Superscript

Ctrl/Cmd+↓

Subscript

Ctrl/Cmd+[

Outdent

Ctrl/Cmd+]

Indent