import org.apache.poi.hssf.usermodel.*;import java.io.FileOutputStream;
import java.io.IOException;/**
* Demonstrates how to create borders around cells.
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class Borders
{
public static void main(String[] args)
throws IOException
{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow((short) 1); // Create a cell and put a value in it.
HSSFCell cell = row.createCell((short) 1);
cell.setCellValue(4); // Style the cell with borders all around.
HSSFCellStyle style = wb.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFCellStyle.BLACK);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setLeftBorderColor(HSSFCellStyle.GREEN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setRightBorderColor(HSSFCellStyle.BLUE);
style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM_DASHED);
style.setTopBorderColor(HSSFCellStyle.AUTOMATIC);
cell.setCellStyle(style); // Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}
import java.io.IOException;/**
* Demonstrates how to create borders around cells.
*
* @author Glen Stampoultzis (glens at apache.org)
*/
public class Borders
{
public static void main(String[] args)
throws IOException
{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet"); // Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow((short) 1); // Create a cell and put a value in it.
HSSFCell cell = row.createCell((short) 1);
cell.setCellValue(4); // Style the cell with borders all around.
HSSFCellStyle style = wb.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFCellStyle.BLACK);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setLeftBorderColor(HSSFCellStyle.GREEN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setRightBorderColor(HSSFCellStyle.BLUE);
style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM_DASHED);
style.setTopBorderColor(HSSFCellStyle.AUTOMATIC);
cell.setCellStyle(style); // Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货