public User(IRichTextString _Username)
        {
            Can    = new PermissionsTesting_Can(this);
            Cannot = new PermissionsTesting_Cannot(this);

            UserName = _Username;
        }
Example #2
0
        public void ReadRowInSheet(IRow row)
        {
            heads = new List <ExcelHeadAttribute>();
            short cellIndex = row.LastCellNum;//总共多少列

            for (short i = 0; i < cellIndex; i++)
            {
                ICell cell = row.GetCell(i);
                if (cell == null)
                { //对于空列的处理
                    continue;
                }
                IRichTextString rtext = cell.RichStringCellValue;
                string          text  = rtext.String;
                //文本内容,列索引
                if (!string.IsNullOrEmpty(text))
                {
                    ExcelHeadAttribute head = new ExcelHeadAttribute()
                    {
                        ColumnIndex = i,
                        ColumnName  = text.Trim()
                    };
                    heads.Add(head);
                }
            }
        }
Example #3
0
        public void TestQuickGuide()
        {
            IWorkbook wb = _testDataProvider.CreateWorkbook();

            ICreationHelper factory = wb.GetCreationHelper();

            ISheet sheet = wb.CreateSheet();

            ICell cell = sheet.CreateRow(3).CreateCell(5);

            cell.SetCellValue("F4");

            IDrawing drawing = sheet.CreateDrawingPatriarch();

            IClientAnchor   anchor  = factory.CreateClientAnchor();
            IComment        comment = drawing.CreateCellComment(anchor);
            IRichTextString str     = factory.CreateRichTextString("Hello, World!");

            comment.String = (str);
            comment.Author = ("Apache POI");
            //assign the comment to the cell
            cell.CellComment = (comment);

            wb      = _testDataProvider.WriteOutAndReadBack(wb);
            sheet   = wb.GetSheetAt(0);
            cell    = sheet.GetRow(3).GetCell(5);
            comment = cell.CellComment;
            Assert.IsNotNull(comment);
            Assert.AreEqual("Hello, World!", comment.String.String);
            Assert.AreEqual("Apache POI", comment.Author);
            Assert.AreEqual(3, comment.Row);
            Assert.AreEqual(5, comment.Column);
        }
Example #4
0
        private IComment insertComment(IDrawing Drawing, ICell cell, String message)
        {
            ICreationHelper factory = cell.Sheet.Workbook.GetCreationHelper();

            IClientAnchor anchor = factory.CreateClientAnchor();

            anchor.Col1 = (/*setter*/ cell.ColumnIndex);
            anchor.Col2 = (/*setter*/ cell.ColumnIndex + 1);
            anchor.Row1 = (/*setter*/ cell.RowIndex);
            anchor.Row2 = (/*setter*/ cell.RowIndex + 1);
            anchor.Dx1  = (/*setter*/ 100);
            anchor.Dx2  = (/*setter*/ 100);
            anchor.Dy1  = (/*setter*/ 100);
            anchor.Dy2  = (/*setter*/ 100);

            IComment comment = Drawing.CreateCellComment(anchor);

            IRichTextString str = factory.CreateRichTextString(message);

            comment.String   = (/*setter*/ str);
            comment.Author   = (/*setter*/ "fanfy");
            cell.CellComment = (/*setter*/ comment);

            return(comment);
        }
 public ExpiringAction(IUser actionedBy, IDateTime starts, IDateTime ends, IRichTextString reason)
 {
     ActionedBy = actionedBy;
     Starts     = starts;
     Ends       = ends;
     Reason     = reason;
 }
Example #6
0
        public void TestBug57294()
        {
            IWorkbook wb = SXSSFITestDataProvider.instance.CreateWorkbook();

            ISheet sheet = wb.CreateSheet();
            IRow   row   = sheet.CreateRow(0);
            ICell  cell  = row.CreateCell(0);

            IRichTextString str = new XSSFRichTextString("Test rich text string");

            str.ApplyFont(2, 4, (short)0);
            Assert.AreEqual(3, str.NumFormattingRuns);
            cell.SetCellValue(str);

            IWorkbook wbBack = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb);

            wb.Close();

            // re-read after serializing and reading back
            ICell cellBack = wbBack.GetSheetAt(0).GetRow(0).GetCell(0);

            Assert.IsNotNull(cellBack);
            IRichTextString strBack = cellBack.RichStringCellValue;

            Assert.IsNotNull(strBack);
            Assert.AreEqual(3, strBack.NumFormattingRuns);
            Assert.AreEqual(0, strBack.GetIndexOfFormattingRun(0));
            Assert.AreEqual(2, strBack.GetIndexOfFormattingRun(1));
            Assert.AreEqual(4, strBack.GetIndexOfFormattingRun(2));

            wbBack.Close();
        }
