theoephraim / node-google-spreadsheet

Google Sheets API wrapper for Javascript / Typescript
https://theoephraim.github.io/node-google-spreadsheet
The Unlicense
2.32k stars 391 forks source link

Keeping formatting in text cells #611

Open AxelTerizaki opened 1 year ago

AxelTerizaki commented 1 year ago

Hello !

First, thanks for this module, it's very handy and the documentation really helped me understand how to fetch a gsheet for my app.

I have a question though and I'd like to know if it's an API limitation or if it's a "bug" : I have cells with text inside that has partial formatting applied, like some of the text is in italics in some of the cells.

So basically

"This kind of text" is returned as "This kind of text" without italics. Is this a google API limitation?

Thanks in advance for your answer !

theoephraim commented 1 year ago

Hi @AxelTerizaki

In general, there is no way to return text that includes italics, like "this kind of text". The best we can do is return all the info necessary to reconstruct that formatting. If we wanted to get really fancy, we could perhaps provide a way to get/set the text in equivalent html, as this would probably be more user friendly than the TextFormatRun metadata the sheets API uses... But I'd probably wait until I get a few requests to do this before implementing it.

Now on formatting in general -

If you are using the row-based methods, it is internally using the spreadsheets.values api, which simplify things quite a bit and has no formatting info available.

Using the cell based methods, there are methods to deal with the formatting of the entire cell, but I have not added anything to deal with the textFormatRuns yet. Although it would be very easy to at least just expose it as the data is already there. If this would be helpful for you, please let me know (and of course feel free to open a PR).

Cheers

BenediktEckstein commented 1 year ago

Hi It would be great to have access to TextFormatRun.

lortonx commented 6 months ago

bump

PrudiusVladislav commented 1 month ago

hey, any update on exposing the textFormatRuns? seems like I can't find it on the GoogleSpreadsheetCell object. I would really appreciate you adding the info about partial text formatting within cells, since it's the only thing blocking our project from using this amazing module.

lortonx commented 1 month ago

hey, any update on exposing the textFormatRuns? seems like I can't find it on the GoogleSpreadsheetCell object. I would really appreciate you adding the info about partial text formatting within cells, since it's the only thing blocking our project from using this amazing module. @PrudiusVladislav

This project extends the functionality of google-spreadsheet and adds the ability to control TextFormatRun https://gist.github.com/lortonx/6ccb1b27400e25382d92e8654f1b1949

theoephraim commented 1 month ago

@lortonx - nice work! That's really neat. I had been hoping to build something just like it.

Would be great to get it built into the core, although probably would not want to add cheerio as a dependency. I bet we could get away with a more lightweight (and less bullet-proof) html parser. Would love to see a PR if you're up for it :)