public void ApplyFont(int startIndex, int endIndex, IFont font)
        {
            if (startIndex > endIndex)
            {
                throw new ArgumentException("Start index must be less than end index.");
            }
            if (startIndex < 0 || endIndex > this.Length)
            {
                throw new ArgumentException("Start and end index not in range.");
            }
            if (startIndex == endIndex)
            {
                return;
            }
            if (this.st.sizeOfRArray() == 0 && this.st.IsSetT())
            {
                this.st.AddNewR().t = this.st.t;
                this.st.unsetT();
            }
            string   text     = this.String;
            XSSFFont xssfFont = (XSSFFont)font;
            SortedDictionary <int, CT_RPrElt> formatMap = this.GetFormatMap(this.st);
            CT_RPrElt ctRprElt = new CT_RPrElt();

            this.SetRunAttributes(xssfFont.GetCTFont(), ctRprElt);
            this.ApplyFont(formatMap, startIndex, endIndex, ctRprElt);
            this.st.Set(this.buildCTRst(text, formatMap));
        }
Exemple #2
0
        /**
         * Applies a font to the specified characters of a string.
         *
         * @param startIndex    The start index to apply the font to (inclusive)
         * @param endIndex      The end index to apply to font to (exclusive)
         * @param font          The index of the font to use.
         */
        public void ApplyFont(int startIndex, int endIndex, IFont font)
        {
            if (startIndex > endIndex)
            {
                throw new ArgumentException("Start index must be less than end index, but had " + startIndex + " and " + endIndex);
            }
            if (startIndex < 0 || endIndex > Length)
            {
                throw new ArgumentException("Start and end index not in range, but had " + startIndex + " and " + endIndex);
            }
            if (startIndex == endIndex)
            {
                return;
            }

            if (st.sizeOfRArray() == 0 && st.IsSetT())
            {
                //convert <t>string</t> into a text Run: <r><t>string</t></r>
                st.AddNewR().t = (st.t);
                st.unsetT();
            }

            String   text     = this.String;
            XSSFFont xssfFont = (XSSFFont)font;

            SortedDictionary <int, CT_RPrElt> formats = GetFormatMap(st);
            CT_RPrElt fmt = new CT_RPrElt();

            SetRunAttributes(xssfFont.GetCTFont(), fmt);
            ApplyFont(formats, startIndex, endIndex, fmt);

            CT_Rst newSt = buildCTRst(text, formats);

            st.Set(newSt);
        }
Exemple #3
0
        public override bool Equals(Object o)
        {
            if (!(o is XSSFFont))
            {
                return(false);
            }

            XSSFFont cf = (XSSFFont)o;

            return(_ctFont.ToString().Equals(cf.GetCTFont().ToString()));
        }
