예제 #1
0
        /**
         * Prototype with the default structure of a new auto-shape.
         */
        protected internal static CT_Shape Prototype()
        {
            // in poi, method XmlObject set(XmlObject srcObj) will create a copy of XmlObject
            // so this prototype object would be newly set to shape object
            // but in .net, the prototype object will be modified and keep its contents, would
            // affect next usage. so comment the following code, and create a new prototype object
            // for every calling of Prototype().
            //if (prototype == null)
            {
                CT_Shape shape = new CT_Shape();

                CT_ShapeNonVisual nv = shape.AddNewNvSpPr();
                NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr();
                nvp.id   = (/*setter*/ 1);
                nvp.name = (/*setter*/ "Shape 1");
                nv.AddNewCNvSpPr();

                NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeProperties sp = shape.AddNewSpPr();
                CT_Transform2D    t2d = sp.AddNewXfrm();
                CT_PositiveSize2D p1  = t2d.AddNewExt();
                p1.cx = (/*setter*/ 0);
                p1.cy = (/*setter*/ 0);
                CT_Point2D p2 = t2d.AddNewOff();
                p2.x = (/*setter*/ 0);
                p2.y = (/*setter*/ 0);

                CT_PresetGeometry2D geom = sp.AddNewPrstGeom();
                geom.prst = (/*setter*/ ST_ShapeType.rect);
                geom.AddNewAvLst();

                NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody body = shape.AddNewTxBody();
                CT_TextBodyProperties bodypr = body.AddNewBodyPr();
                bodypr.anchor = (/*setter*/ ST_TextAnchoringType.t);
                bodypr.rtlCol = (/*setter*/ false);
                CT_TextParagraph p = body.AddNewP();
                p.AddNewPPr().algn = (/*setter*/ ST_TextAlignType.l);
                CT_TextCharacterProperties endPr = p.AddNewEndParaRPr();
                endPr.lang = (/*setter*/ "en-US");
                endPr.sz   = (/*setter*/ 1100);
                CT_SolidColorFillProperties scfpr = endPr.AddNewSolidFill();
                scfpr.AddNewSrgbClr().val         = (/*setter*/ new byte[] { 0, 0, 0 });

                body.AddNewLstStyle();

                prototype = shape;
            }
            return(prototype);
        }
예제 #2
0
        /**
         * Prototype with the default structure of a new auto-shape.
         */
        protected internal static CT_Shape GetPrototype()
        {
            if (prototype == null)
            {
                CT_Shape shape = new CT_Shape();

                CT_ShapeNonVisual nv = shape.AddNewNvSpPr();
                NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr();
                nvp.id   = (/*setter*/ 1);
                nvp.name = (/*setter*/ "Shape 1");
                nv.AddNewCNvSpPr();

                NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeProperties sp  = shape.AddNewSpPr();
                NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Transform2D     t2d = sp.AddNewXfrm();
                CT_PositiveSize2D p1 = t2d.AddNewExt();
                p1.cx = (/*setter*/ 0);
                p1.cy = (/*setter*/ 0);
                CT_Point2D p2 = t2d.AddNewOff();
                p2.x = (/*setter*/ 0);
                p2.y = (/*setter*/ 0);

                CT_PresetGeometry2D geom = sp.AddNewPrstGeom();
                geom.prst = (/*setter*/ ST_ShapeType.rect);
                geom.AddNewAvLst();

                NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody body = shape.AddNewTxBody();
                CT_TextBodyProperties bodypr = body.AddNewBodyPr();
                bodypr.anchor = (/*setter*/ ST_TextAnchoringType.t);
                bodypr.rtlCol = (/*setter*/ false);
                CT_TextParagraph p = body.AddNewP();
                p.AddNewPPr().algn = (/*setter*/ ST_TextAlignType.l);
                CT_TextCharacterProperties endPr = p.AddNewEndParaRPr();
                endPr.lang = (/*setter*/ "en-US");
                endPr.sz   = (/*setter*/ 1100);
                CT_SolidColorFillProperties scfpr = endPr.AddNewSolidFill();
                scfpr.AddNewSrgbClr().val         = (/*setter*/ new byte[] { 0, 0, 0 });

                body.AddNewLstStyle();

                prototype = shape;
            }
            return(prototype);
        }
예제 #3
0
        /**
         *
         * 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);
                    }
                }
            }
        }
예제 #4
0
        /**
         * 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 = (/*setter*/ pr.GetBArray(0).val);
            }
            if (pr.SizeOfUArray() > 0)
            {
                ST_UnderlineValues u1 = pr.GetUArray(0).val;
                if (u1 == ST_UnderlineValues.single)
                {
                    rPr.u = (/*setter*/ ST_TextUnderlineType.sng);
                }
                else if (u1 == ST_UnderlineValues.@double)
                {
                    rPr.u = (/*setter*/ ST_TextUnderlineType.dbl);
                }
                else if (u1 == ST_UnderlineValues.none)
                {
                    rPr.u = (/*setter*/ ST_TextUnderlineType.none);
                }
            }
            if (pr.SizeOfIArray() > 0)
            {
                rPr.i = (/*setter*/ pr.GetIArray(0).val);
            }

            if (pr.SizeOfRFontArray() > 0)
            {
                CT_TextFont rFont = rPr.IsSetLatin() ? rPr.latin : rPr.AddNewLatin();
                rFont.typeface = (/*setter*/ pr.GetRFontArray(0).val);
            }

            if (pr.SizeOfSzArray() > 0)
            {
                int sz = (int)(pr.GetSzArray(0).val * 100);
                rPr.sz = (/*setter*/ 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 = (/*setter*/ xlsColor.rgb);
                }
                else if (xlsColor.IsSetIndexed())
                {
                    HSSFColor indexed = (HSSFColor)HSSFColor.GetIndexHash()[((int)xlsColor.indexed)];
                    if (indexed != null)
                    {
                        byte[] rgb = new byte[3];
                        rgb[0] = (byte)indexed.GetTriplet()[0];
                        rgb[1] = (byte)indexed.GetTriplet()[1];
                        rgb[2] = (byte)indexed.GetTriplet()[2];
                        CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr();
                        clr.val = (/*setter*/ rgb);
                    }
                }
            }
        }
예제 #5
0
        public void SetFontColor(Color color)
        {
            CT_TextCharacterProperties  rPr  = GetRPr();
            CT_SolidColorFillProperties fill = rPr.IsSetSolidFill() ? rPr.solidFill : rPr.AddNewSolidFill();
            CT_SRgbColor clr = fill.IsSetSrgbClr() ? fill.srgbClr : fill.AddNewSrgbClr();

            clr.val = (new byte[] { color.R, color.G, color.B });

            if (fill.IsSetHslClr())
            {
                fill.UnsetHslClr();
            }
            if (fill.IsSetPrstClr())
            {
                fill.UnsetPrstClr();
            }
            if (fill.IsSetSchemeClr())
            {
                fill.UnsetSchemeClr();
            }
            if (fill.IsSetScrgbClr())
            {
                fill.UnsetScrgbClr();
            }
            if (fill.IsSetSysClr())
            {
                fill.UnsetSysClr();
            }
        }
예제 #6
0
        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;
            }
        }