To create a format painter button, add an event listener to indicate when to copy the formatting of a selected area, and indicate the new are to paste the formatting too. Then bind the selection changed event to the active sheet to invoke copyToOptions for the style and span to copy the formatting.
Steps to Complete:
Create a format painter button
Add an event listener to the format painter button
Create a resetFormatPainting() function
Bind the active sheets to the SelectionChanged event
Step 1: Create a format painter button
Add an HTML element button
Step 2: Add an event listener to the format painter button
Create two variables, fromRange, and isFormatpainint = False.
Add an event listener to the format painter button to get the sheets selection.
Store the selection in a data array and store the data array in the variable fromRange.
Then have the isFormatPainting variable change to True to indicate that when the button is clicked, formatting is occurring.
Finally, change the text content of the Format Painter button to read ‘Formatting’.
Step 3: Create a resetFormatPainting() function
Create a function called resetFormatPainting() that will set the variable isFormatPainting to False and change the text content of the Format Painter button to read “Format Painting”
Step 4: Bind the active sheets to the SelectionChanged event
Bind the active sheet to the SelectionChanged event that with determine the selected area and the area the formatting will be copied too. This utilizes SpreadJS’s copyToOptions to specify to copy the span and style.
After following these steps you are now able to use the Format Painter button to copy the format of a selected area to a new space in the SpreadJS instance.