Example #7
0
        public void GetCellComment()
        {
            IWorkbook       wb      = _testDataProvider.CreateWorkbook();
            ISheet          sheet   = wb.CreateSheet();
            ICreationHelper factory = wb.GetCreationHelper();
            IRow            row     = sheet.CreateRow(0);
            ICell           cell    = row.CreateCell(1);

            // cell does not have a comment
            Assert.IsNull(cell.CellComment);

            // add a cell comment
            IClientAnchor anchor = factory.CreateClientAnchor();

            anchor.Col1 = cell.ColumnIndex;
            anchor.Col2 = cell.ColumnIndex + 1;
            anchor.Row1 = row.RowNum;
            anchor.Row2 = row.RowNum + 3;
            IDrawing        drawing = sheet.CreateDrawingPatriarch();
            IComment        comment = drawing.CreateCellComment(anchor);
            IRichTextString str     = factory.CreateRichTextString("Hello, World!");

            comment.String   = str;
            comment.Author   = "Apache POI";
            cell.CellComment = comment;
            // ideally assertSame, but XSSFCell creates a new XSSFCellComment wrapping the same bean for every call to getCellComment.
            Assert.AreEqual(comment, cell.CellComment);
            wb.Close();
        }
Example #8
0
        /**
         * Set a string value for the cell.
         *
         * @param str  value to Set the cell to.  For formulas we'll Set the 'pre-Evaluated result string,
         * for String cells we'll Set its value.  For other types we will
         * change the cell to a string cell and Set its value.
         * If value is null then we will change the cell to a Blank cell.
         */
        public void SetCellValue(IRichTextString str)
        {
            if (str == null || str.String == null)
            {
                SetCellType(CellType.BLANK);
                return;
            }
            CellType cellType = CellType;

            switch (cellType)
            {
            case CellType.FORMULA:
                _cell.v = (str.String);
                _cell.t = (ST_CellType.str);
                break;

            default:
                if (_cell.t == ST_CellType.inlineStr)
                {
                    //set the 'pre-Evaluated result
                    _cell.v = str.String;
                }
                else
                {
                    _cell.t = ST_CellType.s;
                    XSSFRichTextString rt = (XSSFRichTextString)str;
                    rt.SetStylesTableReference(_stylesSource);
                    int sRef = _sharedStringSource.AddEntry(rt.GetCTRst());
                    _cell.v = sRef.ToString();
                }
                break;
            }
        }
Example #9
0
        /// <summary>
        /// Creates a cell and sets it to a rich text value.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="column">The column.</param>
        /// <param name="value">The value to set.</param>
        /// <returns>The newly created cell.</returns>
        public static ICell SetCell(this IRow row, int column, IRichTextString value)
        {
            var cell = row.CreateCell(column);

            cell.SetCellValue(value);
            return(cell);
        }
Example #10
0
        public void SetCellValue(IRichTextString value)
        {
            XSSFRichTextString xvalue = (XSSFRichTextString)value;

            if (xvalue != null && xvalue.String != null)
            {
                EnsureRichTextStringType();

                if (xvalue.Length > SpreadsheetVersion.EXCEL2007.MaxTextLength)
                {
                    throw new InvalidOperationException("The maximum length of cell contents (text) is 32,767 characters");
                }

                if (xvalue.HasFormatting())
                {
                    logger.Log(POILogger.WARN, "SXSSF doesn't support Shared Strings, rich text formatting information has be lost");
                }

                ((RichTextValue)_value).Value = xvalue;
            }
            else
            {
                SetCellType(CellType.Blank);
            }
        }
Example #11
0
 public void Kick(IUser kickedBy, IRichTextString reason = null)
 {
     KickHistory = new PermanentAction(
         kickedBy,
         DateTime.Now.ToDateTime(),
         reason ?? "No Reason.".AsRichTextString()
         );
 }
Example #12
0
 public RichTextMessage(IRichTextString input)
 {
     Datestamp = DateTime.Now.ToDate();
     Timestamp = DateTime.Now.ToTime();
     User      = Users.None;
     String    = input;
     Type      = MessageType.Unknown;
 }
Example #13
0
 public void Freeze(IUser frozenBy, ITimeSpan duration = null, IRichTextString reason = null)
 {
     FreezeHistory = new ExpiringAction(
         frozenBy,
         DateTime.Now.ToDateTime(),
         (DateTime.Now + (duration ?? TimeSpan.MaxValue.ToTimeSpan()).ToSystemTimeSpan()).ToDateTime(),
         reason ?? "No Reason.".AsRichTextString()
         );
 }
