POI

POI api Projects

POI api Project 1

Compressed Unicode in Excel Using POI2.5
Previous Home Next

In this page of the tutorials we are going to set the sheet name forcing the encoding. The methods can be used for built in data format.

setSheetName(int sheet, String name)

This method is provide the facility to set the sheet name in Excel.

setSheetName(int sheet, String name, short encoding)

This method is used to detect the automatically unicode and sets its encoding appropriately. Simply we can use the setSheetName(int sheet, String encoding) method. this has the facility to set the unicode for setting encoding appropriately.

setSheetName(int sheet, String name)

This method is also used to set the sheet name. It is throw IllegalArgumentException if we are take the name which is greater than 31 chars or contains /\,?,*,[,],etc then it will throws the exception.

Example

package r4r;
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFRow;
public class compressedtest {
	public static void main(String arg[]) {
		try{
		FileOutputStream out = new FileOutputStream
		("compressedtest.xls");
		HSSFWorkbook hs = new HSSFWorkbook();
		HSSFCellStyle hc = hs.createCellStyle();
		hs.setSheetName(0, "HSSF Test", HSSFWorkbook.ENCODING_COMPRESSED_UNICODE );
		hs.write(out);
		out.close();
		}catch(Exception e){} 
	}
}
Previous Home Next