eplus操作excle行高自动换行

 1 private static void ChangeAllRowHeight(string filePath, string sheetName, double rowHeight)
 2 {
 3     using (ExcelPackage excelPackage = new ExcelPackage(new FileInfo(filePath)))
 4     {
 5         ExcelWorksheet excelWorksheet = excelPackage.Workbook.Worksheets[sheetName];
 6         int rowCount = excelWorksheet.Dimension.End.Row;
 7         
 8         // Set row height for each row and disable wrap text
 9         for (int i = 1; i <= rowCount; i++)
10         {
11             excelWorksheet.Row(i).Height = rowHeight;
12             excelWorksheet.Row(i).Style.WrapText = false; // Disable wrap text
13             
14             // Set background color for the first row
15             if (i == 1)
16             {
17                 excelWorksheet.Row(i).Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
18                 excelWorksheet.Row(i).Style.Fill.BackgroundColor.SetColor(Color.Gray); // Set gray background
19             }
20         }
21         
22         excelPackage.Save();
23     }
24 }

 

posted @ 2024-07-11 11:06  吖吼、  阅读(35)  评论(0)    收藏  举报