本文整理汇总了C#中NPOI.OpenXmlFormats.Spreadsheet.CT_Font类的典型用法代码示例。如果您正苦于以下问题:C# CT_Font类的具体用法?C# CT_Font怎么用?C# CT_Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CT_Font类属于NPOI.OpenXmlFormats.Spreadsheet命名空间,在下文中一共展示了CT_Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetFontArray
public void SetFontArray(CT_Font[] array)
{
if (array != null)
fontField = new List<CT_Font>(array);
else
fontField.Clear();
}
示例2: GetString
public static string GetString(CT_Font font)
{
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, font, namespaces);
return writer.ToString();
}
}
示例3: TestBoldweight
public void TestBoldweight()
{
CT_Font ctFont = new CT_Font();
CT_BooleanProperty bool1 = ctFont.AddNewB();
bool1.val = (false);
ctFont.SetBArray(0, bool1);
XSSFFont xssfFont = new XSSFFont(ctFont);
Assert.AreEqual(false, xssfFont.IsBold);
xssfFont.IsBold = (true);
Assert.AreEqual(ctFont.b.Count, 1);
Assert.AreEqual(true, ctFont.GetBArray(0).val);
}
示例4: Parse
public static CT_Font Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
if (node == null)
return null;
CT_Font ctObj = new CT_Font();
ctObj.name = new List<CT_FontName>();
ctObj.charset = new List<CT_IntProperty>();
ctObj.family = new List<CT_IntProperty>();
ctObj.b = new List<CT_BooleanProperty>();
ctObj.i = new List<CT_BooleanProperty>();
ctObj.strike = new List<CT_BooleanProperty>();
ctObj.color = new List<CT_Color>();
ctObj.sz = new List<CT_FontSize>();
ctObj.u = new List<CT_UnderlineProperty>();
ctObj.vertAlign = new List<CT_VerticalAlignFontProperty>();
ctObj.scheme = new List<CT_FontScheme>();
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == "outline")
ctObj.outline = CT_BooleanProperty.Parse(childNode, namespaceManager);
else if (childNode.LocalName == "shadow")
ctObj.shadow = CT_BooleanProperty.Parse(childNode, namespaceManager);
else if (childNode.LocalName == "condense")
ctObj.condense = CT_BooleanProperty.Parse(childNode, namespaceManager);
else if (childNode.LocalName == "extend")
ctObj.extend = CT_BooleanProperty.Parse(childNode, namespaceManager);
else if (childNode.LocalName == "name")
ctObj.name.Add(CT_FontName.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "charset")
ctObj.charset.Add(CT_IntProperty.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "family")
ctObj.family.Add(CT_IntProperty.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "b")
ctObj.b.Add(CT_BooleanProperty.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "i")
ctObj.i.Add(CT_BooleanProperty.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "strike")
ctObj.strike.Add(CT_BooleanProperty.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "color")
ctObj.color.Add(CT_Color.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "sz")
ctObj.sz.Add(CT_FontSize.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "u")
ctObj.u.Add(CT_UnderlineProperty.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "vertAlign")
ctObj.vertAlign.Add(CT_VerticalAlignFontProperty.Parse(childNode, namespaceManager));
else if (childNode.LocalName == "scheme")
ctObj.scheme.Add(CT_FontScheme.Parse(childNode, namespaceManager));
}
return ctObj;
}
示例5: TestCharSet
public void TestCharSet()
{
CT_Font ctFont = new CT_Font();
CT_IntProperty prop = ctFont.AddNewCharset();
prop.val = (FontCharset.ANSI.Value);
ctFont.SetCharsetArray(0, prop);
XSSFFont xssfFont = new XSSFFont(ctFont);
Assert.AreEqual(FontCharset.ANSI.Value, xssfFont.Charset);
xssfFont.SetCharSet(FontCharset.DEFAULT);
Assert.AreEqual(FontCharset.DEFAULT.Value, ctFont.GetCharsetArray(0).val);
// Try with a few less usual ones:
// Set with the Charset itself
xssfFont.SetCharSet(FontCharset.RUSSIAN);
Assert.AreEqual(FontCharset.RUSSIAN.Value, xssfFont.Charset);
// And Set with the Charset index
xssfFont.SetCharSet(FontCharset.ARABIC.Value);
Assert.AreEqual(FontCharset.ARABIC.Value, xssfFont.Charset);
// This one isn't allowed
Assert.AreEqual(null, FontCharset.ValueOf(9999));
try
{
xssfFont.SetCharSet(9999);
Assert.Fail("Shouldn't be able to Set an invalid charset");
}
catch (POIXMLException) { }
// Now try with a few sample files
// Normal charset
XSSFWorkbook workbook = XSSFTestDataSamples.OpenSampleWorkbook("Formatting.xlsx");
Assert.AreEqual(0,
((XSSFCellStyle)workbook.GetSheetAt(0).GetRow(0).GetCell(0).CellStyle).GetFont().Charset
);
// GB2312 charact Set
workbook = XSSFTestDataSamples.OpenSampleWorkbook("49273.xlsx");
Assert.AreEqual(134,
((XSSFCellStyle)workbook.GetSheetAt(0).GetRow(0).GetCell(0).CellStyle).GetFont().Charset
);
}
示例6: SetUp
public void SetUp()
{
stylesTable = new StylesTable();
ctStylesheet = stylesTable.GetCTStylesheet();
ctBorderA = new CT_Border();
XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
long borderId = stylesTable.PutBorder(borderA);
Assert.AreEqual(1, borderId);
XSSFCellBorder borderB = new XSSFCellBorder();
Assert.AreEqual(1, stylesTable.PutBorder(borderB));
ctFill = new CT_Fill();
XSSFCellFill fill = new XSSFCellFill(ctFill);
long fillId = stylesTable.PutFill(fill);
Assert.AreEqual(2, fillId);
ctFont = new CT_Font();
XSSFFont font = new XSSFFont(ctFont);
long fontId = stylesTable.PutFont(font);
Assert.AreEqual(1, fontId);
cellStyleXf = ctStylesheet.AddNewCellStyleXfs().AddNewXf();
cellStyleXf.borderId = 1;
cellStyleXf.fillId = 1;
cellStyleXf.fontId = 1;
cellXfs = ctStylesheet.AddNewCellXfs();
cellXf = cellXfs.AddNewXf();
cellXf.xfId = (1);
cellXf.borderId = (1);
cellXf.fillId = (1);
cellXf.fontId = (1);
stylesTable.PutCellStyleXf(cellStyleXf);
stylesTable.PutCellXf(cellXf);
cellStyle = new XSSFCellStyle(1, 1, stylesTable, null);
Assert.IsNotNull(stylesTable.GetFillAt(1).GetCTFill().patternFill);
Assert.AreEqual(ST_PatternType.darkGray, stylesTable.GetFillAt(1).GetCTFill().patternFill.patternType);
}
示例7: ParseTest
public void ParseTest()
{
string fontName = "Tahoma";
CT_Font expected = new CT_Font();
var name = expected.AddNewName();
name.val = fontName;
var b = expected.AddNewB();
b.val = true;
string firstXml = CT_Font.GetString(expected);
CT_Font actual = CT_Font.Parse(firstXml);
string secondXml = CT_Font.GetString(actual);
Assert.AreEqual(firstXml, secondXml);
Assert.AreEqual(expected.name.val, actual.name.val);
Assert.AreEqual(fontName, actual.name.val);
Assert.AreEqual(expected.nameSpecified, actual.nameSpecified);
Assert.AreEqual(expected.b.val, actual.b.val);
Assert.AreEqual(true, actual.b.val);
Assert.AreEqual(expected.bSpecified, actual.bSpecified);
Assert.AreEqual(expected.iSpecified, actual.iSpecified);
Assert.AreEqual(false, actual.iSpecified);
}
示例8: TestScheme
public void TestScheme()
{
CT_Font ctFont = new CT_Font();
CT_FontScheme scheme = ctFont.AddNewScheme();
scheme.val = (ST_FontScheme.major);
ctFont.SetSchemeArray(0, scheme);
XSSFFont font = new XSSFFont(ctFont);
Assert.AreEqual(FontScheme.MAJOR, font.GetScheme());
font.SetScheme(FontScheme.NONE);
Assert.AreEqual(ST_FontScheme.none, ctFont.GetSchemeArray(0).val);
}
示例9: TestTypeOffset
public void TestTypeOffset()
{
CT_Font ctFont = new CT_Font();
CT_VerticalAlignFontProperty valign = ctFont.AddNewVertAlign();
valign.val = (ST_VerticalAlignRun.baseline);
ctFont.SetVertAlignArray(0, valign);
XSSFFont font = new XSSFFont(ctFont);
Assert.AreEqual(FontSuperScript.None, font.TypeOffset);
font.TypeOffset = FontSuperScript.Super;
Assert.AreEqual(ST_VerticalAlignRun.superscript, ctFont.GetVertAlignArray(0).val);
}
示例10: TestThemeColor
public void TestThemeColor()
{
CT_Font ctFont = new CT_Font();
CT_Color color = ctFont.AddNewColor();
color.theme = (1);
color.themeSpecified = true;
ctFont.SetColorArray(0, color);
XSSFFont xssfFont = new XSSFFont(ctFont);
Assert.AreEqual((short)ctFont.GetColorArray(0).theme, xssfFont.GetThemeColor());
xssfFont.SetThemeColor(IndexedColors.Red.Index);
Assert.AreEqual((uint)IndexedColors.Red.Index, ctFont.GetColorArray(0).theme);
}
示例11: TestFamily
public void TestFamily()
{
CT_Font ctFont = new CT_Font();
CT_IntProperty family = ctFont.AddNewFamily();
family.val = (FontFamily.MODERN.Value);
ctFont.SetFamilyArray(0, family);
XSSFFont xssfFont = new XSSFFont(ctFont);
Assert.AreEqual(FontFamily.MODERN.Value, xssfFont.Family);
}
示例12: AddNewFont
public CT_Font AddNewFont()
{
CT_Font font = new CT_Font();
this.fontField = font;
return font;
}
示例13: XSSFFont
/**
* Create a new XSSFont. This method is protected to be used only by XSSFWorkbook
*/
public XSSFFont()
{
this._ctFont = new CT_Font();
FontName = DEFAULT_FONT_NAME;
FontHeight =DEFAULT_FONT_SIZE;
}
示例14: SetRunAttributes
/**
* Copy font attributes from CTFont bean into CTRPrElt bean
*/
private void SetRunAttributes(CT_Font ctFont, CT_RPrElt pr)
{
if (ctFont.SizeOfBArray() > 0) pr.AddNewB().val = (ctFont.GetBArray(0).val);
if (ctFont.sizeOfUArray() > 0) pr.AddNewU().val =(ctFont.GetUArray(0).val);
if (ctFont.sizeOfIArray() > 0) pr.AddNewI().val =(ctFont.GetIArray(0).val);
if (ctFont.sizeOfColorArray() > 0)
{
CT_Color c1 = ctFont.GetColorArray(0);
CT_Color c2 = pr.AddNewColor();
if (c1.IsSetAuto())
{
c2.auto = (c1.auto);
c2.autoSpecified = true;
}
if (c1.IsSetIndexed())
{
c2.indexed = (c1.indexed);
c2.indexedSpecified = true;
}
if (c1.IsSetRgb())
{
c2.SetRgb(c1.rgb);
c2.rgbSpecified = true;
}
if (c1.IsSetTheme())
{
c2.theme = (c1.theme);
c2.themeSpecified = true;
}
if (c1.IsSetTint())
{
c2.tint = (c1.tint);
c2.tintSpecified = true;
}
}
if (ctFont.sizeOfSzArray() > 0) pr.AddNewSz().val = (ctFont.GetSzArray(0).val);
if (ctFont.sizeOfNameArray() > 0) pr.AddNewRFont().val = (ctFont.name.val);
if (ctFont.sizeOfFamilyArray() > 0) pr.AddNewFamily().val =(ctFont.GetFamilyArray(0).val);
if (ctFont.sizeOfSchemeArray() > 0) pr.AddNewScheme().val = (ctFont.GetSchemeArray(0).val);
if (ctFont.sizeOfCharsetArray() > 0) pr.AddNewCharset().val = (ctFont.GetCharsetArray(0).val);
if (ctFont.sizeOfCondenseArray() > 0) pr.AddNewCondense().val = (ctFont.GetCondenseArray(0).val);
if (ctFont.sizeOfExtendArray() > 0) pr.AddNewExtend().val = (ctFont.GetExtendArray(0).val);
if (ctFont.sizeOfVertAlignArray() > 0) pr.AddNewVertAlign().val = (ctFont.GetVertAlignArray(0).val);
if (ctFont.sizeOfOutlineArray() > 0) pr.AddNewOutline().val =(ctFont.GetOutlineArray(0).val);
if (ctFont.sizeOfShadowArray() > 0) pr.AddNewShadow().val =(ctFont.GetShadowArray(0).val);
if (ctFont.sizeOfStrikeArray() > 0) pr.AddNewStrike().val = (ctFont.GetStrikeArray(0).val);
}
示例15: WriteTo
/**
* Write this table out as XML.
*
* @param out The stream to write to.
* @throws IOException if an error occurs while writing.
*/
public void WriteTo(Stream out1)
{
// Work on the current one
// Need to do this, as we don't handle
// all the possible entries yet
CT_Stylesheet styleSheet = doc.GetStyleSheet();
// Formats
CT_NumFmts ctFormats = new CT_NumFmts();
ctFormats.count = (uint)numberFormats.Count;
if (ctFormats.count > 0)
ctFormats.countSpecified = true;
foreach (KeyValuePair<int, String> fmt in numberFormats)
{
CT_NumFmt ctFmt = ctFormats.AddNewNumFmt();
ctFmt.numFmtId = (uint)fmt.Key;
ctFmt.formatCode = fmt.Value;
}
styleSheet.numFmts = (ctFormats);
int idx;
// Fonts
CT_Fonts ctFonts = new CT_Fonts();
ctFonts.count = (uint)fonts.Count;
if (ctFonts.count > 0)
ctFonts.countSpecified = true;
CT_Font[] ctfnt = new CT_Font[fonts.Count];
idx = 0;
foreach (XSSFFont f in fonts)
ctfnt[idx++] = f.GetCTFont();
ctFonts.SetFontArray(ctfnt);
styleSheet.fonts = (ctFonts);
// Fills
var ctf = new List<CT_Fill>(fills.Count);
foreach (XSSFCellFill f in fills)
ctf.Add( f.GetCTFill());
CT_Fills ctFills = new CT_Fills();
ctFills.SetFillArray(ctf);
ctFills.count = (uint)fills.Count;
if (ctFills.count > 0)
ctFills.countSpecified = true;
styleSheet.fills = ctFills;
// Borders
List<CT_Border> ctb = new List<CT_Border>(borders.Count);
idx = 0;
foreach (XSSFCellBorder b in borders)
ctb.Add(b.GetCTBorder());
CT_Borders ctBorders = new CT_Borders();
ctBorders.SetBorderArray(ctb);
ctBorders.count = (uint)ctb.Count;
if (ctBorders.count > 0)
ctBorders.countSpecified = true;
styleSheet.borders = ctBorders;
// Xfs
if (xfs.Count > 0)
{
CT_CellXfs ctXfs = new CT_CellXfs();
ctXfs.count = (uint)xfs.Count;
if (ctXfs.count > 0)
ctXfs.countSpecified = true;
ctXfs.xf = xfs;
styleSheet.cellXfs = (ctXfs);
}
// Style xfs
if (styleXfs.Count > 0)
{
CT_CellStyleXfs ctSXfs = new CT_CellStyleXfs();
ctSXfs.count = (uint)(styleXfs.Count);
if (ctSXfs.count > 0)
ctSXfs.countSpecified = true;
ctSXfs.xf = styleXfs;
styleSheet.cellStyleXfs = (ctSXfs);
}
// Style dxfs
if (dxfs.Count > 0)
{
CT_Dxfs ctDxfs = new CT_Dxfs();
ctDxfs.count = (uint)dxfs.Count;
if (ctDxfs.count > 0)
ctDxfs.countSpecified = true;
ctDxfs.dxf = dxfs;
styleSheet.dxfs = (ctDxfs);
}
// Save
//.........这里部分代码省略.........