Example #14
0
 public void Ban(IUser bannedBy, ITimeSpan duration = null, IRichTextString reason = null)
 {
     BanHistory = new ExpiringAction(
         bannedBy,
         DateTime.Now.ToDateTime(),
         (DateTime.Now + (duration ?? TimeSpan.MaxValue.ToTimeSpan()).ToSystemTimeSpan()).ToDateTime(),
         reason ?? "No Reason.".AsRichTextString()
         );
 }
Example #15
0
        public static TextBlock ToTextBlock(IRichTextString input)
        {
            TextBlock output = new TextBlock();

            output.Padding      = new Thickness(5, 0, 5, 0);
            output.Margin       = new Thickness(0, 0, 0, 0);
            output.TextWrapping = TextWrapping.WrapWithOverflow;
            foreach (IRichTextElement thisElement in input.Elements)
            {
                #region Set String
                Run thisRun = new Run(thisElement.Message);
                #endregion
                #region Set Formatting
                if (thisElement.IsBold)
                {
                    thisRun.FontWeight = FontWeights.Bold;
                }
                if (thisElement.IsItallic)
                {
                    thisRun.FontStyle = FontStyles.Italic;
                }
                if (thisElement.IsUnderlined)
                {
                    thisRun.TextDecorations = TextDecorations.Underline;
                }
                if (thisElement.IsStrikeout)
                {
                    thisRun.TextDecorations = TextDecorations.Strikethrough;
                }
                #endregion
                #region Set Color
                thisRun.Foreground = new SolidColorBrush
                                     (
                    Color.FromArgb(
                        thisElement.ForeColor.Alpha,
                        thisElement.ForeColor.Red,
                        thisElement.ForeColor.Green,
                        thisElement.ForeColor.Blue)
                                     );
                ////thisRun.Background = new SolidColorBrush
                ////(
                ////	Color.FromArgb(
                ////		thisElement.BackColor.Alpha,
                ////		thisElement.BackColor.Red,
                ////		thisElement.BackColor.Green,
                ////		thisElement.BackColor.Blue)
                ////);
                thisRun.Background = new SolidColorBrush
                                     (
                    Color.FromArgb(0, 0, 0, 0)
                                     );
                #endregion
                output.Inlines.Add(thisRun);
            }
            return(output);
        }
Example #16
0
        /// <summary>
        /// 设置字符串的字体
        /// </summary>
        /// <param name="workbook">需要应用字体的工作簿</param>
        /// <param name="richText">单元格上的字符串</param>
        /// <param name="fontSize">字体大小</param>
        /// <param name="fontName">字体名称</param>
        public static IFont ApplyFont(this IWorkbook workbook, IRichTextString richText, short fontSize, string fontName = "宋体")
        {
            IFont font = workbook.CreateFont();

            font.Underline          = FontUnderlineType.None;
            font.FontName           = fontName;
            font.FontHeightInPoints = fontSize;
            richText.ApplyFont(0, richText.Length, font);
            return(font);
        }
Example #17
0
        /// <summary>
        /// 在字符串的指定起止位置设置下划线
        /// </summary>
        /// <param name="workbook">需要添加下划线的工作簿</param>
        /// <param name="richText">单元格上的字符串</param>
        /// <param name="fontSize">字体大小</param>
        /// <param name="startIndex">添加下划线的起始字符索引</param>
        /// <param name="endIndex">添加下划线的末尾字符索引</param>
        /// <param name="fontName">字体名称</param>
        public static IFont SetUnderline(this IWorkbook workbook, IRichTextString richText, short fontSize, int startIndex, int endIndex, string fontName = "宋体")
        {
            IFont font = workbook.CreateFont();

            font.Underline          = FontUnderlineType.Single;
            font.FontName           = fontName;
            font.FontHeightInPoints = fontSize;
            richText.ApplyFont(startIndex, endIndex, font);
            return(font);
        }
