Set column width from HTML

Hello

How can we set the column width using HtmlLoadOptions while converting HTML to Excel?

Thanks

@akash400mn you can set the column width by specifying the width in any of the cells in that column.
For example, try this:

<table border="1">
  <tr>
    <th style="width:100px">Header 1</th>
    <th style="width:200px">Header 2</th>
    <th style="width:300px">Header 3</th>
  </tr>
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
    <td>Cell 3</td>
  </tr>
</table>

Does this work for you?

Regards,
Mario

@akash400mn or you can use the columns group with the current latest version:
https://www.gemboxsoftware.com/spreadsheet/nightlybuilds/GBS49v1263.zip

Or the current latest NuGet package:
Install-Package GemBox.Spreadsheet -Version 49.0.1263-hotfix

For example, try this:

<table border="1">
  <colgroup>
    <col width="100">
    <col width="200">
    <col width="300">
  </colgroup>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
    <th>Header 3</th>
  </tr>
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
    <td>Cell 3</td>
  </tr>
</table>

Regards,
Mario

Thanks Mario

Definitely i will try this.
One more query, i am using serial key provided by my client. I have html file size of 6 mb and i am trying to convert to pdf using SpreadsheetInfo but getting following error
**
“Input file or data stream does not conform to the expected file format specification”
**
but doing the same thing with some kb size html file, it converts fine. Can you pls help me with this.

Unfortunately, I was unable to reproduce this issue.
Please send us your HTML file so that we can reproduce the issue and investigate it.

Hello Mario,
unfortunately. i am not able to upload the html file here, is there any other way to upload it?

You can send us an email or create a support ticket, see our Contact page.

1 Like

The problem occurs because the HTML table contains this:

<tbody>
  <tr>
    ...
  </tr>
<tbody>
  <tr>
    ...
  </tr>
<tbody>
  <tr>
    ...
  </tr>
<tbody>
...

In other words, a new <tbody> tag is opened for each row and at the very end there is only one </tbody> closing tag.
As a quick fix, you can just remove all the occurrences of <tbody> and </tbody> from your HTML.

I hope this helps.

Regards,
Mario