tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Excel > JExcel API > How to set Text Orientation in Excel Cells

How to set Text Orientation in Excel Cells 

Java Excel API is an open source java library to read, write and modify Excel spread sheets. This requires the library jxl-2.6.12.jar to be in classpath. The following example shows how to set Cell Orientation in Excel Spread sheet.

File Name  :  
com/bethecoder/tutorials/jexcelapi/write/CellOrientationTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.jexcelapi.write;

import java.io.File;
import java.io.IOException;

import jxl.Workbook;
import jxl.format.Orientation;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

public class CellOrientationTest {

  /**
   @param args
   @throws IOException 
   @throws IOException 
   @throws WriteException 
   @throws BiffException 
   */
  public static void main(String[] argsthrows IOException, WriteException {
    //Creates a writable workbook with the given file name
    WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/JXL/CellOrientation.xls"));

    WritableSheet sheet = workbook.createSheet("My Sheet"0);
    
    /**
     * Add Orientation cells
     */
    addCell(sheet, Orientation.VERTICAL, 00"Vertical Orientation");
    addCell(sheet, Orientation.PLUS_90, 10"Plus 90 Orientation");
    addCell(sheet, Orientation.MINUS_90, 20"Minus 90 Orientation");
    addCell(sheet, Orientation.PLUS_45, 30"Plus 45 Orientation");
    addCell(sheet, Orientation.MINUS_45, 60"Minus 45 Orientation");
    addCell(sheet, Orientation.STACKED, 70"Stacked Orientation");
    
    //Writes out the data held in this workbook in Excel format
    workbook.write()

    //Close and free allocated memory 
    workbook.close()
  }

  private static void addCell(WritableSheet sheet, 
      Orientation orientation, 
      int col, int row, String descthrows WriteException {
    
    WritableCellFormat format = new WritableCellFormat();
    format.setOrientation(orientation);
    Label label = new Label(col, row, desc, format);
      sheet.addCell(label);
  }
}
   

It gives the following output,
cell-orientation.gif


                    Print

   



Books Recommendation

 
 
bl  br