Compressed Unicode in Excel Using POI3.0

In this program we are going to set the sheet name forcing the encoding.

Compressed Unicode in Excel Using POI3.0

In this program we are going to set the sheet name forcing the encoding.

Compressed Unicode in Excel Using POI3.0

Compressed Unicode in Excel Using POI3.0

     

In this program 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 used to set the sheet name. 

setSheetName(int sheet, String name, short encoding): 
This method is deprecated. In POI 3.0, now automatically detects unicode and sets the encoding appropriately. Simply use setSheetName(int sheet, String encoding)

setSheetName(int sheet, String name):
This method is used to set the sheet name. This method can  throw IllegalArgumentException if the name is greater than 31 chars or contains /\,?,*,[,],etc 

setSheetName( int sheet, String name, short encoding):
This method is also deprecated. Now POI3.0 automatically detects Unicode and sets the encoding appropriately. Simply use setSheetName(int sheet, String encoding) 
 
 The code of the program is given below:
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFRow;
class compressedUnicode
  {
  public static void main(String arg[]) {
try{
FileOutputStream out = new FileOutputStream
(
"compressedUnicode.xls");
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
HSSFCellStyle cs = hssfworkbook.createCellStyle();
hssfworkbook.setSheetName(0"HSSF Test"
HSSFWorkbook.ENCODING_COMPRESSED_UNICODE 
);
hssfworkbook.write(out);
out.close();
}catch(Exception e){}
  }}

The output of the program is given below:

Download this example.