Google Apps Script - Docs. Converting table cells with formatting to HTML












0














I'm creating a Google Script add-on in Docs (not Sheets) which allows people to input content into predefined table cells, which I then later on need to parse and turn into HTML.



I'm almost there, thanks to this answer: https://stackoverflow.com/a/47313357/2586977 and the GoogleDoc2HTML script it mentions. I can get out everything I need, except for the simple formatting that some content will require – bold, italics and links.



The method described in the linked article uses getTextAttributeIndices() to work out where these attribute changes are located, then splices the corresponding HTML tags into the output to replicate the formatting. It's kind of long-winded, but it works!



The problem I have is that getTextAttributeIndices() will only work on [Text][2] elements, and I'm trying to get the indices of content in a [TableCell][3] element.



The console gives me the error message:




TypeError: Cannot find function getTextAttributeIndices in object TableCell.




If do myTableCell.getText() first, I lose all the formatting.










share|improve this question






















  • Check the reference documentation. There are probably methods on the TableCell instance that allow you to retrieve the cell's attributes.
    – Dimu Designs
    Nov 13 at 0:29












  • There is certainly TableCell.getAttributes() but the result from that only apply to the whole cell, and there isn't a corresponding method to get the attribute indices. In my case, the content in the cell won't be all bold, or all italic, or all one link, but a block of text potentially containing all of those mixed together.
    – axemonkey
    Nov 13 at 10:20
















0














I'm creating a Google Script add-on in Docs (not Sheets) which allows people to input content into predefined table cells, which I then later on need to parse and turn into HTML.



I'm almost there, thanks to this answer: https://stackoverflow.com/a/47313357/2586977 and the GoogleDoc2HTML script it mentions. I can get out everything I need, except for the simple formatting that some content will require – bold, italics and links.



The method described in the linked article uses getTextAttributeIndices() to work out where these attribute changes are located, then splices the corresponding HTML tags into the output to replicate the formatting. It's kind of long-winded, but it works!



The problem I have is that getTextAttributeIndices() will only work on [Text][2] elements, and I'm trying to get the indices of content in a [TableCell][3] element.



The console gives me the error message:




TypeError: Cannot find function getTextAttributeIndices in object TableCell.




If do myTableCell.getText() first, I lose all the formatting.










share|improve this question






















  • Check the reference documentation. There are probably methods on the TableCell instance that allow you to retrieve the cell's attributes.
    – Dimu Designs
    Nov 13 at 0:29












  • There is certainly TableCell.getAttributes() but the result from that only apply to the whole cell, and there isn't a corresponding method to get the attribute indices. In my case, the content in the cell won't be all bold, or all italic, or all one link, but a block of text potentially containing all of those mixed together.
    – axemonkey
    Nov 13 at 10:20














0












0








0







I'm creating a Google Script add-on in Docs (not Sheets) which allows people to input content into predefined table cells, which I then later on need to parse and turn into HTML.



I'm almost there, thanks to this answer: https://stackoverflow.com/a/47313357/2586977 and the GoogleDoc2HTML script it mentions. I can get out everything I need, except for the simple formatting that some content will require – bold, italics and links.



The method described in the linked article uses getTextAttributeIndices() to work out where these attribute changes are located, then splices the corresponding HTML tags into the output to replicate the formatting. It's kind of long-winded, but it works!



The problem I have is that getTextAttributeIndices() will only work on [Text][2] elements, and I'm trying to get the indices of content in a [TableCell][3] element.



The console gives me the error message:




TypeError: Cannot find function getTextAttributeIndices in object TableCell.




If do myTableCell.getText() first, I lose all the formatting.










share|improve this question













I'm creating a Google Script add-on in Docs (not Sheets) which allows people to input content into predefined table cells, which I then later on need to parse and turn into HTML.



I'm almost there, thanks to this answer: https://stackoverflow.com/a/47313357/2586977 and the GoogleDoc2HTML script it mentions. I can get out everything I need, except for the simple formatting that some content will require – bold, italics and links.



The method described in the linked article uses getTextAttributeIndices() to work out where these attribute changes are located, then splices the corresponding HTML tags into the output to replicate the formatting. It's kind of long-winded, but it works!



The problem I have is that getTextAttributeIndices() will only work on [Text][2] elements, and I'm trying to get the indices of content in a [TableCell][3] element.



The console gives me the error message:




TypeError: Cannot find function getTextAttributeIndices in object TableCell.




If do myTableCell.getText() first, I lose all the formatting.







