From e64e1727b5157887c56340be78689551c50936c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=89=E7=A5=A5=20=E8=A9=B9?= Date: Wed, 9 Oct 2024 19:11:28 +0800 Subject: [PATCH] fix mac height --- Controllers/ApiController.cs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index bf304e72..e472033d 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -518,6 +518,14 @@ namespace QuotationMaker.Controllers saRowIndex--; } + string agent = Request.Headers["User-Agent"].ToString(); + + string post_pc = "win"; + + if (agent.Contains("Macintosh")) + { + post_pc = "mac"; + } //自适应高度,9代表从第10行开始,表头部分不会多行;endRow是结束的行,也就是有数据内容的行数,毕竟没内容的单元格,也没必要自适应行高 for (int i = saRowIndex; i < saRowIndex + 3; i++) @@ -543,7 +551,7 @@ namespace QuotationMaker.Controllers cellWidth += sheet.GetColumnWidth(k); } - int cellStringLength = GetCellStringLength(CurCell.StringCellValue); + int cellStringLength = GetCellStringLength(CurCell.StringCellValue, post_pc); if (cellStringLength > cellWidth) { double newHg1 = (double)(OldHg * (cellStringLength / cellWidth + 1)); @@ -624,7 +632,7 @@ namespace QuotationMaker.Controllers string downloadName = objDetail.quotation_name + " 報價單_" + DateTime.Now.ToString("yyyy-MM-dd"); - string agent = Request.Headers["User-Agent"].ToString(); + //if (agent.Contains("Macintosh")) //{ @@ -647,7 +655,7 @@ namespace QuotationMaker.Controllers /// /// 待判断字符或字符串 /// 宽度 - public int GetCellStringLength(string text) + public int GetCellStringLength(string text, string pc_type) { //汉字 453、数字和字母 239 //这里的汉字与字母的宽度值,要根据Excel的字体大小计算 @@ -663,11 +671,26 @@ namespace QuotationMaker.Controllers } else if (t > 127) { - result += 660; + + if (pc_type == "win") + { + result += 660; + } + else { + result += 760; + } + } else { - result += 370; + if (pc_type == "win") + { + result += 370; + } + else { + result += 440; + } + } } return result;