How to call the SetColumnWidth function from the Excel Buffer

Hi all,

May I know how to call the SetColumnWidth function from the Excel Buffer in Business Central? the ColName how to verify?

Thank you.

Answers

  • AlexDenAlexDen Member Posts: 86
    Hi,

    Add this code to the WriteSheet() function before setting the orientation:
    XlWrkShtWriter.SetColumnWidth('B',120);
    

    And use the following code to create a new workbook:
    xlBuffer.CreateBook('','Sheet1');
    xlBuffer.AddColumn('Some text',FALSE,'',FALSE,FALSE,FALSE,'',xlBuffer."Cell Type"::Text);
    xlBuffer.SetSkipAutoFit();  // Important to use this function if you want to have custom column width
    xlBuffer.WriteSheet('','','');
    xlBuf.CloseBook;
    xlBuf.OpenExcel;
    xlBuf.GiveUserControl;
    

    It's just an example, you have to create function to save columns names and width to some variable and then use it in WriteSheet() function.
    Keep in mind that in this case you will have to specify width for all columns as AutoFit function is disabled.
Sign In or Register to comment.