Problem of not being able to use Autofit in xlsx or html-to-xlsx format



  • Greetings, can autofit be made according to the length of the incoming data in reports in xslx or html-to-xlsx format? From the link below
    There are two examples I made in playgraound. Although I used the "xlsxColAutofit" feature in the html-to-xlsx example, it did not work. Can you help me with this?

    https://playground.jsreport.net/w/anon/bWIiZgrQ


  • administrators

    hi!

    for the template "test2" which uses html-to-xlsx recipe the issue is the inline style you use for the table, letter-spacing: -4px any reason why are you doing this? if you remove this negative spacing it works as expected, in html-to-xlsx recipe the autofit is done automatically, no need to do anything else

    this piece of code you have there can be removed (anyway it is not doing anything valid/supported)

    Object.assign(options, {
          xlsx: {
            addOptions: {
              xlsxColAutofit: true
            }
          }
        });
    

    for the template "test" which uses xlsx recipe, you are using the xlsxColAutofit helper wrong, the xlsx recipe has two phases, the generation and transformation phase, xlsxColAutofit is a helper designed to be used in the generation phase (so inside the xlsx template edited by MS Excel), however you are using it in the transformation phase which is wrong. an updated example can be found here: https://playground.jsreport.net/w/anon/u4O~fYYf

    for the autofit to work correctly you need to generate the cells in the generation phase, because if you create new cells in the transformation phase then the xlsxColAutofit won't be able to catch them because it runs first.



  • thank you for your help l fix my problem


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.