jsreport html-to-excel options

1.2k views Asked by At

I'm using the excellent jsreport solution to convert html to excel using the 'html-to-excel' recipe.
Does this recipe have any options to control the worksheet options?
Like display the sheet right to left, set the sheet's name, display grid lines etc.

1

There are 1 answers

4
itminus On BEST ANSWER
  1. The html-to-excel recipe uses html-to-xlsx under the hood. According to the document, if you want to display grid lines, you could use css style to control grid line :
    td {
        border-style: solid;
    }

you could also use text-align too. But only a little features are supported.

  1. The default html-to-xlsx (legacy) doesn't support custom sheet names. However, if you look into the unit test, you will find that there's a better html-to-better-xlsx:
      template: {
        content: `
        <table name="Data">
          <tr>
              <td data-cell-type="number">1</td>
          </tr>
        </table>
        `,
        recipe: 'html-to-better-xlsx',
        engine: 'none',
        baseXlsxTemplate: {
          content: xlsxTemplateBuf.toString('base64')
        },
        htmlToXlsx: {
          insertToXlsxTemplate: true
        }
      }

that means adding a [name] attribute to table and setting the recipe as html-to-better-xlsx should work.

  1. The Xlsx recipe allows us to control over the Excel completely. For example, to custom the sheet name, see https://playground.jsreport.net/w/anon/BJa5OBWD-2
{{#xlsxMerge "xl/workbook.xml" "workbook.sheets[0].sheet[0]"}}
   <sheet name="My Sheet Name"/>
{{/xlsxMerge}}

{{{xlsxPrint}}}