google-apps-script






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 16:38









axemonkey

132




132












  • Check the reference documentation. There are probably methods on the TableCell instance that allow you to retrieve the cell's attributes.
    – Dimu Designs
    Nov 13 at 0:29












  • There is certainly TableCell.getAttributes() but the result from that only apply to the whole cell, and there isn't a corresponding method to get the attribute indices. In my case, the content in the cell won't be all bold, or all italic, or all one link, but a block of text potentially containing all of those mixed together.
    – axemonkey
    Nov 13 at 10:20


















  • Check the reference documentation. There are probably methods on the TableCell instance that allow you to retrieve the cell's attributes.
    – Dimu Designs
    Nov 13 at 0:29












  • There is certainly TableCell.getAttributes() but the result from that only apply to the whole cell, and there isn't a corresponding method to get the attribute indices. In my case, the content in the cell won't be all bold, or all italic, or all one link, but a block of text potentially containing all of those mixed together.
    – axemonkey
    Nov 13 at 10:20
















Check the reference documentation. There are probably methods on the TableCell instance that allow you to retrieve the cell's attributes.
– Dimu Designs
Nov 13 at 0:29






Check the reference documentation. There are probably methods on the TableCell instance that allow you to retrieve the cell's attributes.
– Dimu Designs
Nov 13 at 0:29














There is certainly TableCell.getAttributes() but the result from that only apply to the whole cell, and there isn't a corresponding method to get the attribute indices. In my case, the content in the cell won't be all bold, or all italic, or all one link, but a block of text potentially containing all of those mixed together.
– axemonkey
Nov 13 at 10:20




There is certainly TableCell.getAttributes() but the result from that only apply to the whole cell, and there isn't a corresponding method to get the attribute indices. In my case, the content in the cell won't be all bold, or all italic, or all one link, but a block of text potentially containing all of those mixed together.
– axemonkey
Nov 13 at 10:20












2 Answers
2






active

oldest

votes


















0














@axemonkey Your solution will work but it's brittle since the documentation does not guarantee that the paragraph element will always be a child element at index 0. Rummaged through the documentation and found this method:



TabelCell::findElement(elementType)



You can use that method to fetch child elements of a given type. It returns a RangeElement which wraps the child element so you have to call the following method:



RangeElement::getElement()





So using the above, a more reliable way to get the paragraph element is this:



var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();


To get the Text element in the paragraph you can use findElement() on the paragraph instance as well:



var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();


So bringing it all together you'd get:



var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();
var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();

var indices = text.getAttributeIndices();


There's more code to write, but you'll have more readable code and its less likely break since it does not rely on child indices.





PS: When you invoke the getElement() method on a RangeElement its returns the element, but as far as the Apps Script GUI is concerned you only get auto-completion for properties associated with the Element interface. If you want to get auto-completion for the properties and methods specific to a given element type, then leverage one of the many type casting methods defined in the Element interface. These methods are always prefixed with as. So to get code-completion for the text element you could write code like this:



var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement().asText();





share|improve this answer























  • Fantastic, thank you! I had a feeling my solution could be improved, but I just couldn't see the wood for the trees any more. Cheers!
    – axemonkey
    Nov 13 at 14:43










  • @axemonkey Here's a trick I use when I get to that point...just skim the official reference documentation - don't look for anything too specific - just peruse Class and Functions descriptions that pertain to a given built-in service (Document, Spreadsheet, Form etc.) and see what jumps out at you...You'd be surprised at how effective this is.
    – Dimu Designs
    Nov 13 at 15:02












  • One thing I found when I implemented this, is that the findElement() calls don't find PARAGRAPH or TEXT – I needed to use the full DocumentApp.ElementType.PARAGRAPH and DocumentApp.ElementType.TEXT inside the parentheses. But it's working now, and more readable and sturdy. Thanks again!
    – axemonkey
    Nov 13 at 15:26












  • You're correct. Updated my response accordingly...and added a little extra in the process.
    – Dimu Designs
    Nov 13 at 15:29










  • Awesomeness. Thanks for the help! 😄
    – axemonkey
    Nov 13 at 15:46



















1














I finally cracked it, so I'm sharing the answer in case anyone else runs into this.



getTextAttributeIndices() only works on Text elements, not TableCell elements.



BUT it turns out that when you create a TableCell element and enter content into it, it implicitly creates a Paragraph element and that contains a Text element.



Therefore this does NOT work:




myTableCell.getTextAttributeIndices()




but this DOES work:




