/** * * org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt to * org.openxmlformats.schemas.drawingml.x2006.main.CTFont adapter */ private static void ApplyAttributes(CT_RPrElt pr, CT_TextCharacterProperties rPr) { if (pr.sizeOfBArray() > 0) { rPr.b = (pr.GetBArray(0).val); } if (pr.sizeOfUArray() > 0) { ST_UnderlineValues u1 = pr.GetUArray(0).val; if (u1 == ST_UnderlineValues.single) { rPr.u = (ST_TextUnderlineType.sng); } else if (u1 == ST_UnderlineValues.@double) { rPr.u = (ST_TextUnderlineType.dbl); } else if (u1 == ST_UnderlineValues.none) { rPr.u = (ST_TextUnderlineType.none); } } if (pr.sizeOfIArray() > 0) { rPr.i = (pr.GetIArray(0).val); } if (pr.sizeOfFamilyArray() > 0) { CT_TextFont rFont = rPr.AddNewLatin(); rFont.typeface = (pr.GetRFontArray(0).val); } if (pr.sizeOfSzArray() > 0) { int sz = (int)(pr.GetSzArray(0).val * 100); rPr.sz = (sz); } if (pr.sizeOfColorArray() > 0) { CT_SolidColorFillProperties fill = rPr.IsSetSolidFill() ? rPr.solidFill : rPr.AddNewSolidFill(); NPOI.OpenXmlFormats.Spreadsheet.CT_Color xlsColor = pr.GetColorArray(0); if (xlsColor.IsSetRgb()) { CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr(); clr.val = (xlsColor.rgb); } else if (xlsColor.IsSetIndexed()) { HSSFColor indexed = HSSFColor.GetIndexHash()[(int)xlsColor.indexed] as HSSFColor; if (indexed != null) { byte[] rgb = indexed.RGB; CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr(); clr.val = (rgb); } } } }
/** * * CTRPrElt --> CTFont adapter */ protected static CT_Font ToCTFont(CT_RPrElt pr) { CT_Font ctFont = new CT_Font(); if (pr.sizeOfBArray() > 0) { ctFont.AddNewB().val = (pr.GetBArray(0).val); } if (pr.sizeOfUArray() > 0) { ctFont.AddNewU().val = (pr.GetUArray(0).val); } if (pr.sizeOfIArray() > 0) { ctFont.AddNewI().val = (pr.GetIArray(0).val); } if (pr.sizeOfColorArray() > 0) { CT_Color c1 = pr.GetColorArray(0); CT_Color c2 = ctFont.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.GetRgb()); c2.rgbSpecified = true; } if (c1.IsSetTheme()) { c2.theme = (c1.theme); c2.themeSpecified = true; } if (c1.IsSetTint()) { c2.tint = (c1.tint); c2.tintSpecified = true; } } if (pr.sizeOfSzArray() > 0) { ctFont.AddNewSz().val = (pr.GetSzArray(0).val); } if (pr.sizeOfRFontArray() > 0) { ctFont.AddNewName().val = (pr.GetRFontArray(0).val); } if (pr.sizeOfFamilyArray() > 0) { ctFont.AddNewFamily().val = (pr.GetFamilyArray(0).val); } if (pr.sizeOfSchemeArray() > 0) { ctFont.AddNewScheme().val = (pr.GetSchemeArray(0).val); } if (pr.sizeOfCharsetArray() > 0) { ctFont.AddNewCharset().val = (pr.GetCharsetArray(0).val); } if (pr.sizeOfCondenseArray() > 0) { ctFont.AddNewCondense().val = (pr.GetCondenseArray(0).val); } if (pr.sizeOfExtendArray() > 0) { ctFont.AddNewExtend().val = (pr.GetExtendArray(0).val); } if (pr.sizeOfVertAlignArray() > 0) { ctFont.AddNewVertAlign().val = (pr.GetVertAlignArray(0).val); } if (pr.sizeOfOutlineArray() > 0) { ctFont.AddNewOutline().val = (pr.GetOutlineArray(0).val); } if (pr.sizeOfShadowArray() > 0) { ctFont.AddNewShadow().val = (pr.GetShadowArray(0).val); } if (pr.sizeOfStrikeArray() > 0) { ctFont.AddNewStrike().val = (pr.GetStrikeArray(0).val); } return(ctFont); }
private static void ApplyAttributes(CT_RPrElt pr, CT_TextCharacterProperties rPr) { if (pr.sizeOfBArray() > 0) { rPr.b = pr.GetBArray(0).val; } if (pr.sizeOfUArray() > 0) { switch (pr.GetUArray(0).val) { case ST_UnderlineValues.none: rPr.u = ST_TextUnderlineType.none; break; case ST_UnderlineValues.single: rPr.u = ST_TextUnderlineType.sng; break; case ST_UnderlineValues.@double: rPr.u = ST_TextUnderlineType.dbl; break; } } if (pr.sizeOfIArray() > 0) { rPr.i = pr.GetIArray(0).val; } if (pr.sizeOfFamilyArray() > 0) { rPr.AddNewLatin().typeface = pr.GetRFontArray(0).val; } if (pr.sizeOfSzArray() > 0) { int num = (int)(pr.GetSzArray(0).val * 100.0); rPr.sz = num; } if (pr.sizeOfColorArray() <= 0) { return; } CT_SolidColorFillProperties colorFillProperties = rPr.IsSetSolidFill() ? rPr.solidFill : rPr.AddNewSolidFill(); NPOI.OpenXmlFormats.Spreadsheet.CT_Color colorArray = pr.GetColorArray(0); if (colorArray.IsSetRgb()) { (colorFillProperties.IsSetSrgbClr() ? colorFillProperties.srgbClr : colorFillProperties.AddNewSrgbClr()).val = colorArray.rgb; } else { if (!colorArray.IsSetIndexed()) { return; } HSSFColor hssfColor = HSSFColor.GetIndexHash()[(object)(int)colorArray.indexed] as HSSFColor; if (hssfColor == null) { return; } byte[] numArray = new byte[3] { (byte)hssfColor.GetTriplet()[0], (byte)hssfColor.GetTriplet()[1], (byte)hssfColor.GetTriplet()[2] }; (colorFillProperties.IsSetSrgbClr() ? colorFillProperties.srgbClr : colorFillProperties.AddNewSrgbClr()).val = numArray; } }