Example #18
0
        /// <summary>
        /// 将一个源文件的某个单元格的值复制到目标文件的指定单元格
        /// 以富文本的形式,保留原格式
        /// </summary>
        /// <param name="dst_row">目标行</param>
        /// <param name="dst_col">目标列</param>
        /// <param name="src_row">源行</param>
        /// <param name="src_col">源列</param>
        /// <param name="dst">目标文件</param>
        /// <param name="src">源文件</param>
        /// <returns></returns>
        public static bool CopyCell(int dst_row, int dst_col, int src_row, int src_col, ref HSSFSheet dst, ref HSSFSheet src)
        {
            if (src.GetRow(src_row - 1) == null)
            {
                return(false);
            }
            else
            {
                HSSFRow t_src_row = (HSSFRow)src.GetRow(src_row - 1);
                if (t_src_row.GetCell(src_col - 1) == null)
                {
                    return(false);
                }
                else
                {
                    HSSFCell t_src_cell = (HSSFCell)t_src_row.GetCell(src_col - 1);

                    if (dst.GetRow(dst_row - 1) == null)
                    {
                        HSSFRow t_row = (HSSFRow)dst.CreateRow(dst_row - 1);

                        HSSFCell t_cell = (HSSFCell)t_row.CreateCell(dst_col - 1);


                        t_cell.CellStyle = t_src_cell.CellStyle;
                        IRichTextString t = t_src_cell.RichStringCellValue;
                        t_cell.SetCellValue(t);
                    }
                    else
                    {
                        HSSFRow t_row = (HSSFRow)dst.GetRow(dst_row - 1);

                        if (t_row.GetCell(dst_col - 1) == null)
                        {
                            HSSFCell t_cell = (HSSFCell)t_row.CreateCell(dst_col - 1);
                            t_cell.CellStyle = t_src_cell.CellStyle;
                            IRichTextString t = t_src_cell.RichStringCellValue;
                            t_cell.SetCellValue(t);
                        }
                        else
                        {
                            HSSFCell t_cell = (HSSFCell)t_row.GetCell(dst_col - 1);

                            t_cell.CellStyle = t_src_cell.CellStyle;
                            IRichTextString t = t_src_cell.RichStringCellValue;
                            t_cell.SetCellValue(t);
                        }
                    }
                }
            }


            return(true);
        }
            public void Cell(CellRegion region, IRichTextString value, ICellStyle style, bool isBorder)
            {
                ICell            cell    = row.CreateCell(region.Col);
                CellRangeAddress address = region.GetRegion();

                sheet.AddMergedRegion(address);
                cell.SetCellValue(value);
                if (isBorder)
                {
                    SetBorder(address);
                }
            }
Example #20
0
        private void WriteFormatData(ContinuableRecordOutput out1, IRichTextString str)
        {
            int nRuns = str.NumFormattingRuns;

            for (int i = 0; i < nRuns; i++)
            {
                out1.WriteShort(str.GetIndexOfFormattingRun(i));
                int fontIndex = ((HSSFRichTextString)str).GetFontOfFormattingRun(i);
                out1.WriteShort(fontIndex == HSSFRichTextString.NO_FONT ? 0 : fontIndex);
                out1.WriteInt(0); // skip reserved
            }
            out1.WriteShort(str.Length);
            out1.WriteShort(0);
            out1.WriteInt(0); // skip reserved
        }
Example #21
0
        public void testBug58175a()
        {
            IWorkbook wb = new SXSSFWorkbook();

            try
            {
                ISheet sheet = wb.CreateSheet();
                IRow   row   = sheet.CreateRow(1);
                ICell  cell  = row.CreateCell(3);
                cell.SetCellValue("F4");
                IDrawing        drawing = sheet.CreateDrawingPatriarch();
                ICreationHelper factory = wb.GetCreationHelper();
                // When the comment box is visible, have it show in a 1x3 space
                IClientAnchor anchor = factory.CreateClientAnchor();
                anchor.Col1 = (cell.ColumnIndex);
                anchor.Col2 = (cell.ColumnIndex + 1);
                anchor.Row1 = (row.RowNum);
                anchor.Row2 = (row.RowNum + 3);
                // Create the comment and set the text+author
                IComment        comment = drawing.CreateCellComment(anchor);
                IRichTextString str     = factory.CreateRichTextString("Hello, World!");
                comment.String = (str);
                comment.Author = ("Apache POI");

                /* fixed the problem as well
                 * comment.setColumn(cell.ColumnIndex);
                 * comment.setRow(cell.RowIndex);
                 */
                // Assign the comment to the cell
                cell.CellComment = (comment);
                FileStream out1 = new FileStream("C:\\temp\\58175.xlsx", FileMode.CreateNew, FileAccess.ReadWrite);
                try
                {
                    wb.Write(out1);
                }
                finally
                {
                    out1.Close();
                }
            }
            finally
            {
                wb.Close();
            }
        }
