Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AutoSizeRow method #907

Merged
merged 11 commits into from
Aug 21, 2022

Conversation

artem-iron
Copy link
Contributor

There was AutoSizeColumn method, that adjusts width of the column to fit it's contents, but no such method to adjust the height of the row. This change implements such a method in a very similar to AutoSizeColumn way. It also adds a tests for new methods.

Artem Koloskov added 11 commits August 9, 2022 14:13
Added to prepare for auto height for rows implementation
…of SheetUtil.

Also added method to check row height in specific span of columns.
…dd reloads with actual IRow for GetRowHeight.
Got rid of default character height, it as needed by width getter, because excel limits width of the column by number of characters, and height isn't tied to it. Fixed how row span is counted, it was wrong. Added ratio to final height so it is close to how  excel would count it.
Implemented in ISheet interface and in XSSFSheet class. HSSFSheet and SXSSFSheet implement interface through stubs for now.
SixLabors.ImageSharp mesures strings differently, thus new control value.
@tonyqus
Copy link
Member

tonyqus commented Aug 21, 2022

Since this is a new feature and there is no impact on existing features, I'll merge it first and see if there is some feedback from users. Thank you for your contribution. I really appreicate it.

@tonyqus tonyqus merged commit a273be8 into nissl-lab:master Aug 21, 2022
@artem-iron
Copy link
Contributor Author

The pleasure is mine, thanks for taking time to take a look at it.

@artem-iron artem-iron deleted the implement-autosizerow branch August 22, 2022 03:37
@tonyqus tonyqus added this to the NPOI 2.6.0 milestone Nov 15, 2022
@ahmedsharafzyada
Copy link

I am facing this issue

System. Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at NPOI.SS.Util.SheetUtil.IFont2Font(IFont font1) at NPOI.SS.Util.SheetUtil.GetDefaultCharWidth(IWorkbook wb) at NPOI.SS.Util.SheetUtil.GetColumnWidth(ISheet sheet, Int32 column, Boolean useMergedCells, Int32 firstRow, Int32 lastRow, Int32 maxRows) at NPOI.SS.Util.SheetUtil.GetColumnWidth(ISheet sheet, Int32 column, Boolean useMergedCells) at NPOI.XSSF.UserModel.XSSFSheet.AutoSizeColumn(Int32 column, Boolean useMergedCells) at NPOI.XSSF.UserModel.XSSFSheet.AutoSizeColumn(Int32 column) at SAS.RCM.DataExportInvalidOperationException:ing.Excel.NPOI.NpoiExcelExporterBase.CreateExcelPackage(String fileName, Action1 creator)

@artem-iron
Copy link
Contributor Author

Linux/docker?

@artem-iron
Copy link
Contributor Author

Usually this happens to me on docker images with no fonts installed. The AutoSizeColumn method is measuring the string in the cell using it's font but for this it need information on the font. And in many Linux images there are no font installed which creates this error you are facing. Even if this is not a Linux - just try to install any font and try again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants