Professional Documents
Culture Documents
Package Import Import Import Import Import Import Import Import Import Import Import Import Public Class
Package Import Import Import Import Import Import Import Import Import Import Import Import Public Class
com.bethecoder.tutorials.jexcelapi.write;
import java.io.File;
import java.io.IOException;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.format.Colour;
import jxl.format.Pattern;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
public class CellBackgroundPatternTest {
/**
* @param args
* @throws IOException
* @throws IOException
* @throws WriteException
* @throws BiffException
*/
public static void main(String[] args) throws IOException, WriteExceptio
n {
//Creates a writable workbook with the given file name
WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/JXL/
BGPattern.xls"));
WritableSheet sheet = workbook.createSheet("My Sheet", 0);
// Create the label, specifying content and format
Label label = new Label(1, 2, "ABC", getCellFormat(Colour.GREEN, Patte
rn.GRAY_25));
Label label2 = new Label(1, 4, "PQR", getCellFormat(Colour.BLUE, Patte
rn.GRAY_50));
Label label3 = new Label(1, 6, "XYZ", getCellFormat(Colour.ORANGE, Pat
tern.GRAY_75));
sheet.addCell(label);
sheet.addCell(label2);
sheet.addCell(label3);
//Writes out the data held in this workbook in Excel format
workbook.write();
//Close and free allocated memory
workbook.close();
}
/*******************************With Bold*****************************/
return cellFormat;
}
/*********************************Without Bold**********************/
return cellFormat;
}
/******************************************************************/
}
It gives the following output,