Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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
 }
Ejemplo n.º 5
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;
        }