Hi,
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();
e.setShrinkToFit(true);
TestHSSFCellStyle t1 = new TestHSSFCellStyle(e);
HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0);
cell.setCellStyle(t1);
FileOutputStream fileOut =
new FileOutputStream("workbookTest.xls");
wb.write(fileOut);
fileOut.close();
}
}
But, I am not able to set the property. Kindly help me to proceed the same.
Thanks,
Vidhya