@@ -26,6 +26,9 @@ namespace NPOI.XSSF.Model
2626 using System . IO ;
2727 using NPOI . OpenXml4Net . OPC ;
2828 using System . Xml ;
29+ using NPOI . Util ;
30+ using NPOI . XSSF . UserModel ;
31+ using NPOI . SS . UserModel ;
2932 using System . Text ;
3033
3134 /**
@@ -529,18 +532,28 @@ private static String GetKey(CT_Rst st)
529532 return st . XmlText ;
530533 }
531534
532- /**
533- * Return a string item by index
534- *
535- * @ param idx index of item to return.
536- * @return the item at the specified position in this Shared String table.
537- */
535+ /// <summary>
536+ /// Return a string item by index
537+ /// </summary>
538+ /// < param name=" idx"> index of item to return.</param>
539+ /// <returns> the item at the specified position in this Shared String table.</returns>
540+ [ Obsolete ( "use GetItemAt(int idx) instead. Removal at POI 4.2" ) ]
538541 public CT_Rst GetEntryAt ( int idx )
539542 {
540543 EnsureLoaded ( ) ;
541544 return strings [ idx ] ;
542545 }
543546
547+ /// <summary>
548+ /// Return a string item by index
549+ /// </summary>
550+ /// <param name="idx">index of item to return.</param>
551+ /// <returns>the item at the specified position in this Shared String table.</returns>
552+ public IRichTextString GetItemAt ( int idx )
553+ {
554+ return new XSSFRichTextString ( strings [ idx ] ) ;
555+ }
556+
544557 /**
545558 * Return an integer representing the total count of strings in the workbook. This count does not
546559 * include any numbers, it counts only the total of text strings in the workbook.
@@ -583,6 +596,8 @@ public int UniqueCount
583596 * @param st the entry to add
584597 * @return index the index of Added entry
585598 */
599+ [ Obsolete ( "use <code>addSharedStringItem(RichTextString string)</code> instead" ) ]
600+ [ Removal ( Version = "4.2" ) ]
586601 public int AddEntry ( CT_Rst st )
587602 {
588603 EnsureLoaded ( ) ;
@@ -606,11 +621,33 @@ public int AddEntry(CT_Rst st)
606621 return idx ;
607622 }
608623
624+ /**
625+ * Add an entry to this Shared String table (a new value is appended to the end).
626+ *
627+ * <p>
628+ * If the Shared String table already contains this string entry, its index is returned.
629+ * Otherwise a new entry is added.
630+ * </p>
631+ *
632+ * @param string the entry to add
633+ * @since POI 4.0.0
634+ * @return index the index of added entry
635+ */
636+ public int AddSharedStringItem ( IRichTextString str )
637+ {
638+ if ( ! ( str is XSSFRichTextString ) ) {
639+ throw new ArgumentException ( "Only XSSFRichTextString argument is supported" ) ;
640+ }
641+ return AddEntry ( ( ( XSSFRichTextString ) str ) . GetCTRst ( ) ) ;
642+ }
643+
609644 /**
610645 * Provide low-level access to the underlying array of CT_Rst beans
611646 *
612647 * @return array of CT_Rst beans
613648 */
649+ [ Obsolete ( "use <code>getSharedStringItems</code> instead" ) ]
650+ [ Removal ( Version = "4.2" ) ]
614651 public IList < CT_Rst > Items
615652 {
616653 get
@@ -621,8 +658,27 @@ public IList<CT_Rst> Items
621658 }
622659
623660 /**
624- * Write this table out as XML.
661+ * Provide access to the strings in the SharedStringsTable
625662 *
663+ * @return list of shared string instances
664+ */
665+ public IList < IRichTextString > SharedStringItems
666+ {
667+ get
668+ {
669+ List < IRichTextString > items = new List < IRichTextString > ( ) ;
670+ foreach ( CT_Rst rst in strings )
671+ {
672+ items . Add ( new XSSFRichTextString ( rst ) ) ;
673+ }
674+ return items . AsReadOnly ( ) ;
675+ }
676+ }
677+
678+ /**
679+ *
680+ * this table out as XML.
681+ *
626682 * @param out The stream to write to.
627683 * @throws IOException if an error occurs while writing.
628684 */
0 commit comments