Excel Column width

Excel Column width

jtoler5jtoler5 Posts: 93Questions: 34Answers: 3

I tried searching for this but all I am finding references TableTools... is there anyway to make the export function for Excel using Buttons to set the column width? I would really like for it to just autowidth.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,468 Site admin

    No sorry. There wasn't that option with TableTools and there still isn't with Buttons. It is something that I plan to introduce a new feature for in the next major version of Buttons. Hopefully not too far away!

    Allan

  • jtoler5jtoler5 Posts: 93Questions: 34Answers: 3

    Awesome. Anyway we could customize the Excel more would be awesome! I have this project that currently has 3 separate files for screen, PDF, and excel. It was poorly written and I am trying to make it all one the correct way. An option to define to column format (ex: Number) would be awesome if there is not already a way.

  • ttse23ttse23 Posts: 10Questions: 3Answers: 0
    edited January 2017

    Is there an update for this issue? I need to adjust the widths for my columns

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948
    Answer ✓

    The below function will set all columns to width of 30. Assign it to the customize callback of the excel.

    function (xlsx) {
        var sheet = xlsx.xl.worksheets['sheet1.xml'];
        var col = $('col', sheet);
        col.each(function () {
              $(this).attr('width', 30);
       });
    };
    

    Kevin

  • ttse23ttse23 Posts: 10Questions: 3Answers: 0

    Thanks!

  • j.cuej.cue Posts: 7Questions: 1Answers: 0

    Joining the conversation a little late...
    @kthorngren what if we need only one specific column resized? Your code above works perfectly, but both of my examples below are not working.

    $('row c[r^="D"]', sheet).attr('width', 50);
    or
    $('row c[r^="D"]', sheet).each(function(){ $(this).attr('width', 50); });
    Any advice?

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948

    This code should allow you to set column D (col array element 3) to width of 50.

    function (xlsx) {
      var sheet = xlsx.xl.worksheets['sheet1.xml'];
      var col = $('col', sheet);
      $(col[3]).attr('width', 50);
    }
    

    Kevin

  • j.cuej.cue Posts: 7Questions: 1Answers: 0

    That worked!

    Do you by chance have a source where I can learn more about these manipulation techniques? Before finding this thread I had only seen 's' where 'width' is, and the only selector format I'd seen was in the $('row c...', sheet) format. I would really like to learn more about changing attributes like font size for a specific cell.

    Thanks for your help,

    Joe

  • kthorngrenkthorngren Posts: 21,315Questions: 26Answers: 4,948

    This page has some info that may help to understand the XML layout of the spreadsheet:
    http://officeopenxml.com/SScontentOverview.php

    My approach for this type of thing is to find some base examples to work from then use console.log to look at the parameters passed into the function. That's what I did to answer your question. Just took my example and looked at what was available via console.log(col). I'm sure I took the same approach for finding the original answer.

    Kevin

  • allanallan Posts: 63,489Questions: 1Answers: 10,468 Site admin

    Which is more or less the approach I took to develop the code originally :smile:. Took an xlsx file, unzipped it and take a look at the xml and try to cross reference it with what folklore is available on the web.

    Allan

  • j.cuej.cue Posts: 7Questions: 1Answers: 0

    Appreciate the insight. Thanks again!

    Joe

This discussion has been closed.