• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

setShrinkToFit using POI

Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am trying to implement setShrinkToFit function using jakarta POI Package, for setting a particular cell in MS Excel to have the property setShrinkToFit to be checked as true.

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import java.io.IOException;
import java.io.FileOutputStream;

public class TestHSSFCellStyle extends HSSFCellStyle {

TestHSSFCellStyle(ExtendedFormatRecord e) {

super((short) 0, e);


public static void main(String[] args) throws IOException {

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("format sheet");

ExtendedFormatRecord e = new ExtendedFormatRecord();


TestHSSFCellStyle t1 = new TestHSSFCellStyle(e);
HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0);

FileOutputStream fileOut =
new FileOutputStream("workbookTest.xls");


But, I am not able to set the property. Kindly help me to proceed the same.

Posts: 43081
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't really have an answer, but the javadocs says about the constructor you're using:

protected HSSFCellStyle (short index, ExtendedFormatRecord rec)
Creates new HSSFCellStyle why would you want to do this??

That might be worth thinking about. Since all the other ExtendedFormatRecord options are accessible through HSSFCellStyle, maybe setShrinkToFit isn't implemented?

I'm also not quite clear on what 'index' is; are you sure that 0 is an appropriate value?
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic