我正在使用EEPlus在MVC-5 C#应用程序下构建一个Excel文件.一切都按计划进行,直到我在一行上设置一个高度(因此图像可以适合).
我加载de图像并在第20列设置高度,如下所示:
Image cfPhoto = null;
Bitmap cfBm = null;
ExcelPicture pictureCf = null;
var photoInitialColumn = 0;
i++;
completedFormPhotos.ForEach(delegate(CompletedFormPhoto cfP)
{
cfPhoto = Image.FromFile(HostingEnvironment.MapPath("~/Content/Images/FormPhotos/" + cfP.Id + ".jpg"));
cfBm = new Bitmap(cfPhoto, new Size(215, 170));
pictureCf = worksheet.Drawings.AddPicture(cfP.Id.ToString(), cfBm);
pictureCf.SetPosition(i+1, 0, photoInitialColumn, 10);
worksheet.Cells[_alpha[photoInitialColumn] + (i + 3) + ':' + _alpha[photoInitialColumn + 1] + (i + 3)].Merge = true;
worksheet.Cells[_alpha[photoInitialColumn] + (i + 3) + ':' + _alpha[photoInitialColumn + 1] + (i + 3)].Value = cfP.comment;
worksheet.Cells[_alpha[photoInitialColumn] …Run Code Online (Sandbox Code Playgroud) 我正在使用EPPlus和C#并试图自动调整/自动调整行的高度以适应显示带有文本换行的合并单元格的所有内容所需的高度.但无论我尝试什么,文本总是截断.由于我在各种工作表上使用各种文本大小重复此过程,因此我不想对行高进行硬编码(除了强制行的最小高度).如果可能的话,我想在EPPlus/C#中做到这一点.
单元格A2:E2合并,WrapText = true:
文本截断的单元格
这是所需的Cell Height应该是什么样子
这是我的相关简短C#代码
Int32 intToCol;
intToCol = 5;
eppWorksheet.Cells[2, 1, 2, intToCol].Merge = true;
eppWorksheet.Cells[2, 1].Style.WrapText = true;
//Check if at the minimum height. If not, resize the row
if (eppWorksheet.Row(2).Height < 35.25)
{
eppWorksheet.Row(2).Height = 35.25;
}
Run Code Online (Sandbox Code Playgroud)
我看过EPPlus中的Autofit行,除非我读错了,否则它似乎没有直接回答我的问题.
但是我遗漏了一些细节,因为下面的代码写在一行上并且没有扩展单元格的高度.到目前为止,这是我的代码:
ws.Cells[$"A{row}:F{row}"].Merge = true;
ws.Cells[$"A{row}"].Style.WrapText = true;
ws.SelectedRange[$"A{row}"].Value = purchaseHistory[0].LineText;
Run Code Online (Sandbox Code Playgroud)