myTableCell.getChild(0).getChild(0).getTextAttributeIndices()







share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266481%2fgoogle-apps-script-docs-converting-table-cells-with-formatting-to-html%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    @axemonkey Your solution will work but it's brittle since the documentation does not guarantee that the paragraph element will always be a child element at index 0. Rummaged through the documentation and found this method:



    TabelCell::findElement(elementType)



    You can use that method to fetch child elements of a given type. It returns a RangeElement which wraps the child element so you have to call the following method:



    RangeElement::getElement()





    So using the above, a more reliable way to get the paragraph element is this:



    var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();


    To get the Text element in the paragraph you can use findElement() on the paragraph instance as well:



    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();


    So bringing it all together you'd get:



    var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();
    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();

    var indices = text.getAttributeIndices();


    There's more code to write, but you'll have more readable code and its less likely break since it does not rely on child indices.





    PS: When you invoke the getElement() method on a RangeElement its returns the element, but as far as the Apps Script GUI is concerned you only get auto-completion for properties associated with the Element interface. If you want to get auto-completion for the properties and methods specific to a given element type, then leverage one of the many type casting methods defined in the Element interface. These methods are always prefixed with as. So to get code-completion for the text element you could write code like this:



    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement().asText();





    share|improve this answer























    • Fantastic, thank you! I had a feeling my solution could be improved, but I just couldn't see the wood for the trees any more. Cheers!
      – axemonkey
      Nov 13 at 14:43










    • @axemonkey Here's a trick I use when I get to that point...just skim the official reference documentation - don't look for anything too specific - just peruse Class and Functions descriptions that pertain to a given built-in service (Document, Spreadsheet, Form etc.) and see what jumps out at you...You'd be surprised at how effective this is.
      – Dimu Designs
      Nov 13 at 15:02












    • One thing I found when I implemented this, is that the findElement() calls don't find PARAGRAPH or TEXT – I needed to use the full DocumentApp.ElementType.PARAGRAPH and DocumentApp.ElementType.TEXT inside the parentheses. But it's working now, and more readable and sturdy. Thanks again!
      – axemonkey
      Nov 13 at 15:26












    • You're correct. Updated my response accordingly...and added a little extra in the process.
      – Dimu Designs
      Nov 13 at 15:29










    • Awesomeness. Thanks for the help! 😄
      – axemonkey
      Nov 13 at 15:46
















    0














    @axemonkey Your solution will work but it's brittle since the documentation does not guarantee that the paragraph element will always be a child element at index 0. Rummaged through the documentation and found this method:



    TabelCell::findElement(elementType)



    You can use that method to fetch child elements of a given type. It returns a RangeElement which wraps the child element so you have to call the following method:



    RangeElement::getElement()





    So using the above, a more reliable way to get the paragraph element is this:



    var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();


    To get the Text element in the paragraph you can use findElement() on the paragraph instance as well:



    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();


    So bringing it all together you'd get:



    var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();
    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();

    var indices = text.getAttributeIndices();


    There's more code to write, but you'll have more readable code and its less likely break since it does not rely on child indices.





    PS: When you invoke the getElement() method on a RangeElement its returns the element, but as far as the Apps Script GUI is concerned you only get auto-completion for properties associated with the Element interface. If you want to get auto-completion for the properties and methods specific to a given element type, then leverage one of the many type casting methods defined in the Element interface. These methods are always prefixed with as. So to get code-completion for the text element you could write code like this:



    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement().asText();





    share|improve this answer























    • Fantastic, thank you! I had a feeling my solution could be improved, but I just couldn't see the wood for the trees any more. Cheers!
      – axemonkey
      Nov 13 at 14:43










    • @axemonkey Here's a trick I use when I get to that point...just skim the official reference documentation - don't look for anything too specific - just peruse Class and Functions descriptions that pertain to a given built-in service (Document, Spreadsheet, Form etc.) and see what jumps out at you...You'd be surprised at how effective this is.
      – Dimu Designs
      Nov 13 at 15:02












    • One thing I found when I implemented this, is that the findElement() calls don't find PARAGRAPH or TEXT – I needed to use the full DocumentApp.ElementType.PARAGRAPH and DocumentApp.ElementType.TEXT inside the parentheses. But it's working now, and more readable and sturdy. Thanks again!
      – axemonkey
      Nov 13 at 15:26












    • You're correct. Updated my response accordingly...and added a little extra in the process.
      – Dimu Designs
      Nov 13 at 15:29










    • Awesomeness. Thanks for the help! 😄
      – axemonkey
      Nov 13 at 15:46














    0












    0








    0






    @axemonkey Your solution will work but it's brittle since the documentation does not guarantee that the paragraph element will always be a child element at index 0. Rummaged through the documentation and found this method:



    TabelCell::findElement(elementType)



    You can use that method to fetch child elements of a given type. It returns a RangeElement which wraps the child element so you have to call the following method:



    RangeElement::getElement()





    So using the above, a more reliable way to get the paragraph element is this:



    var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();


    To get the Text element in the paragraph you can use findElement() on the paragraph instance as well:



    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();


    So bringing it all together you'd get:



    var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();
    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();

    var indices = text.getAttributeIndices();


    There's more code to write, but you'll have more readable code and its less likely break since it does not rely on child indices.





    PS: When you invoke the getElement() method on a RangeElement its returns the element, but as far as the Apps Script GUI is concerned you only get auto-completion for properties associated with the Element interface. If you want to get auto-completion for the properties and methods specific to a given element type, then leverage one of the many type casting methods defined in the Element interface. These methods are always prefixed with as. So to get code-completion for the text element you could write code like this:



    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement().asText();





    share|improve this answer














    @axemonkey Your solution will work but it's brittle since the documentation does not guarantee that the paragraph element will always be a child element at index 0. Rummaged through the documentation and found this method:



    TabelCell::findElement(elementType)



    You can use that method to fetch child elements of a given type. It returns a RangeElement which wraps the child element so you have to call the following method:



    RangeElement::getElement()





    So using the above, a more reliable way to get the paragraph element is this:



    var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();


    To get the Text element in the paragraph you can use findElement() on the paragraph instance as well:



    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();


    So bringing it all together you'd get:



    var paragraph = tableCell.findElement(DocumentApp.ElementType.PARAGRAPH).getElement();
    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement();

    var indices = text.getAttributeIndices();


    There's more code to write, but you'll have more readable code and its less likely break since it does not rely on child indices.





    PS: When you invoke the getElement() method on a RangeElement its returns the element, but as far as the Apps Script GUI is concerned you only get auto-completion for properties associated with the Element interface. If you want to get auto-completion for the properties and methods specific to a given element type, then leverage one of the many type casting methods defined in the Element interface. These methods are always prefixed with as. So to get code-completion for the text element you could write code like this:



    var text = paragraph.findElement(DocumentApp.ElementType.TEXT).getElement().asText();






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 13 at 15:33

























    answered Nov 13 at 13:57









    Dimu Designs

    2,5732411




    2,5732411












    • Fantastic, thank you! I had a feeling my solution could be improved, but I just couldn't see the wood for the trees any more. Cheers!
      – axemonkey
      Nov 13 at 14:43










    • @axemonkey Here's a trick I use when I get to that point...just skim the official reference documentation - don't look for anything too specific - just peruse Class and Functions descriptions that pertain to a given built-in service (Document, Spreadsheet, Form etc.) and see what jumps out at you...You'd be surprised at how effective this is.
      – Dimu Designs
      Nov 13 at 15:02












    • One thing I found when I implemented this, is that the findElement() calls don't find PARAGRAPH or TEXT – I needed to use the full DocumentApp.ElementType.PARAGRAPH and DocumentApp.ElementType.TEXT inside the parentheses. But it's working now, and more readable and sturdy. Thanks again!
      – axemonkey
      Nov 13 at 15:26












    • You're correct. Updated my response accordingly...and added a little extra in the process.
      – Dimu Designs
      Nov 13 at 15:29










    • Awesomeness. Thanks for the help! 😄
      – axemonkey
      Nov 13 at 15:46


















    • Fantastic, thank you! I had a feeling my solution could be improved, but I just couldn't see the wood for the trees any more. Cheers!
      – axemonkey
      Nov 13 at 14:43










    • @axemonkey Here's a trick I use when I get to that point...just skim the official reference documentation - don't look for anything too specific - just peruse Class and Functions descriptions that pertain to a given built-in service (Document, Spreadsheet, Form etc.) and see what jumps out at you...You'd be surprised at how effective this is.
      – Dimu Designs
      Nov 13 at 15:02












    • One thing I found when I implemented this, is that the findElement() calls don't find PARAGRAPH or TEXT – I needed to use the full DocumentApp.ElementType.PARAGRAPH and DocumentApp.ElementType.TEXT inside the parentheses. But it's working now, and more readable and sturdy. Thanks again!
      – axemonkey
      Nov 13 at 15:26












    • You're correct. Updated my response accordingly...and added a little extra in the process.
      – Dimu Designs
      Nov 13 at 15:29










    • Awesomeness. Thanks for the help! 😄
      – axemonkey
      Nov 13 at 15:46
















    Fantastic, thank you! I had a feeling my solution could be improved, but I just couldn't see the wood for the trees any more. Cheers!
    – axemonkey
    Nov 13 at 14:43




    Fantastic, thank you! I had a feeling my solution could be improved, but I just couldn't see the wood for the trees any more. Cheers!
    – axemonkey
    Nov 13 at 14:43












    @axemonkey Here's a trick I use when I get to that point...just skim the official reference documentation - don't look for anything too specific - just peruse Class and Functions descriptions that pertain to a given built-in service (Document, Spreadsheet, Form etc.) and see what jumps out at you...You'd be surprised at how effective this is.
    – Dimu Designs
    Nov 13 at 15:02






    @axemonkey Here's a trick I use when I get to that point...just skim the official reference documentation - don't look for anything too specific - just peruse Class and Functions descriptions that pertain to a given built-in service (Document, Spreadsheet, Form etc.) and see what jumps out at you...You'd be surprised at how effective this is.
    – Dimu Designs
    Nov 13 at 15:02














    One thing I found when I implemented this, is that the findElement() calls don't find PARAGRAPH or TEXT – I needed to use the full DocumentApp.ElementType.PARAGRAPH and DocumentApp.ElementType.TEXT inside the parentheses. But it's working now, and more readable and sturdy. Thanks again!
    – axemonkey
    Nov 13 at 15:26






    One thing I found when I implemented this, is that the findElement() calls don't find PARAGRAPH or TEXT – I needed to use the full DocumentApp.ElementType.PARAGRAPH and DocumentApp.ElementType.TEXT inside the parentheses. But it's working now, and more readable and sturdy. Thanks again!
    – axemonkey
    Nov 13 at 15:26














    You're correct. Updated my response accordingly...and added a little extra in the process.
    – Dimu Designs
    Nov 13 at 15:29




    You're correct. Updated my response accordingly...and added a little extra in the process.
    – Dimu Designs
    Nov 13 at 15:29












    Awesomeness. Thanks for the help! 😄
    – axemonkey
    Nov 13 at 15:46




    Awesomeness. Thanks for the help! 😄
    – axemonkey
    Nov 13 at 15:46













    1














    I finally cracked it, so I'm sharing the answer in case anyone else runs into this.



    getTextAttributeIndices() only works on Text elements, not TableCell elements.



    BUT it turns out that when you create a TableCell element and enter content into it, it implicitly creates a Paragraph element and that contains a Text element.



    Therefore this does NOT work:




    myTableCell.getTextAttributeIndices()




    but this DOES work:




    myTableCell.getChild(0).getChild(0).getTextAttributeIndices()







    share|improve this answer


























      1














      I finally cracked it, so I'm sharing the answer in case anyone else runs into this.



      getTextAttributeIndices() only works on Text elements, not TableCell elements.



      BUT it turns out that when you create a TableCell element and enter content into it, it implicitly creates a Paragraph element and that contains a Text element.



      Therefore this does NOT work:




      myTableCell.getTextAttributeIndices()




      but this DOES work:




      myTableCell.getChild(0).getChild(0).getTextAttributeIndices()







      share|improve this answer
























        1












        1








        1






        I finally cracked it, so I'm sharing the answer in case anyone else runs into this.



        getTextAttributeIndices() only works on Text elements, not TableCell elements.



        BUT it turns out that when you create a TableCell element and enter content into it, it implicitly creates a Paragraph element and that contains a Text element.



        Therefore this does NOT work:




        myTableCell.getTextAttributeIndices()




        but this DOES work:




        myTableCell.getChild(0).getChild(0).getTextAttributeIndices()







        share|improve this answer












        I finally cracked it, so I'm sharing the answer in case anyone else runs into this.



        getTextAttributeIndices() only works on Text elements, not TableCell elements.



        BUT it turns out that when you create a TableCell element and enter content into it, it implicitly creates a Paragraph element and that contains a Text element.



        Therefore this does NOT work:




        myTableCell.getTextAttributeIndices()




        but this DOES work:




        myTableCell.getChild(0).getChild(0).getTextAttributeIndices()








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 11:01









        axemonkey

        132




        132






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266481%2fgoogle-apps-script-docs-converting-table-cells-with-formatting-to-html%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python