Auto column width in EPPlus

前端 未结 10 1417
心在旅途
心在旅途 2020-12-23 00:31

How to make columns to be auto width when texts in columns are long?

I use this code

 Worksheet.Column(colIndex).AutoFitColumn() \'on all columns\'
         


        
10条回答
  •  难免孤独
    2020-12-23 00:54

    I know this is an old question, but I use the code below and it seems to directly address what you have tried to do.

    using (var xls = new ExcelPackage())
    {
        var ws = xls.Workbook.Worksheets.Add("Some Name");
    
        //**Add Column Names to worksheet!**
        //**Add data to worksheet!**
    
        const double minWidth = 0.00;
        const double maxWidth = 50.00;
    
        ws.Cells.AutoFitColumns(minWidth, maxWidth);
    
        return pkg.GetAsByteArray();
    }
    

提交回复
热议问题