Hi @amjad.sahi,
Yes, I’ve tried the new version 23.3 and the updated sample code @John.He provide me.
there are few regressions in this version/code.
- row height is changed and is not consistent with the rest of the pdf. (section table header, first row -when short or long the hight is different, when very long is also another size- and the last row of the table.
- the long email - is still cut in the middle from the top border.
- the date time format changed from 12H display to 24H. which should not happen.
image.png (21.9 KB)
attached 3 version
- valid hights with word wrap issue (old version) old version with word wrap issue.pdf (53.9 KB)
- with version upgrade version upgraded.pdf (159.8 KB)
- version upgrade + updated code. version upgrade + updated code.pdf (137.9 KB)
here’s the updated code -
//double minTextLengthToBrake = Convert.ToInt32(_configuration["WorkbookDefaultStyle:MinTextLengthToBrake"]);
double minTextLengthToBrake = 40;
var activeWorksheet = workbook.Worksheets[0];
for (int i = 0; i < activeWorksheet.Cells.Rows.Count; i++)
{
var row = activeWorksheet.Cells.Rows[i];
if (row == null || row.LastCell == null || row.FirstCell == null)
{
continue;
}
for (int columnI = 0; columnI < row.LastCell.Column; columnI++)
{
var cell = row.GetCellOrNull(columnI);
if (cell == null
|| cell.Type == CellValueType.IsNull
|| cell.IsMerged)
{
continue;
}
if (!string.IsNullOrWhiteSpace(cell.Value.ToString()))
{
var style = cell.GetStyle();
style.HorizontalAlignment = TextAlignmentType.Left;
cell.SetStyle(style);
cell.Value = cell.Value.ToString().Trim();
}
if (cell.Value.ToString().Trim().Length >= minTextLengthToBrake)
{
var style = cell.GetStyle();
style.IsTextWrapped = true;
cell.SetStyle(style);
AutoFitterOptions autoFitterOptions = new AutoFitterOptions()
{
IgnoreHidden = true,
FormatStrategy = CellValueFormatStrategy.DisplayString,
MaxRowHeight = 36,
AutoFitWrappedTextType = AutoFitWrappedTextType.Paragraph
};
activeWorksheet.AutoFitRow(row.Index, row.FirstCell.Column, row.LastCell.Column, autoFitterOptions);
}
}
}
save format:
public void PrintingSetup(Worksheet activeWorksheet)
{
var pageSetup = activeWorksheet.PageSetup;
pageSetup.PaperSize = PaperSizeType.PaperA4;
pageSetup.SetFitToPages(1, 0);
}
saving to stream
public byte[] SaveToStream(WorkbookDesigner designe)
{
using var stream = new MemoryStream();
var pdfSaveOptions = GetPdfSaveOption();
designer.Workbook.Save(stream, pdfSaveOptions);
return stream.ToArray();
static PdfSaveOptions GetPdfSaveOption() => new()
{
OptimizationType = PdfOptimizationType.MinimumSize,
AllColumnsInOnePagePerSheet = true,
};
}