From 086694595db74a618f130476698d3c725fc100c1 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Wed, 21 Aug 2024 16:24:25 +0800 Subject: [PATCH] =?UTF-8?q?excel=E5=AF=BC=E5=87=BA=E7=9A=84=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E8=A1=8C=E9=AB=98=E6=A0=B9=E6=8D=AE=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=A0=BC=E5=86=85=E5=AE=B9=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tiobon.Core.Common/Helper/NPOIHelper.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Tiobon.Core.Common/Helper/NPOIHelper.cs b/Tiobon.Core.Common/Helper/NPOIHelper.cs index 71641da7..3198ea43 100644 --- a/Tiobon.Core.Common/Helper/NPOIHelper.cs +++ b/Tiobon.Core.Common/Helper/NPOIHelper.cs @@ -308,7 +308,6 @@ public class NPOIHelper try { sheet.SetColumnWidth(columnNum, columnWidth * 300); // 256 - } catch (Exception e) { @@ -316,6 +315,18 @@ public class NPOIHelper } } + for (int rowNum = 2; rowNum <= sheet.LastRowNum; rowNum++) + { + IRow currentRow = sheet.GetRow(rowNum); + + int length = 25; + foreach (var item in currentRow.Cells) + { + if (item != null) + length = Encoding.UTF8.GetBytes(item.ToString()).Length > length ? Encoding.UTF8.GetBytes(item.ToString()).Length : length; + } + currentRow.HeightInPoints = 35 * (length / 150 + 1); + } using (MemoryStream ms = new MemoryStream()) { workbook.Write(ms);