本文整理汇总了C#中ICellStyle类的典型用法代码示例。如果您正苦于以下问题:C# ICellStyle类的具体用法?C# ICellStyle怎么用?C# ICellStyle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICellStyle类属于命名空间,在下文中一共展示了ICellStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertCell
private static int InsertCell(IRow row, int cellIndex, string value, ICellStyle cellStyle)
{
var cell = row.CreateCell(cellIndex);
cell.SetCellValue(value);
cell.CellStyle = cellStyle;
cellIndex++;
return cellIndex;
}
示例2: columnMerge
internal static void columnMerge(ISheet sheet, ICellStyle cellStyle, int row, int startColumn, int endColumn)
{
sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(row, row, startColumn, endColumn));
cellStyle.BorderBottom = BorderStyle.Thin;
cellStyle.BorderTop = BorderStyle.Thin;
cellStyle.BorderLeft = BorderStyle.Thin;
cellStyle.BorderRight = BorderStyle.Thin;
}
示例3: ValidationAdder
public ValidationAdder(ISheet fSheet, ICellStyle style_1, ICellStyle style_2,
ICellStyle cellStyle, int validationType)
{
_sheet = fSheet;
_style_1 = style_1;
_style_2 = style_2;
_cellStyle = cellStyle;
_validationType = validationType;
_currentRowIndex = fSheet.PhysicalNumberOfRows;
}
示例4: Resolve
/// <summary>
/// 解析为Npoi单元格样式
/// </summary>
public ICellStyle Resolve() {
_result = _workbook.CreateCellStyle();
_result.Alignment = GetHorizontalAlignment();
_result.VerticalAlignment = GetVerticalAlignment();
SetBackgroundColor();
SetFillPattern();
SetBorderColor();
SetFont();
_result.WrapText = _style.IsWrap;
return _result;
}
示例5: AttachedCellStyle
public static void AttachedCellStyle(this IWorkbook owner, string propertyName, ICellStyle value)
{
Dictionary<string, ICellStyle> values;
if (!_table.TryGetValue(owner, out values))
{
values = new Dictionary<string, ICellStyle>();
_table.Add(owner, values);
}
values[propertyName] = value;
}
示例6: WriteCell
protected ICell WriteCell(IRow row, int column, Action<ICell> setValue, ICellStyle style = null)
{
var cell = row.CreateCell(column);
setValue(cell);
if (style != null)
{
cell.CellStyle = style;
}
return cell;
}
示例7: SetStyle
public void SetStyle(
int hauteur,
int longeur,
int beginHauteurCadre,
int beginLongeurCadre,
int hauteurCadre,
int longeurCadre,
ICellStyle style,
bool forcedRightBorder)
{
if (hauteur == beginHauteurCadre && longeur == beginLongeurCadre)
{
SetLeftTopCornerStyle(style);
}
else if (hauteur == beginHauteurCadre && longeur == longeurCadre)
{
SetRightTopCornerStyle(style);
}
else if (hauteur == beginHauteurCadre)
{
SetOnlyTopStyle(style);
}
else if (hauteur == hauteurCadre && longeur == beginLongeurCadre)
{
SetBottomLeftCornerStyle(style);
}
else if (hauteur == hauteurCadre && longeur == longeurCadre)
{
SetBottomRightCornerStyle(style);
}
else if (hauteur == hauteurCadre)
{
SetOnlyBottomStyle(style);
}
else if (longeur == beginLongeurCadre)
{
SetOnlyLeftStyle(style);
}
else if (longeur == longeurCadre)
{
SetOnlyRightStyle(style);
}
if (forcedRightBorder)
{
style.BorderRight = _tailleBorder;
}
else
{
style.BorderRight = style.BorderRight;
}
}
示例8: CreateRowCell
public IRow CreateRowCell(ISheet sheet, int rowIdx, int fromColIdx, int toColIdx, ICellStyle cellStyle)
{
IRow row = sheet.CreateRow(rowIdx);
for (int i = fromColIdx; i <= toColIdx; i++)
{
ICell cell = row.CreateCell(i);
if (cellStyle != null)
{
cell.CellStyle = cellStyle;
}
}
return row;
}
示例9: ApplyStyle
/// <summary>
/// Applies the style by copying the fluent style to the NPOI style object,.
/// </summary>
/// <param name="workbook">The workbook.</param>
/// <param name="destination">The destination NPOI style object to apply the FluentStyle to.</param>
public void ApplyStyle(IWorkbook workbook, ICellStyle destination)
{
// If users sets format string this overrides the DataFormat property.
if (Format != null)
{
var dataFormat = workbook.CreateDataFormat();
DataFormat = dataFormat.GetFormat(Format);
}
if (Alignment != null) destination.Alignment = Alignment.Value;
if (BorderBottom != null) destination.BorderBottom = BorderBottom.Value;
if (BorderDiagonal != null) destination.BorderDiagonal = BorderDiagonal.Value;
if (BorderDiagonalColor != null) destination.BorderDiagonalColor = BorderDiagonalColor.Value;
if (BorderDiagonalLineStyle != null) destination.BorderDiagonalLineStyle = BorderDiagonalLineStyle.Value;
if (BorderLeft != null) destination.BorderLeft = BorderLeft.Value;
if (BorderRight != null) destination.BorderRight = BorderRight.Value;
if (BorderTop != null) destination.BorderTop = BorderTop.Value;
if (BottomBorderColor != null) destination.BottomBorderColor = BottomBorderColor.Value;
if (DataFormat != null) destination.DataFormat = DataFormat.Value;
if (FillBackgroundColor != null) destination.FillBackgroundColor = FillBackgroundColor.Value;
if (FillForegroundColor != null) destination.FillForegroundColor = FillForegroundColor.Value;
if (FillPattern != null) destination.FillPattern = FillPattern.Value;
if (Indention != null) destination.Indention = Indention.Value;
if (LeftBorderColor != null) destination.LeftBorderColor = LeftBorderColor.Value;
if (RightBorderColor != null) destination.RightBorderColor = RightBorderColor.Value;
if (Rotation != null) destination.Rotation = Rotation.Value;
if (ShrinkToFit != null) destination.ShrinkToFit = ShrinkToFit.Value;
if (TopBorderColor != null) destination.TopBorderColor = TopBorderColor.Value;
if (VerticalAlignment != null) destination.VerticalAlignment = VerticalAlignment.Value;
if (WrapText != null) destination.WrapText = WrapText.Value;
if (FontIsNeeded)
{
var font = workbook.CreateFont();
if (FontWeight != null) font.Boldweight = (short)FontWeight.Value;
if (Charset != null) font.Charset = Charset.Value;
if (Color != null) font.Color = Color.Value;
if (FontHeight != null) font.FontHeight = FontHeight.Value;
if (FontHeightInPoints != null) font.FontHeightInPoints = FontHeightInPoints.Value;
if (FontName != null) font.FontName = FontName;
if (Italic != null) font.IsItalic = Italic.Value;
if (Strikeout != null) font.IsStrikeout = Strikeout.Value;
if (SuperScript != null) font.TypeOffset = SuperScript.Value;
if (Underline != null) font.Underline = Underline.Value;
destination.SetFont(font);
}
}
示例10: SetCellStyle
public void SetCellStyle(ICell cell, ICellStyle npoiCellStyle)
{
CellStyleWrapper cellStyle = new CellStyleWrapper(npoiCellStyle);
string cellStyleKey = cellStyle.GetKey();
if (cellStyles.ContainsKey(cellStyleKey)) {
// reuse cached styles
CellStyleWrapper cachedCellStyle = cellStyles[cellStyleKey];
cell.CellStyle = cachedCellStyle.CellStyle;
} else {
// If the style does not exist create a new one
ICellStyle newCellStyle = xlWorkbook.CreateCellStyle();
CopyCellStyle(xlWorkbook, npoiCellStyle, newCellStyle);
Add(new CellStyleWrapper(newCellStyle));
cell.CellStyle = newCellStyle;
}
}
示例11: CopyCellStyle
/// <summary>
/// Copy c1 into c2
/// </summary>
public static void CopyCellStyle(IWorkbook wb, ICellStyle c1, ICellStyle c2)
{
c2.Alignment = c1.Alignment;
c2.BorderBottom = c1.BorderBottom;
c2.BorderLeft = c1.BorderLeft;
c2.BorderRight = c1.BorderRight;
c2.BorderTop = c1.BorderTop;
c2.BottomBorderColor = c1.BottomBorderColor;
c2.DataFormat = c1.DataFormat;
c2.FillBackgroundColor = c1.FillBackgroundColor;
c2.FillForegroundColor = c1.FillForegroundColor;
c2.FillPattern = c1.FillPattern;
c2.SetFont(wb.GetFontAt(c1.FontIndex));
// HIDDEN ?
c2.Indention = c1.Indention;
c2.LeftBorderColor = c1.LeftBorderColor;
// LOCKED ?
c2.RightBorderColor = c1.RightBorderColor;
c2.Rotation = c1.Rotation;
c2.TopBorderColor = c1.TopBorderColor;
c2.VerticalAlignment = c1.VerticalAlignment;
c2.WrapText = c1.WrapText;
}
示例12: GetStyleWithFormat
internal ICellStyle GetStyleWithFormat(ICellStyle baseStyle, string dataFormat)
{
ICellStyle newStyle = CreateCellStyle();
newStyle.CloneStyleFrom(baseStyle);
if (StringMethods.IsNullOrWhiteSpace(dataFormat))
return newStyle;
// check if this is a built-in format
var builtinFormatId = GetBuiltIndDataFormat(dataFormat);
if (builtinFormatId != -1)
{
newStyle.DataFormat = builtinFormatId;
}
else
{
// not a built-in format, so create a new one
var newDataFormat = CreateDataFormat();
newStyle.DataFormat = newDataFormat.GetFormat(dataFormat);
}
return newStyle;
}
示例13: CloneStyleFrom
/**
* Clones all the style information from another
* XSSFCellStyle, onto this one. This
* XSSFCellStyle will then have all the same
* properties as the source, but the two may
* be edited independently.
* Any stylings on this XSSFCellStyle will be lost!
*
* The source XSSFCellStyle could be from another
* XSSFWorkbook if you like. This allows you to
* copy styles from one XSSFWorkbook to another.
*/
public void CloneStyleFrom(ICellStyle source)
{
if (source is XSSFCellStyle)
{
XSSFCellStyle src = (XSSFCellStyle)source;
// Is it on our Workbook?
if (src._stylesSource == _stylesSource)
{
// Nice and easy
_cellXf = src.GetCoreXf();
_cellStyleXf = src.GetStyleXf();
}
else
{
// Copy the style
try
{
// Remove any children off the current style, to
// avoid orphaned nodes
if (_cellXf.IsSetAlignment())
_cellXf.UnsetAlignment();
if (_cellXf.IsSetExtLst())
_cellXf.UnsetExtLst();
// Create a new Xf with the same contents
_cellXf =
src.GetCoreXf().Copy();
// Swap it over
_stylesSource.ReplaceCellXfAt(_cellXfId, _cellXf);
}
catch (XmlException e)
{
throw new POIXMLException(e);
}
// Copy the format
String fmt = src.GetDataFormatString();
DataFormat=(
(new XSSFDataFormat(_stylesSource)).GetFormat(fmt)
);
// Copy the font
try
{
CT_Font ctFont =
src.GetFont().GetCTFont().Clone();
XSSFFont font = new XSSFFont(ctFont);
font.RegisterTo(_stylesSource);
SetFont(font);
}
catch (XmlException e)
{
throw new POIXMLException(e);
}
}
// Clear out cached details
_font = null;
_cellAlignment = null;
}
else
{
throw new ArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
}
}
示例14: CellStyleCache
public CellStyleCache(IWorkbook xlWorkbook)
{
this.xlWorkbook = xlWorkbook;
this.cellStyles = new Dictionary<string, CellStyleWrapper>();
this.cellStyle = xlWorkbook.CreateCellStyle();
this.defaultCellStyle = xlWorkbook.CreateCellStyle();
}
示例15: CreateStyle
private static void CreateStyle(XSSFWorkbook workbook)
{
//获取字体
_normalFont = GetFontStyle(workbook, "宋体", null, 14);
_scoreFont = GetFontStyle(workbook, "宋体", _scoreColor, 24);
_winRateFont = GetFontStyle(workbook, "宋体", _winRateColor, 14);
//获取样式
_normalLeftCellStyle = GetCellStyle(workbook, _normalFont, null, FillPattern.NoFill, null, HorizontalAlignment.Left, VerticalAlignment.Center);
_normalCenterCellStyle = GetCellStyle(workbook, _normalFont, null, FillPattern.NoFill, null, HorizontalAlignment.Center, VerticalAlignment.Center);
_aquaCellStyle = GetCellStyle(workbook, _normalFont, _bgColor1, FillPattern.SolidForeground, null, HorizontalAlignment.Left, VerticalAlignment.Center);
_greycellStyle = GetCellStyle(workbook, _normalFont, _bgColor2, FillPattern.SolidForeground, null, HorizontalAlignment.Center, VerticalAlignment.Center);
}