Expanded example
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352863 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
75166c95e4
commit
f4440a1c3c
@ -56,7 +56,9 @@ package org.apache.poi.hssf.usermodel.examples;
|
|||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
import org.apache.poi.hssf.usermodel.contrib.HSSFRegionUtil;
|
import org.apache.poi.hssf.usermodel.contrib.HSSFRegionUtil;
|
||||||
|
import org.apache.poi.hssf.usermodel.contrib.HSSFCellUtil;
|
||||||
import org.apache.poi.hssf.util.Region;
|
import org.apache.poi.hssf.util.Region;
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
@ -67,34 +69,43 @@ import java.io.FileOutputStream;
|
|||||||
*/
|
*/
|
||||||
public class ConvienceFunctions
|
public class ConvienceFunctions
|
||||||
{
|
{
|
||||||
public static void main( String[] args ) throws Exception
|
public static void main( String[] args )
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
HSSFWorkbook wb = new HSSFWorkbook();
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
HSSFSheet sheet1 = wb.createSheet( "new sheet" );
|
HSSFSheet sheet1 = wb.createSheet( "new sheet" );
|
||||||
|
|
||||||
|
// Create a merged region
|
||||||
HSSFRow row = sheet1.createRow( (short) 1 );
|
HSSFRow row = sheet1.createRow( (short) 1 );
|
||||||
|
HSSFRow row2 = sheet1.createRow( (short) 2 );
|
||||||
HSSFCell cell = row.createCell( (short) 1 );
|
HSSFCell cell = row.createCell( (short) 1 );
|
||||||
cell.setCellValue( "This is a test of merging" );
|
cell.setCellValue( "This is a test of merging" );
|
||||||
Region region = new Region( 1, (short) 1, 4, (short) 4 );
|
Region region = new Region( 1, (short) 1, 4, (short) 4 );
|
||||||
sheet1.addMergedRegion( region );
|
sheet1.addMergedRegion( region );
|
||||||
|
|
||||||
HSSFRegionUtil.setBorderBottom( HSSFCellStyle.BORDER_MEDIUM_DASHED,
|
// Set the border and border colors.
|
||||||
region,
|
final short borderMediumDashed = HSSFCellStyle.BORDER_MEDIUM_DASHED;
|
||||||
sheet1,
|
HSSFRegionUtil.setBorderBottom( borderMediumDashed,
|
||||||
wb);
|
region, sheet1, wb );
|
||||||
HSSFRegionUtil.setBorderTop( HSSFCellStyle.BORDER_MEDIUM_DASHED,
|
HSSFRegionUtil.setBorderTop( borderMediumDashed,
|
||||||
region,
|
region, sheet1, wb );
|
||||||
sheet1,
|
HSSFRegionUtil.setBorderLeft( borderMediumDashed,
|
||||||
wb);
|
region, sheet1, wb );
|
||||||
HSSFRegionUtil.setBorderLeft( HSSFCellStyle.BORDER_MEDIUM_DASHED,
|
HSSFRegionUtil.setBorderRight( borderMediumDashed,
|
||||||
region,
|
region, sheet1, wb );
|
||||||
sheet1,
|
HSSFRegionUtil.setBottomBorderColor(HSSFColor.AQUA.index, region, sheet1, wb);
|
||||||
wb);
|
HSSFRegionUtil.setTopBorderColor(HSSFColor.AQUA.index, region, sheet1, wb);
|
||||||
HSSFRegionUtil.setBorderRight( HSSFCellStyle.BORDER_MEDIUM_DASHED,
|
HSSFRegionUtil.setLeftBorderColor(HSSFColor.AQUA.index, region, sheet1, wb);
|
||||||
region,
|
HSSFRegionUtil.setRightBorderColor(HSSFColor.AQUA.index, region, sheet1, wb);
|
||||||
sheet1,
|
|
||||||
wb);
|
|
||||||
|
|
||||||
|
// Shows some usages of HSSFCellUtil
|
||||||
|
HSSFCellStyle style = wb.createCellStyle();
|
||||||
|
style.setIndention((short)4);
|
||||||
|
HSSFCellUtil.createCell(row, 8, "This is the value of the cell", style);
|
||||||
|
HSSFCell cell2 = HSSFCellUtil.createCell( row2, 8, "This is the value of the cell");
|
||||||
|
HSSFCellUtil.setAlignment(cell2, wb, HSSFCellStyle.ALIGN_CENTER);
|
||||||
|
|
||||||
|
// Write out the workbook
|
||||||
FileOutputStream fileOut = new FileOutputStream( "workbook.xls" );
|
FileOutputStream fileOut = new FileOutputStream( "workbook.xls" );
|
||||||
wb.write( fileOut );
|
wb.write( fileOut );
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user