Unable to paste from spreadsheet

Better workaround:

Diff:
--- a/src/XF/Html/Renderer/BbCode.php
+++ b/src/XF/Html/Renderer/BbCode.php
@@ -491,6 +491,12 @@ class BbCode
      */
     public function renderCss(Tag $tag, $stringOutput)
     {
+        // Workaround: https://xenforo.com/community/threads/unable-to-paste-from-spreadsheet.223298/
+        if (preg_match('/^\[(th|td)/i', $stringOutput))
+        {
+            return $stringOutput;
+        }
+
         $css = $tag->attribute('style');
         if ($css)
         {
 
It looks like this bug still exists, and it’s surprising how quiet this thread has been. Is it being discussed somewhere else?

Thanks for the workaround, @Steffen. Although it removes all cell customizations, it does the job. Better to lose customization instead of garbage entries.
Perhaps the following could be an alternative to using preg_match? (Also, I think only td is affected, but it should be fine to include tr as well.)

PHP:
if (in_array($tag->tagName(), ['td', 'tr']))
 
Moved one of my sites to XF 2.3 and already have users complaining about this. The nature of the site is such that there are a LOT of copy/paste from spreadsheets so this is a very unexpected, and unwelcomed regression from XF 2.2.

Here's another instance to look into:

When I copy the table into the editor, it looks fine:

Screenshot 2025-02-13 092119.webp

However, when I hit preview, it changes the bottom line...

Screenshot 2025-02-13 092144.webp

When I submitted the post, it (obviously) took the preview version of the table, which is 💩. You can see the result, after the thread was posted, here: https://xenforo.com/community/threads/table-copy-paste-test.229188/
 
This previously worked before upgrading to 2.3
We have the same problem too, in 2.3 and 2.4.
Give a try here instead:

Valori nutrizionali - Composizione Chimica

Parte edibile100%-
Acqua42 g-
Carboidrati disponibili0-
Carboidrati complessi0-
Zuccheri solubili0-
Proteine35,60 g-
Grassi (Lipidi)14,20 g-
[TR]
[td]Composizione chimica[/td][td]valore per 100g[/td][td]RDA (%)[/td]
[/TR]
 
I'm also facing this issue... I have pasted in from Excel and Sheets - errors as shown throughout this test thread.

But removing formatting get's closer but still not usable.
 
It looks like this bug still exists, and it’s surprising how quiet this thread has been. Is it being discussed somewhere else?

Thanks for the workaround, @Steffen. Although it removes all cell customizations, it does the job. Better to lose customization instead of garbage entries.
Perhaps the following could be an alternative to using preg_match? (Also, I think only td is affected, but it should be fine to include tr as well.)

PHP:
if (in_array($tag->tagName(), ['td', 'tr']))
We had to fix this on our own site. The 'th' tag is also affected and should be added to this list.
 
Steffen workaround did not worked for me, XF2.3
Code:
ParseError: syntax error, unexpected token "if" in src/XF/Html/Renderer/BbCode.php at line 495

    Composer\Autoload\{closure}() in src/vendor/composer/ClassLoader.php at line 427
    Composer\Autoload\ClassLoader->loadClass() in src/XF/ControllerPlugin/EditorPlugin.php at line 42
    XF\ControllerPlugin\EditorPlugin->convertToBbCode() in src/XF/ControllerPlugin/EditorPlugin.php at line 21
    XF\ControllerPlugin\EditorPlugin->fromInput() in src/XF/Pub/Controller/PostController.php at line 71
    XF\Pub\Controller\PostController->setupPostEdit() in src/XF/Pub/Controller/PostController.php at line 154
    XF\Pub\Controller\PostController->actionEdit() in src/XF/Mvc/Dispatcher.php at line 362
    XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
    XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
    XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
    XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2824
    XF\App->run() in src/XF.php at line 806
    XF::runApp() in index.php at line 23

From my Bbcode.php:
Code:
    /**
     * Renders the CSS for a given tag.
     *
     * @param Tag $tag
     * @param string $stringOutput
     *
     * @return string BB code output
     */
    public function renderCss(Tag $tag, $stringOutput)
    {
+        // Workaround: https://xenforo.com/community/threads/unable-to-paste-from-spreadsheet.223298/
+        if (preg_match('/^\[(TD|TR)/i', $stringOutput))
+        {
+            return $stringOutput;
+        }
        $css = $tag->attribute('style');
        if ($css)
        {
            foreach ($css AS $cssRule => $cssValue)
 
Steffen workaround did not worked for me, XF2.3
Code:
ParseError: syntax error, unexpected token "if" in src/XF/Html/Renderer/BbCode.php at line 495

    Composer\Autoload\{closure}() in src/vendor/composer/ClassLoader.php at line 427
    Composer\Autoload\ClassLoader->loadClass() in src/XF/ControllerPlugin/EditorPlugin.php at line 42
    XF\ControllerPlugin\EditorPlugin->convertToBbCode() in src/XF/ControllerPlugin/EditorPlugin.php at line 21
    XF\ControllerPlugin\EditorPlugin->fromInput() in src/XF/Pub/Controller/PostController.php at line 71
    XF\Pub\Controller\PostController->setupPostEdit() in src/XF/Pub/Controller/PostController.php at line 154
    XF\Pub\Controller\PostController->actionEdit() in src/XF/Mvc/Dispatcher.php at line 362
    XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
    XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
    XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
    XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2824
    XF\App->run() in src/XF.php at line 806
    XF::runApp() in index.php at line 23

From my Bbcode.php:
Code:
    /**
     * Renders the CSS for a given tag.
     *
     * @param Tag $tag
     * @param string $stringOutput
     *
     * @return string BB code output
     */
    public function renderCss(Tag $tag, $stringOutput)
    {
+        // Workaround: https://xenforo.com/community/threads/unable-to-paste-from-spreadsheet.223298/
+        if (preg_match('/^\[(TD|TR)/i', $stringOutput))
+        {
+            return $stringOutput;
+        }
        $css = $tag->attribute('style');
        if ($css)
        {
            foreach ($css AS $cssRule => $cssValue)

Remove the "+" symbol from the front of the lines.
 
unfortunatey is still not doing anything after correcting the file:

PHP:
    /**
     * Renders the CSS for a given tag.
     *
     * @param Tag $tag
     * @param string $stringOutput
     *
     * @return string BB code output
     */
    public function renderCss(Tag $tag, $stringOutput)
    {
// Workaround: https://xenforo.com/community/threads/unable-to-paste-from-spreadsheet.223298/
if (preg_match('/^\[(TD|TR|TABLE)/i', $stringOutput))
{
       return $stringOutput;
}
        $css = $tag->attribute('style');
        if ($css)
 

Attachments

  • tabele.webp
    tabele.webp
    22.8 KB · Views: 8
PHP:
    /**
     * Renders the CSS for a given tag.
     *
     * @param Tag $tag
     * @param string $stringOutput
     *
     * @return string BB code output
     */
    public function renderCss(Tag $tag, $stringOutput)
    {

        // Workaround: https://xenforo.com/community/threads/unable-to-paste-from-spreadsheet.223298/
        if (preg_match('/^\[(th|td)/i', $stringOutput))
        {
            return $stringOutput;
        }
        // End Workaround

        $css = $tag->attribute('style');
        if ($css)
        {

I tested the workaround. It removes all cell customizations but it works.
Now the bbcode.php is listed in the integrity check. @Steffen Can this be fixed?

@tenis You should write td instead of TD for example.

Edit: the bbcode,php can be found in src/XF/Html/Renderer
 
Last edited:
My first try was with no CAPS. Then I tried with CAPS to match the existig errors.
I want to try a “find and replace” query update.
Example:
Code:
UPDATE xf_post SET message = REPLACE(message, 'oldtext', 'newtext');

And I will replace something like:
Code:
TABLE="class: x"] --> [TABLE]
[TD][B]Nr --> [TD width="25"][B]Nr
[TD][CENTER][B]LOC       --> [TD width="25"][CENTER][B]LOC   
[TD="width: 25"] --> [TD width="25"]
[TD="width: 120"] --> [TD width="120"]
[TD="width: 280"] --> [TD width="280"]
[TD="width: 20"] --> [TD width="20"]
TD="bgcolor:#2C75ee"] --> [TD]
[TD="bgcolor:#d31f1f"] --> [TD]
[TD="bgcolor:#00ff00"] --> [TD]
[TD="bgcolor:#ffff00"] --> [TD]
[TD="bgcolor:#ff0000"] --> [TD]
[TD="bgcolor:#ff8700"] --> [TD]
 
Last edited:
Back
Top Bottom