Example #22
0
        private static void ProcessFontRuns(RecordInputStream in1, IRichTextString str,
                                            int formattingRunDataLength)
        {
            if (formattingRunDataLength % FORMAT_RUN_ENCODED_SIZE != 0)
            {
                throw new RecordFormatException("Bad format run data length " + formattingRunDataLength
                                                + ")");
            }
            int nRuns = formattingRunDataLength / FORMAT_RUN_ENCODED_SIZE;

            for (int i = 0; i < nRuns; i++)
            {
                short index = in1.ReadShort();
                short iFont = in1.ReadShort();
                in1.ReadInt(); // skip reserved.
                str.ApplyFont(index, str.Length, iFont);
            }
        }
Example #23
0
        /// <summary>
        /// Set a string value for the cell. Please note that if you are using
        /// full 16 bit Unicode you should call SetEncoding() first.
        /// </summary>
        /// <param name="value">value to Set the cell to.  For formulas we'll Set the formula
        /// string, for String cells we'll Set its value.  For other types we will
        /// Change the cell to a string cell and Set its value.
        /// If value is null then we will Change the cell to a Blank cell.</param>
        public void SetCellValue(IRichTextString value)
        {
            int   row        = _record.Row;
            int   col        = _record.Column;
            short styleIndex = _record.XFIndex;

            if (value == null)
            {
                NotifyFormulaChanging();
                SetCellType(CellType.Blank, false, row, col, styleIndex);
                return;
            }

            if (value.Length > NPOI.SS.SpreadsheetVersion.EXCEL97.MaxTextLength)
            {
                throw new ArgumentException("The maximum length of cell contents (text) is 32,767 characters");
            }
            if (cellType == CellType.Formula)
            {
                // Set the 'pre-Evaluated result' for the formula
                // note - formulas do not preserve text formatting.
                FormulaRecordAggregate fr = (FormulaRecordAggregate)_record;
                fr.SetCachedStringResult(value.String);
                // Update our local cache to the un-formatted version
                stringValue = new HSSFRichTextString(value.String);
                return;
            }

            if (cellType != CellType.String)
            {
                SetCellType(CellType.String, false, row, col, styleIndex);
            }
            int index = 0;

            HSSFRichTextString hvalue = (HSSFRichTextString)value;
            UnicodeString      str    = hvalue.UnicodeString;

            index = book.Workbook.AddSSTString(str);
            ((LabelSSTRecord)_record).SSTIndex = index;
            stringValue = hvalue;
            stringValue.SetWorkbookReferences(book.Workbook, ((LabelSSTRecord)_record));
            stringValue.UnicodeString = book.Workbook.GetSSTString(index);
        }
Example #24
0
        public void RemoveFromGroup(IUser addedBy, IGroup group, IRichTextString reason = null)
        {
            if (!IsCurrentlyInGroup(group))
            {
                return;                                         //Not even in the group.
            }
            GroupUpdateHistory.Add(
                new GroupUpdate()
            {
                Group = group,
                Rank  = group.GetLowestRank(),

                ActionedBy       = addedBy,
                ActionedDateTime = DateTime.Now.ToDateTime(),

                Reason = reason ?? ObjectFactory.CreateRichTextString("No Reason.")
            }
                );
        }
Example #25
0
        public void AddToGroup(IUser addedBy, IGroup group, IRichTextString reason = null)
        {
            if (IsCurrentlyInGroup(group))
            {
                return;                                        //Currently a member, no need to add again.
            }
            GroupUpdateHistory.Add(
                new GroupUpdate()
            {
                Group = group,
                Rank  = group.GetLowestRank(),

                ActionedBy       = addedBy,
                ActionedDateTime = DateTime.Now.ToDateTime(),

                Reason = reason ?? ObjectFactory.CreateRichTextString("No Reason.")
            }
                );
        }
Example #26
0
        public void Bug48325()
        {
            IWorkbook       wb      = _testDataProvider.CreateWorkbook();
            ISheet          sheet   = wb.CreateSheet("Test");
            ICreationHelper factory = wb.GetCreationHelper();

            IRow  row  = sheet.CreateRow(0);
            ICell cell = row.CreateCell(0);

            IFont           font = wb.CreateFont();
            IRichTextString rts  = factory.CreateRichTextString("");

            rts.ApplyFont(font);
            cell.SetCellValue(rts);

            sheet.AutoSizeColumn(0);

            Assert.IsNotNull(_testDataProvider.WriteOutAndReadBack(wb));

            wb.Close();
        }
