POI

POI api Projects

POI api Project 1

How to Set Sheet Name and Compressed Unicode
Previous Home Next

 

In this page of the example we are going to set the sheet name and compress it. There are following 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.

setSheetName( int sheet, String name, short encoding):-
This method is automatically detects Unicode and sets the encoding appropriately. for performing this operation we can used the setSheetName(int sheet, String encoding).


 
package r4r;
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFRow;
public class setsheetnamecompressed {
	public static void main(String arg[]) {
		try{
		FileOutputStream out = new FileOutputStream
		("setSheetNameUnicodeDataFormat.xls");
		HSSFWorkbook hssfworkbook = new HSSFWorkbook();
		HSSFCellStyle cs = hssfworkbook.createCellStyle();
		hssfworkbook.setSheetName(0, 
		"\u0422\u0441\u0422\u043E\u0432\u0430\u044F " + 
		"\u0421\u0442\u0440\u0437\u043D\u0438\u0447\u043A\u0422", 
		  HSSFWorkbook.ENCODING_UTF_16 );
		hssfworkbook.write(out);
		out.close();
		}catch(Exception e){}
		  }
}


Previous Home Next