您的位置:首页 > Web前端 > CSS

NPOI 1.2.3教程 -11 边框样式BorderStyle

2011-01-23 15:49 1951 查看
using System;
using System.Text;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.HPSF;
using NPOI.POIFS.FileSystem;
using NPOI.SS.UserModel;

namespace SetBorderStyleInXls
{
class Program
{
static void Main(string[] args)
{
InitializeWorkbook();

Sheet sheet = hssfworkbook.CreateSheet("new sheet");

// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.CreateRow(1);

// Create a cell and put a value in it.
Cell cell = row.CreateCell(1);
cell.SetCellValue(4);

// Style the cell with borders all around.
CellStyle style = hssfworkbook.CreateCellStyle();
style.BorderBottom= CellBorderType.THIN;
style.BottomBorderColor= HSSFColor.BLACK.index;
style.BorderLeft = CellBorderType.DASH_DOT_DOT;
style.LeftBorderColor= HSSFColor.GREEN.index;
style.BorderRight = CellBorderType.HAIR;
style.RightBorderColor= HSSFColor.BLUE.index;
style.BorderTop = CellBorderType.MEDIUM_DASHED;
style.TopBorderColor= HSSFColor.ORANGE.index;
cell.CellStyle= style;

WriteToFile();
}

static HSSFWorkbook hssfworkbook;

static void WriteToFile()
{
//Write the stream data of workbook to the root directory
FileStream file = new FileStream(@"test.xls", FileMode.Create);
hssfworkbook.Write(file);
file.Close();
}

static void InitializeWorkbook()
{
hssfworkbook = new HSSFWorkbook();

//Create a entry of DocumentSummaryInformation
DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "NPOI Team";
hssfworkbook.DocumentSummaryInformation = dsi;

//Create a entry of SummaryInformation
SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
si.Subject = "NPOI SDK Example";
hssfworkbook.SummaryInformation = si;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: