Hi, excel provides the option "shrink to fit" for a cell, which autosizes the content of the cell, if it is too long. Unfortunately it is not possible to set this option using POI. Since the class "org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment" already supports this option, the necessessary enhancement should be quite simple. I just need the following methods in XSSFCellStyle: public void setShrinkToFit(boolean shrinkToFit) { getCellAlignment().setShrinkToFit(shrinkToFit); } public boolean getShrinkToFit() { CTCellAlignment align = _cellXf.getAlignment(); return align != null && align.isSetShrinkToFit(); } Regards Oliver
Does Excel support this for .xls files, or is it .xlsx only? (That would affect if we need to put it on the interface or not, and if we therefore need to get a test .xls file to identify the record there)
Created attachment 30956 [details] Test file containing the option "shrink to fit" Excel supports this for .xls files too. I've added a test document which contains a cell with this option.
If you have some time, any chance you could create two very similar and simple .xls files? Firstly create one without shrink to fit, then open the same file + set shrink to fit + save-as. (Should help ensure they're very similar). Then, run org.apache.poi.hssf.dev.BiffViewer against the two, and diff the output. With any luck, that will flag up the record that gets changed, along with the option to do it!
Hi POI developer, excel provides the option "shrink to fit" for a cell, which autosizes the content of the cell, if it is too long in version 3.7. but I can't find the method 'setShrinkToFit' in class "org.apache.poi.hssf.usermodel.HSSFCellStyle" at version 3.9.
I've created both test files (with and without shrink to fit) and diffed the output of BiffViewer. Unfortunately there are 275 differences between them. But in the output for the file with shrink to fit a found the entry ".shrinktoft= true" in line 3475. I hope/guess this is the important difference between these files.
Created attachment 30967 [details] The output of BiffViewer for a file without shrink to fit
Created attachment 30968 [details] The output of BiffViewer for a file with shrink to fit
(In reply to Oliver Frank from comment #5) > for the file with shrink to fit a found the entry > ".shrinktoft= true" in line 3475. That looks very likely to be what we need! Which record does this live in? (Should be a few lines about that in the output)
Here is the record, in which this line occurs: Offset=0x00000C9A(3226) recno=114 sid=0x00E0 size=0x0014(20) [EXTENDEDFORMAT] CELL_RECORD_TYPE .fontindex = 0 .formatindex = 0 .celloptions = 1 .islocked = true .ishidden = false .recordtype= 0 .parentidx = 0 .alignmentoptions= 20 .alignment = 0 .wraptext = false .valignment= 2 .justlast = 0 .rotation = 0 .indentionoptions= 1010 .indent = 0 .shrinktoft= true .mergecells= false .readngordr= 0 .formatflag= false .fontflag = false .prntalgnmt= true .borderflag= false .paternflag= false .celloption= false .borderoptns = 0 .lftln = 0 .rgtln = 0 .topln = 0 .btmln = 0 .paleteoptns = 0 .leftborder= 0 .rghtborder= 0 .diag = 0 .paleteoptn2 = 2000000 .topborder = 0 .botmborder= 0 .adtldiag = 0 .diaglnstyl= 0 .fillpattrn= 0 .fillpaloptn = 20c0 .foreground= 40 .background= 41 [/EXTENDEDFORMAT] Does this contain the information, that you need?
Thanks for your investigations, and test files I've added support in r1539848, along with unit tests for it in r1539850.