Example #27
0
        public void Demote(IUser demotedBy, IGroup group, IRichTextString reason = null)
        {
            if (!IsCurrentlyInGroup(group))
            {
                return;                                         //Not in the group. Can't demote!
            }
            IRank currentRank = GetRankInGroupOrNull(group) ?? group.GetLowestRank();
            IRank newRank     = group.GetNextLowerRank(currentRank);

            GroupUpdateHistory.Add(
                new GroupUpdate()
            {
                Group = group,
                Rank  = newRank,

                ActionedBy       = demotedBy,
                ActionedDateTime = DateTime.Now.ToDateTime(),

                Reason = reason ?? ObjectFactory.CreateRichTextString("No Reason.")
            }
                );
        }
Example #28
0
        /**
         * Set a string value for the cell.
         *
         * @param str  value to Set the cell to.  For formulas we'll Set the 'pre-Evaluated result string,
         * for String cells we'll Set its value.  For other types we will
         * change the cell to a string cell and Set its value.
         * If value is null then we will change the cell to a Blank cell.
         */
        public void SetCellValue(IRichTextString str)
        {
            if (str == null || string.IsNullOrEmpty(str.String))
            {
                SetCellType(CellType.Blank);
                return;
            }

            if (str.Length > SpreadsheetVersion.EXCEL2007.MaxTextLength)
            {
                throw new ArgumentException("The maximum length of cell contents (text) is 32,767 characters");
            }
            CellType cellType = CellType;

            switch (cellType)
            {
            case CellType.Formula:
                _cell.v = (str.String);
                _cell.t = (ST_CellType.str);
                break;

            default:
                if (_cell.t == ST_CellType.inlineStr)
                {
                    //set the 'pre-Evaluated result
                    _cell.v = str.String;
                }
                else
                {
                    _cell.t = ST_CellType.s;
                    XSSFRichTextString rt = (XSSFRichTextString)str;
                    rt.SetStylesTableReference(_stylesSource);
                    int sRef = _sharedStringSource.AddEntry(rt.GetCTRst());
                    _cell.v = sRef.ToString();
                }
                break;
            }
        }
Example #29
0
 public void SetCellValue(IRichTextString str)
 {
     if (str == null || str.String == null)
     {
         this.SetCellType(CellType.BLANK);
     }
     else if (this.CellType == CellType.FORMULA)
     {
         this._cell.v = str.String;
         this._cell.t = ST_CellType.str;
     }
     else if (this._cell.t == ST_CellType.inlineStr)
     {
         this._cell.v = str.String;
     }
     else
     {
         this._cell.t = ST_CellType.s;
         XSSFRichTextString xssfRichTextString = (XSSFRichTextString)str;
         xssfRichTextString.SetStylesTableReference(this._stylesSource);
         this._cell.v = this._sharedStringSource.AddEntry(xssfRichTextString.GetCTRst()).ToString();
     }
 }
Example #30
0
        private static byte[] CreateFormatData(IRichTextString str)
        {
            int nRuns = str.NumFormattingRuns;

            byte[] result = new byte[(nRuns + 1) * FORMAT_RUN_ENCODED_SIZE];
            int    pos    = 0;

            for (int i = 0; i < nRuns; i++)
            {
                LittleEndian.PutUShort(result, pos, str.GetIndexOfFormattingRun(i));
                pos += 2;
                int fontIndex = ((HSSFRichTextString)str).GetFontOfFormattingRun(i);
                LittleEndian.PutUShort(result, pos, fontIndex == HSSFRichTextString.NO_FONT ? 0 : fontIndex);
                pos += 2;
                pos += 4; // skip reserved
            }
            LittleEndian.PutUShort(result, pos, str.Length);
            pos += 2;
            LittleEndian.PutUShort(result, pos, 0);
            pos += 2;
            pos += 4; // skip reserved

            return(result);
        }
        /// <summary>
        /// Adds the cell.
        /// </summary>
        /// <param name="rtfString">The RTF string.</param>
        /// <param name="cellStyle">The cell style.</param>
        /// <returns>CellAddress: the address object of the newly added cell.</returns>
        public CellAddress AddCell(IRichTextString rtfString, ICellStyle cellStyle)
        {
            _nextCellIndex++;
            IRow lastRow = GetLastRow();

            if (_nextCellIndex >= _reportColumnsNum)
            {
                _nextCellIndex = 0;
            }

            ICell lastCell = lastRow.CreateCell(_nextCellIndex, cellStyle);

            lastCell.SetCellValue(rtfString);

            return new CellAddress(lastCell.RowIndex, _nextCellIndex);
        }
 /// <summary>
 /// Creates a cell and sets it to a rich text value.
 /// </summary>
 /// <param name="row">The row.</param>
 /// <param name="column">The column.</param>
 /// <param name="value">The value to set.</param>
 /// <returns>The newly created cell.</returns>
 public static ICell SetCell(this IRow row, int column, IRichTextString value)
 {
     var cell = row.CreateCell(column);
     cell.SetCellValue(value);
     return cell;
 }
