web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

how to autofit columns in excel file

(0) ShareShare
ReportReport
Posted on by 1,176

Hello,

I've written a class that inherits from runbasebatch and I'm using it to fill up excel file. I use two classes  -     OXMLWorkbook_RU, OXMLWorksheet_RU. Here I open and close Excel document:

protected void printDocument(Common   _caller)
{

    this.makeDocument();

    workbook = excelDocument.workbook();
    worksheet = workbook.getWorksheet();
    bookmark = '';


    this.createTMPTable(_caller);
    this.formatTitle(_caller);
    this.formatHeader(taskDaysFactTmp_ICL);
    this.formatBody(taskDaysFactTmp_ICL,taskDaysFactTmp_ICL_additional, _caller);
    
    excelDocument.closeDocument(true);

    comExcelDocument = new ComExcelDocument_RU();
    comExcelDocument.open(excelDocument.fileName(), true);
}

BUt excel file opens with width of the columns not according to the contains of the columns. HOw to autofeet columns? I didn't find anything useful in classes OXMLWorkbook_RU, OXMLWorksheet_RU. I found googling that it can be done like that:

sysExcelWorksheet.columns().autoFit();

But I'm not using SysExcelWorksheet class at all. How to do that in my case?

Thanks.

I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Azat,

    If I understood correctly OpenXML doesn't support autofit option and you need to calculate the width for each column based on cell content

    social.msdn.microsoft.com/.../solution-how-to-autofit-excel-content

  • dark_knight Profile Picture
    1,176 on at

    Hi Sergei,

    I use two classes  -     OXMLWorkbook_RU, OXMLWorksheet_RU but class OXMLWorksheet_RU doesn't contain any autofit() methods for columns.

    Thanks.

  • Tony Mok Profile Picture
    577 on at

    If it is OfficeOpenXml, you can use cells.get_item(1,1,worksheet.Dimension.End.Row,worksheet.Dimension.End.Column).AutoFitColumns();

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 663

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 439 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 337 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans