Post

Table Export Example In Chrome Extensions-img

Table Export Example In Chrome Extensions

June 16, 2023

Tansel Berkant Oflaz

Tansel Berkant Oflaz

Easy way to Exporting Tables in Chrome Extensions

Chrome Extensions

Javascript

Greetings...

Problem

We have a Chrome Extension and we find that there was a problem in our Export Excel operations in the tables we created on this extension. Our tables were being exported, but although the resulting file worked smoothly on Mac computers, it could not be opened on Windows-based computers and Office Excel documents.

Blog Post Image

You can see on the photo an error occurred. If you press yes to continue, you can see that the file is far from readable.

Blog Post Image


Solution

As I said at the beginning, these processes were running smoothly on Mac computers and were causing problems on Windows computers. While the document was unreadable in Office Excel Document, people using Mac Computers could view the data cleanly in IOS’s own Sheet Program.

After reviewing the codes and getting lost in the big project, I thought it would be more useful to use export libraries. Because I didn’t want to spoil a structure that works on one side just because it doesn’t work in a different place.

After a long search for the Export Library, my teammates recommended linways/table-to-excel to me.

You can find the github repo and documentation here.

First of all, I started by defining the CDN on the Extension.

Blog Post Image

Then I invoked the function by capturing the tableIds in our export buttons and sending them to the function I defined in the global.

Blog Post Image

Here is our function. Because we have more than one export process, I tried to make special naming according to the table id. Then I sent it to TableToExcel to handle the job for me

Blog Post Image

Test Our Code

File Output:

Blog Post Image

In this article, I explained the event through the chrome extension but you can use the CDN in your own different projects in a very simple way by defining it in script tags.
I’m leaving the github link here again as a guide for you..

Blog Post Image


© 2024 Tansel Berkant Oflaz. All Rights Reserved.