Excalidraw - Script to create a table

Disclaimer

Is this project open source? Yes
Is this project completely free? Yes
Is this project vibe-coded beyond the author’s ability to comprehend how it works? Yes
Community Directory: [Link](https://community.obsidian.md/xyz)


I was watch this video AI Scripting Superpowers and I decided to follow the steps and play with creating a few scripts. I thought I’d share it here in case any one else would like to use it.

Here is the file for the script. To make it work you need to place it the excalidraw scripts folder.

Create Table.md (15.2 KB)

Table creation process

Since manually creating a table in Excalidraw was tiresome, I created a script that would help with that process. The way it works is that you there is a popup where you enter the number of columns and rows that you would like to have, and then select where you want the headers of the table to be located. (if you want headers) And then on the next popup it has created a form for you to enter the contents of the table.

Templates

Since my use case for using tables is often conjugation or declension tables, the headings are often the same, and I wanted to be able to skip entering them each time. To do this I added a place where you could select a template to use on the first popup.

To save a template that you want to use later you fill out the header information, on the second cell entry popup and click a save template button on that page.

Limitations

  1. I haven’t testing this script with a mobile device, only on a laptop.

  2. I wanted the headers to be a different color than the regular cells so I hardcoded the color of the headers into the script. I’m using obsidian currently on a light theme, and the color I choose for the headers is simply black, if your using a dark theme then this isn’t going to work for you, you should go and change what color you want the headers to be in the script.

    This is the line you would need to change

    ea.style.strokeColor = headerVal ? "#000000" : (st.currentItemStrokeColor || "#000000");
    
    

If you type “black” into the obsidian find function, you should be able to figure out where this line in the script is fairly easily.

  1. There is only one style of table that I created.

Disclaimer

The script was created with ai, there might be bugs, and I don’t have any intention of maintaining the script in any way. Because of the way it was created, the code would most likely need a lot of work on it before it could go into any script library. I’m not familiar enough with the excalidraw api or obsidians to do that work.


This is just one of the scripts that I’ve created this way, I’ll most likely post a few more.

I’ve crossed posted this on the Excalidraw - github discussion page.