This project has moved. For the latest updates, please go here.

autofit row height after setting height value

Mar 2, 2014 at 2:05 AM
Hello, I have an excel document that I want to manually adjust the height to 13.50 (18 pixels)
I saw no other way to set the default height, so
worksheet.Rows().Height = 13.5;
did that for me. However, once you manually set the height, I realized that when you are putting in long text in a cell even if text wrap is enabled, the outcome height will not adjust.
With calibri font and font size 10, the cells become around size 14 for every line when calling the row.adjusttocontent() method so if anybody can give me tips to either set the default height without ruining the textwrap auto height adjust, I'll be so glad :)
Coordinator
Mar 2, 2014 at 9:24 PM
I don't think that can be done. The reason you can do it in Excel is because it's row autofit works with text wrap. ClosedXML's adjust to contents only takes into account the number of lines in cell (in your case 1).

Do you know how to do it in Excel without using autofit?
Mar 2, 2014 at 10:04 PM
Thanks for the very quick reply :)
No, I don't think there is a way to do it without Cells->Format->Autofit height.
http://excelribbon.tips.net/T010735_Automatic_Row_Height_for_Wrapped_Text.html
That kind of explains the situation imo.
Is there any way to implement that kind of feature?
Or at least a way to "reset" the height of rows to the default which does autofit the height?
Coordinator
Mar 2, 2014 at 10:19 PM
Not for a single row. In your case I suggest you set the row height only for the rows you want them to have it and leave the rest with their default.
Mar 2, 2014 at 11:16 PM
hmm.. aite.
I have one last question that is not related to height, but data validation.
I have two worksheets.
Worksheet#1 have two cells, let's say they are A1 and B1.
A1 is a datavalidation from a list from a range from worksheet#2.
The workbook contains named ranges with a scope of the entire workbook, and the names are the possible values of the datavalidation of A1.
Then I want Cell A2 of Worksheet#1 to have a data validation of a list depending on the value of Cell A1, which can be done in excel with
=INDIRECT($A1)
pretty much A2 is getting the value of A1, and creating a dropdown menu which contains the values of ranges that have the name of the value of A1.
How can this be implemented?
I just need to know how that "=INDIRECT()" part can be done with ClosedXML.
Coordinator
Mar 2, 2014 at 11:34 PM
Indirect is not implemented. Did you check the data validation and auto filters pages in the documentation?
Mar 2, 2014 at 11:56 PM
Ah, bummer :/
Yeah, I read through the documentation and was just hoping there was a way around it.
Just because the cells do have formulas
cellWithFormulaA1.FormulaA1 = "=A2+$B$2";
I was hoping there was something similar like
Cell.DataValidation.List("=INDIRECT($A1)");
So currently no dependent drop down feature I guess? :(
Coordinator
Mar 3, 2014 at 12:47 AM
I guess I don't know what you mean. You can have a dropdown based on values from a set of cells. It doesn't matter if those cells get their value from formulas.