Example #33
0
 private static void ProcessFontRuns(RecordInputStream in1, IRichTextString str,
     int formattingRunDataLength)
 {
     if (formattingRunDataLength % FORMAT_RUN_ENCODED_SIZE != 0)
     {
         throw new RecordFormatException("Bad format run data length " + formattingRunDataLength
                 + ")");
     }
     int nRuns = formattingRunDataLength / FORMAT_RUN_ENCODED_SIZE;
     for (int i = 0; i < nRuns; i++)
     {
         short index = in1.ReadShort();
         short iFont = in1.ReadShort();
         in1.ReadInt(); // skip reserved.
         str.ApplyFont(index, str.Length, iFont);
     }
 }
Example #34
0
        private static byte[] CreateFormatData(IRichTextString str)
        {
            int nRuns = str.NumFormattingRuns;
            byte[] result = new byte[(nRuns + 1) * FORMAT_RUN_ENCODED_SIZE];
            int pos = 0;
            for (int i = 0; i < nRuns; i++)
            {
                LittleEndian.PutUShort(result, pos, str.GetIndexOfFormattingRun(i));
                pos += 2;
                int fontIndex = ((HSSFRichTextString)str).GetFontOfFormattingRun(i);
                LittleEndian.PutUShort(result, pos, fontIndex == HSSFRichTextString.NO_FONT ? 0 : fontIndex);
                pos += 2;
                pos += 4; // skip reserved
            }
            LittleEndian.PutUShort(result, pos, str.Length);
            pos += 2;
            LittleEndian.PutUShort(result, pos, 0);
            pos += 2;
            pos += 4; // skip reserved

            return result;
        }
Example #35
0
 private void WriteFormatData(ContinuableRecordOutput out1, IRichTextString str)
 {
     int nRuns = str.NumFormattingRuns;
     for (int i = 0; i < nRuns; i++)
     {
         out1.WriteShort(str.GetIndexOfFormattingRun(i));
         int fontIndex = ((HSSFRichTextString)str).GetFontOfFormattingRun(i);
         out1.WriteShort(fontIndex == HSSFRichTextString.NO_FONT ? 0 : fontIndex);
         out1.WriteInt(0); // skip reserved
     }
     out1.WriteShort(str.Length);
     out1.WriteShort(0);
     out1.WriteInt(0); // skip reserved
 }
Example #36
0
 /**
  * Sets the rich text string used by this comment.
  *
  * @param string  the XSSFRichTextString used by this object.
  */
 public void SetString(string str)
 {
     this.String = (new XSSFRichTextString(str));
 }
        public CellAddress AddCell(IRichTextString rtfString)
        {
            _nextCellIndex++;
            IRow lastRow = GetLastRow();

            if (_nextCellIndex >= _reportColumnsNum)
            {
                _nextCellIndex = 0;
            }

            ICell lastCell;

            if (lastRow.RowNum % 2 == 0)
            {
                lastCell = lastRow.CreateCell(_nextCellIndex, EvenCellStyle);
            }
            else
            {
                lastCell = lastRow.CreateCell(_nextCellIndex, OddCellStyle);
            }

            lastCell.SetCellValue(rtfString);

            return new CellAddress(lastCell.RowIndex, _nextCellIndex);
        }
Example #38
0
 public void SetCellValue(IRichTextString value, ICellStyle style)
 {
     SetCellValue(value);
     CellStyle = style;
 }
Example #39
0
 public void SetCellValue(IRichTextString str, ICellStyle style)
 {
     SetCellValue(str);
     CellStyle = style;
 }
