本文整理汇总了C#中IWorkbook.CreateCellStyle方法的典型用法代码示例。如果您正苦于以下问题:C# IWorkbook.CreateCellStyle方法的具体用法?C# IWorkbook.CreateCellStyle怎么用?C# IWorkbook.CreateCellStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWorkbook
的用法示例。
在下文中一共展示了IWorkbook.CreateCellStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CellStyleCache
public CellStyleCache(IWorkbook xlWorkbook)
{
this.xlWorkbook = xlWorkbook;
this.cellStyles = new Dictionary<string, CellStyleWrapper>();
this.cellStyle = xlWorkbook.CreateCellStyle();
this.defaultCellStyle = xlWorkbook.CreateCellStyle();
}
示例2: BetListExcelBuilder
/// <summary>
/// Initializes a new instance of the <see cref="BetListExcelBuilder" /> class.
/// </summary>
public BetListExcelBuilder()
{
_workbook = new HSSFWorkbook();
_isDisposed = false;
OddCellStyle = _workbook.CreateCellStyle();
EvenCellStyle = _workbook.CreateCellStyle();
OddCellStyleCenterAligned = _workbook.CreateCellStyle();
EvenCellStyleCenterAligned = _workbook.CreateCellStyle();
_nextCellIndex = -1;
RTFHelper = new RTFHelper()
{
NegFont = _workbook.CreateFont(),
NormalFont = _workbook.CreateFont(),
PosFont = _workbook.CreateFont(),
NegFontCrossed = _workbook.CreateFont(),
NormalFontCrossed = _workbook.CreateFont(),
PosFontCrossed = _workbook.CreateFont(),
RTFRenderer = new RtfTextRender()
};
InitDefaultRTFHelper();
InitDefaultCellStyles();
}
示例3: InitCellStyle
public void InitCellStyle(IWorkbook workbook)
{
var font = workbook.CreateFont();
var title = workbook.CreateCellStyle();
var content = workbook.CreateCellStyle();
RegisterFont(font);
RegisterTitleStyle(workbook, title);
RegisterContentStyle(workbook, content);
}
示例4: RegisterCustomStyle
public override void RegisterCustomStyle(IWorkbook workbook)
{
var format = workbook.CreateDataFormat();
ICellStyle cellStyle = workbook.CreateCellStyle();
RegisterContentStyle(workbook, cellStyle);
cellStyle.DataFormat = format.GetFormat("0.00%");
ICellStyle cellStyle2 = workbook.CreateCellStyle();
RegisterContentStyle(workbook, cellStyle2);
cellStyle2.DataFormat = format.GetFormat("¥0.00");
}
示例5: CreateCell
internal static ICell CreateCell(IWorkbook workbook, IRow row, int column, decimal? content, bool isCentered)
{
ICellStyle style = workbook.CreateCellStyle();
ICell cell = row.CreateCell(column);
if (content == null)
{
cell.SetCellValue("");
}
else
{
cell.SetCellValue(Convert.ToDouble(content.Value));
}
if (isCentered)
{
style.Alignment = HorizontalAlignment.Center;
}
style.BorderBottom = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
cell.CellStyle = style;
return cell;
}
示例6: WriteHeaderRow
static void WriteHeaderRow(IWorkbook wb, ISheet sheet)
{
sheet.SetColumnWidth(0, 6000);
sheet.SetColumnWidth(1, 6000);
sheet.SetColumnWidth(2, 3600);
sheet.SetColumnWidth(3, 3600);
sheet.SetColumnWidth(4, 2400);
sheet.SetColumnWidth(5, 2400);
sheet.SetColumnWidth(6, 2400);
sheet.SetColumnWidth(7, 2400);
sheet.SetColumnWidth(8, 2400);
IRow row = sheet.CreateRow(0);
ICellStyle style = wb.CreateCellStyle();
IFont font = wb.CreateFont();
font.Boldweight = (short)FontBoldWeight.BOLD;
style.SetFont(font);
WriteHeaderCell(row, 0, "Raw Long Bits A", style);
WriteHeaderCell(row, 1, "Raw Long Bits B", style);
WriteHeaderCell(row, 2, "Value A", style);
WriteHeaderCell(row, 3, "Value B", style);
WriteHeaderCell(row, 4, "Exp Cmp", style);
WriteHeaderCell(row, 5, "LT", style);
WriteHeaderCell(row, 6, "EQ", style);
WriteHeaderCell(row, 7, "GT", style);
WriteHeaderCell(row, 8, "Check", style);
}
示例7: GetBaseStyle
private ICellStyle GetBaseStyle(IWorkbook workbook)
{
var style = workbook.CreateCellStyle();
style.BorderBottom = style.BorderLeft = style.BorderRight = style.BorderTop = BorderStyle.Thin;
style.FillPattern = FillPattern.SolidForeground;
return style;
}
示例8: SetValueAndFormat
static void SetValueAndFormat(IWorkbook workbook, ICell cell, double value, short formatId)
{
cell.SetCellValue(value);
ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.DataFormat = formatId;
cell.CellStyle = cellStyle;
}
示例9: BorderAndFontSetting
private ICellStyle BorderAndFontSetting(IWorkbook wb, Tk5FieldInfoEx metaInfo, Model model)
{
ICellStyle cellStyle = wb.CreateCellStyle();
if (fUseBorder)
{
cellStyle.BorderTop = BorderStyle.Thin;
cellStyle.BorderRight = BorderStyle.Thin;
cellStyle.BorderBottom = BorderStyle.Thin;
cellStyle.BorderLeft = BorderStyle.Thin;
}
if (model == Model.Content)
{
IFont fontContent = ExcelUtil.FontSetting(wb, fContent);
cellStyle.SetFont(fontContent);
if (metaInfo.Extension != null)
{
ExcelUtil.AlignSetting(metaInfo.Extension.Align, cellStyle);
}
else
{
ExcelUtil.AlignSetting(fContent.Align, cellStyle);
}
}
else
{
ExcelUtil.AlignSetting(fHeader.Align, cellStyle);
IFont fontHeader = ExcelUtil.FontSetting(wb, fHeader);
cellStyle.SetFont(fontHeader);
}
return cellStyle;
}
示例10: CreateBoldStyle
private ICellStyle CreateBoldStyle(IWorkbook workbook)
{
var style = workbook.CreateCellStyle();
var font = workbook.CreateFont();
font.Boldweight = 1000;
style.SetFont(font);
return style;
}
示例11: GrayBackground
internal static void GrayBackground(IWorkbook workbook, ICell cell, bool isCentered)
{
ICellStyle style = workbook.CreateCellStyle();
style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
style.FillPattern = FillPattern.SolidForeground;
if (isCentered)
{
style.Alignment = HorizontalAlignment.Center;
}
style.BorderBottom = BorderStyle.Thin;
style.BorderTop = BorderStyle.Thin;
style.BorderLeft = BorderStyle.Thin;
style.BorderRight = BorderStyle.Thin;
cell.CellStyle = style;
}
示例12: CreateRowItem
private static void CreateRowItem(this ISheet target, IWorkbook workbook, DataTable dataSource)
{
IRow row = null;
ICell cell = null;
ICellStyle cellStyle = null;
IDrawing drawing = null;
IPicture picture = null;
cellStyle = workbook.CreateCellStyle();
cellStyle.Alignment = HorizontalAlignment.CENTER;
cellStyle.VerticalAlignment = VerticalAlignment.CENTER;
for (int rowIndex = 0; rowIndex < dataSource.Rows.Count; rowIndex++)
{
row = target.CreateRow(rowIndex + 1);
for (int columnIndex = 0; columnIndex < dataSource.Columns.Count; columnIndex++)
{
cell = row.CreateCell(columnIndex);
if (dataSource.Columns[columnIndex].DataType == typeof(byte[]))
{
byte[] image = dataSource.Rows[rowIndex][columnIndex] as byte[];
if (image != null && image.Length > 0)
{
int pictureIndex = workbook.AddPicture(dataSource.Rows[rowIndex][columnIndex] as byte[], PictureType.JPEG);
drawing = target.CreateDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, columnIndex, rowIndex + 1, columnIndex, rowIndex + 1);
picture = drawing.CreatePicture(anchor, pictureIndex);
picture.Resize();
}
}
else
{
cell.SetCellValue(dataSource.Rows[rowIndex][columnIndex].ToString());
}
cell.CellStyle = cellStyle;
}
}
}
示例13: GetCellStyle
/// <summary>
/// 创建表格头单元格
/// </summary>
/// <param name="sheet"></param>
/// <returns></returns>
public static ICellStyle GetCellStyle(IWorkbook workbook, bool isHeaderRow = false)
{
ICellStyle style = workbook.CreateCellStyle();
if (isHeaderRow)
{
style.FillPattern = FillPattern.SolidForeground;
style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
IFont f = workbook.CreateFont();
f.Boldweight = (short)FontBoldWeight.Bold;
style.SetFont(f);
}
style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
return style;
}
示例14: SetBorderStyle
public static void SetBorderStyle(IWorkbook workbook, IRow row, int columns)
{
row.Height = 14 * 30;
IFont font18 = workbook.CreateFont();
font18.FontName = "宋体";
font18.FontHeightInPoints = 10;
for (int i = 0; i < columns; i++)
{
ICellStyle style12 = workbook.CreateCellStyle();
style12.SetFont(font18);
//style12.Alignment = HorizontalAlignment.CENTER;
style12.VerticalAlignment = VerticalAlignment.CENTER;
style12.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
style12.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;
style12.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
style12.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;
row.GetCell(i).CellStyle = style12;
}
}
示例15: SetHeaderStyle
public static void SetHeaderStyle(IWorkbook workbook, IRow row, int columns)
{
row.Height = 16 * 30;
IFont font18 = workbook.CreateFont();
font18.FontName = "宋体";
font18.FontHeightInPoints = 12;
font18.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.BOLD;
for (int i = 0; i < columns; i++)
{
ICellStyle style12 = workbook.CreateCellStyle();
style12.SetFont(font18);
// style12.Alignment = HorizontalAlignment.CENTER;
style12.VerticalAlignment = VerticalAlignment.CENTER;
style12.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
style12.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;
style12.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
style12.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;
//style12.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index2;
row.GetCell(i).CellStyle = style12;
}
}