2

I'm generating HTML code for regular tables:

<table cellpadding="0" cellpadding="0">
    <tr>
       <td>Data</td>
       <td>Data</td>
       <td>Data</td>
    <tr>
</table>

After generation, I open the HTML file in a browser (Firefox) and copy and paste into blank Google Doc, BUT Google Docs translates the table without borders borders and default format.

There is a way to format the HTML table to meed the Google Docs requirements? Or there is a way to format a lot of tables of a Google Doc using a macro ? (I mean table borders and single linespacing)

Ivan Cachicatari
  • 4,212
  • 2
  • 21
  • 41

1 Answers1

7

The first thing I notice is the <table> has cellpadding="0" declared on it, twice.

“Do not use [cellpadding or cellspacing], as [they have] been deprecated. The element should be styled using CSS.” —MDN web docs

See this other StackOverflow question for how to set cellpadding and cellspacing in CSS.

This actually addresses your problem, as adding a border-collapse property to your table style will cause allow a table to paste into a Google Doc as a table… if you set it to separate.

Or if you add padding to your td (and th if you have them),

I created this Google Doc, Paste <table> into Docs, with some examples of how different styles effect how a table will paste into a Doc, with those styles noted.

Hope this helps!

I should also note, this was written with copying/pasting taking place in Chrome; different browsers will produce different results. I've also found how much is selected can effect how the table pastes in. My best advice is to experiment based on the look of your table and your desired result.

VTRGnW2uxM
  • 96
  • 2
  • 6