About custom function return new line text

hi,i create my own plugin,and it`s amost done.

1、i use api create my own function

Asc.plugin.callCommand(function () {
                Api.AddCustomFunctionLibrary("DocumentTest", function () {
                    /**
                     * Function that returns the argument
                     * @customfunction
                     * @param {any} data Any data.
                     * @returns {any} second Second argument.
                     */
                    Api.AddCustomFunction(function DOCUMENT_ATTACHMENT(data) {
                        return data;
                    });
                });
            })

yes, it`s working,

now i use Api.PasteHtml and Api.PasteText add DOCUMENT_ATTACHMENT function to cell like:

Asc.plugin.executeMethod('PasteHtml', ['=DOCUMENT_ATTACHMENT("A\nB")'])
Asc.plugin.executeMethod('PasteText', ['=DOCUMENT_ATTACHMENT("A\nB")'])

as you can see,my data is \n,mean i want this function return new line text,
but use PasteHtml,i get A B on cell
use PasteText i get =DOCUMENT_ATTACHMENT(“A on one cell,and next cell well insert B”)

please,how make it`s working

ok,i find solution for my self,this is my code:

Asc.plugin.callCommand(function () {
            Api.AddCustomFunctionLibrary("DocumentTest", function () {
                /**
                 * Function that returns the argument
                 * @customfunction
                 * @param {any} data Any data.
                 * @returns {any} second Second argument.
                 */
                Api.AddCustomFunction(function DOCUMENT_ATTACHMENT(data) {
                    const str = data.split('|')
                    return str.join("\n");
                });
            });
        })

then:

Asc.plugin.executeMethod('PasteText', ['=DOCUMENT_ATTACHMENT("' + data.join("|") + '")'], function () {
                    Asc.plugin.callCommand(function () {
                        const selection = Api.GetSelection()
                        selection.SetFontColor(Api.CreateColorFromRGB(255, 0, 0))
                        selection.SetUnderline('single')
                        selection.SetWrap(true)
                    })
                })
1 Like