使用epplus设置单元格宽度会影响整个列

Joa*_*tor 6 c# asp.net epplus

我在解决这个方面遇到了一些麻烦.有没有办法使用epplus从工作表中设置特定单元格的宽度?因为当我使用时,例如:

ws.Column(1).Width = 40;
Run Code Online (Sandbox Code Playgroud)

整栏受到影响.

提前致谢!

Han*_*Han 13

据我所知,没有办法改变特定细胞的宽度.一列中的所有单元格具有相同的宽度.您可以通过将单元格与其邻居合并来更改单元格的宽度.我有一个例子:

sheet.Cells["A1"].Value = "This is a cell";
sheet.Cells["A1:A2"].Merge = true;
Run Code Online (Sandbox Code Playgroud)

然后你可以使用设置宽度

sheet.Column(1).Width = 40;
Run Code Online (Sandbox Code Playgroud)

要么

sheet.Cells["A1:A2"].AutoFitColumns();
Run Code Online (Sandbox Code Playgroud)


Nag*_*Nag 0

嗨你可以尝试这样

 using (ExcelPackage pck = new ExcelPackage())
        {
            ExcelWorksheet ws = pck.Workbook.Worksheets.Add("1232");
            ws.Cells["A1"].AutoFitColumns();
            //ws.Cells[""].AutoFitColumns(20);//overloaded 
            //ws.Cells[""].AutoFitColumns(20,40);//overloaded min and max lengths
        }
Run Code Online (Sandbox Code Playgroud)