Exemple #4
0
        private void SaveAndReloadReport(IWorkbook wb, FileInfo outFile)
        {
            // run some method on the font to verify if it is "disconnected" already
            //for(short i = 0;i < 256;i++)
            {
                IFont font = wb.GetFontAt((short)0);
                if (font is XSSFFont)
                {
                    XSSFFont xfont  = (XSSFFont)wb.GetFontAt((short)0);
                    CT_Font  ctFont = (CT_Font)xfont.GetCTFont();
                    Assert.AreEqual(0, ctFont.sizeOfBArray());
                }
            }

            FileStream fileOutStream = new FileStream(outFile.FullName, FileMode.Truncate, FileAccess.ReadWrite);

            wb.Write(fileOutStream);
            fileOutStream.Close();
            //Console.WriteLine("File \""+outFile.GetName()+"\" has been saved successfully");

            Stream is1 = new FileStream(outFile.FullName, FileMode.Truncate, FileAccess.ReadWrite);

            try
            {
                IWorkbook newWB;
                if (wb is XSSFWorkbook)
                {
                    newWB = new XSSFWorkbook(is1);
                }
                else if (wb is HSSFWorkbook)
                {
                    newWB = new HSSFWorkbook(is1);
                    //} else if(wb is SXSSFWorkbook) {
                    //    newWB = new SXSSFWorkbook(new XSSFWorkbook(is1));
                }
                else
                {
                    throw new InvalidOperationException("Unknown workbook: " + wb);
                }
                Assert.IsNotNull(newWB.GetSheet("test"));
            }
            finally
            {
                is1.Close();
            }
        }
        /**
         * Append new text to this text run and apply the specify font to it
         *
         * @param text  the text to append
         * @param font  the font to apply to the Appended text or <code>null</code> if no formatting is required
         */
        public void Append(String text, XSSFFont font)
        {
            if (st.sizeOfRArray() == 0 && st.IsSetT())
            {
                //convert <t>string</t> into a text Run: <r><t>string</t></r>
                st.AddNewR().t = st.t;
                st.unsetT();
            }
            CT_RElt lt = st.AddNewR();

            lt.t = (text);
            CT_RPrElt pr = lt.AddNewRPr();

            if (font != null)
            {
                SetRunAttributes(font.GetCTFont(), pr);
            }
        }
        public void Append(string text, XSSFFont font)
        {
            if (this.st.sizeOfRArray() == 0 && this.st.IsSetT())
            {
                CT_RElt ctRelt = this.st.AddNewR();
                ctRelt.t = this.st.t;
                XSSFRichTextString.PreserveSpaces(ctRelt.t);
                this.st.unsetT();
            }
            CT_RElt ctRelt1 = this.st.AddNewR();

            ctRelt1.t = text;
            XSSFRichTextString.PreserveSpaces(ctRelt1.t);
            CT_RPrElt pr = ctRelt1.AddNewRPr();

            if (font == null)
            {
                return;
            }
            this.SetRunAttributes(font.GetCTFont(), pr);
        }
Exemple #7
0
 public void SetStylesTableReference(StylesTable stylestable)
 {
     this.styles = stylestable;
     if (st.sizeOfRArray() > 0)
     {
         foreach (CT_RElt r in st.r)
         {
             CT_RPrElt pr = r.rPr;
             if (pr != null && pr.SizeOfRFontArray() > 0)
             {
                 String fontName = pr.GetRFontArray(0).val;
                 if (fontName.StartsWith("#"))
                 {
                     int      idx  = int.Parse(fontName.Substring(1));
                     XSSFFont font = styles.GetFontAt(idx);
                     pr.rFont = null;
                     SetRunAttributes(font.GetCTFont(), pr);
                 }
             }
         }
     }
 }
 public void SetStylesTableReference(StylesTable stylestable)
 {
     this.styles = stylestable;
     if (this.st.sizeOfRArray() <= 0)
     {
         return;
     }
     foreach (CT_RElt ctRelt in this.st.r)
     {
         CT_RPrElt rPr = ctRelt.rPr;
         if (rPr != null && rPr.sizeOfRFontArray() > 0)
         {
             string val = rPr.GetRFontArray(0).val;
             if (val.StartsWith("#"))
             {
                 XSSFFont fontAt = this.styles.GetFontAt(int.Parse(val.Substring(1)));
                 rPr.rFont = (CT_FontName)null;
                 this.SetRunAttributes(fontAt.GetCTFont(), rPr);
             }
         }
     }
 }
Exemple #9
0
 /**
  * Append new text to this text run and apply the specify font to it
  *
  * @param text  the text to append
  * @param font  the font to apply to the Appended text or <code>null</code> if no formatting is required
  */
 public void Append(String text, XSSFFont font)
 {
     if (st.sizeOfRArray() == 0 && st.IsSetT())
     {
         //convert <t>string</t> into a text Run: <r><t>string</t></r>
         CT_RElt lt = st.AddNewR();
         lt.t = st.t;
         PreserveSpaces(lt.t);
         st.unsetT();
     }
     CT_RElt lt2 = st.AddNewR();
     lt2.t= (text);
     PreserveSpaces(lt2.t);
     CT_RPrElt pr = lt2.AddNewRPr();
     if (font != null) SetRunAttributes(font.GetCTFont(), pr);
 }
Exemple #10
0
 public void TestConstructor()
 {
     XSSFFont xssfFont = new XSSFFont();
     Assert.IsNotNull(xssfFont.GetCTFont());
 }
Exemple #11
0
        public void TestConstructor()
        {
            XSSFFont xssfFont = new XSSFFont();

            Assert.IsNotNull(xssfFont.GetCTFont());
        }