Example #40
0
        /// <summary>
        /// Set a string value for the cell. Please note that if you are using
        /// full 16 bit Unicode you should call SetEncoding() first.
        /// </summary>
        /// <param name="value">value to Set the cell to.  For formulas we'll Set the formula
        /// string, for String cells we'll Set its value.  For other types we will
        /// Change the cell to a string cell and Set its value.
        /// If value is null then we will Change the cell to a Blank cell.</param>
        public void SetCellValue(IRichTextString value)
        {
            HSSFRichTextString hvalue = (HSSFRichTextString)value;

            int row = record.Row;
            int col = record.Column;
            short styleIndex = record.XFIndex;
            if (hvalue == null)
            {
                NotifyFormulaChanging();
                SetCellType(CellType.BLANK, false, row, col, styleIndex);
                return;
            }

            if (hvalue.Length > NPOI.SS.SpreadsheetVersion.EXCEL97.MaxTextLength)
            {
                throw new ArgumentException("The maximum length of cell contents (text) is 32,767 characters");
            }
            if (cellType == CellType.FORMULA)
            {
                // Set the 'pre-Evaluated result' for the formula 
                // note - formulas do not preserve text formatting.
                FormulaRecordAggregate fr = (FormulaRecordAggregate)record;
                fr.SetCachedStringResult(value.String);
                // Update our local cache to the un-formatted version
                stringValue = new HSSFRichTextString(value.String);
                return;
            }

            if (cellType != CellType.STRING)
            {
                SetCellType(CellType.STRING, false, row, col, styleIndex);
            }
            int index = 0;

            UnicodeString str = hvalue.UnicodeString;
            index = book.Workbook.AddSSTString(str);
            ((LabelSSTRecord)record).SSTIndex = index;
            stringValue = hvalue;
            stringValue.SetWorkbookReferences(book.Workbook, ((LabelSSTRecord)record));
            stringValue.UnicodeString = book.Workbook.GetSSTString(index);
        }
Example #41
0
        /**
         * Set a string value for the cell.
         *
         * @param str  value to Set the cell to.  For formulas we'll Set the 'pre-Evaluated result string,
         * for String cells we'll Set its value.  For other types we will
         * change the cell to a string cell and Set its value.
         * If value is null then we will change the cell to a Blank cell.
         */
        public void SetCellValue(IRichTextString str)
        {
            if (str == null || string.IsNullOrEmpty(str.String))
            {
                SetCellType(CellType.Blank);
                return;
            }

            if (str.Length > SpreadsheetVersion.EXCEL2007.MaxTextLength)
            {
                throw new ArgumentException("The maximum length of cell contents (text) is 32,767 characters");
            }
            CellType cellType = CellType;
            switch (cellType)
            {
                case CellType.Formula:
                    _cell.v = (str.String);
                    _cell.t= (ST_CellType.str);
                    break;
                default:
                    if (_cell.t == ST_CellType.inlineStr)
                    {
                        //set the 'pre-Evaluated result
                        _cell.v = str.String;
                    }
                    else
                    {
                        _cell.t = ST_CellType.s;
                        XSSFRichTextString rt = (XSSFRichTextString)str;
                        rt.SetStylesTableReference(_stylesSource);
                        int sRef = _sharedStringSource.AddEntry(rt.GetCTRst());
                        _cell.v=sRef.ToString();
                    }
                    break;
            }
        }
Example #42
0
 /**
  * Set a string value for the cell.
  *
  * @param str  value to Set the cell to.  For formulas we'll Set the 'pre-Evaluated result string,
  * for String cells we'll Set its value.  For other types we will
  * change the cell to a string cell and Set its value.
  * If value is null then we will change the cell to a Blank cell.
  */
 public void SetCellValue(IRichTextString str)
 {
     if (str == null || string.IsNullOrEmpty(str.String))
     {
         SetCellType(CellType.Blank);
         return;
     }
     CellType cellType = CellType;
     switch (cellType)
     {
         case CellType.Formula:
             _cell.v = (str.String);
             _cell.t= (ST_CellType.str);
             break;
         default:
             if (_cell.t == ST_CellType.inlineStr)
             {
                 //set the 'pre-Evaluated result
                 _cell.v = str.String;
             }
             else
             {
                 _cell.t = ST_CellType.s;
                 XSSFRichTextString rt = (XSSFRichTextString)str;
                 rt.SetStylesTableReference(_stylesSource);
                 int sRef = _sharedStringSource.AddEntry(rt.GetCTRst());
                 _cell.v=sRef.ToString();
             }
             break;
     }
 }
        /// <summary>
        /// Adds the merged cell.
        /// </summary>
        /// <param name="rtfString">The RTF string.</param>
        /// <param name="mergedRange">The merged range.</param>
        /// <param name="cellStyle">The cell style.</param>
        /// <returns>CellAddress: the address object of the newly merged cell.</returns>
        public CellAddress AddMergedCell(IRichTextString rtfString, CellRangeAddress mergedRange, ICellStyle cellStyle)
        {
            _nextCellIndex++;

            if (_nextCellIndex >= _reportColumnsNum)
            {
                _nextCellIndex = 0;
            }

            MergeCell(mergedRange);

            IRow firstRow = _worksheet.GetRow(mergedRange.FirstRow);
            ICell lastCell = firstRow.GetCell(mergedRange.FirstColumn);
            lastCell.CellStyle = cellStyle;
            lastCell.SetCellValue(rtfString);

            return new CellAddress(lastCell.RowIndex, _nextCellIndex);
        }