/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ package org.apache.poi.xssf.model; import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS; import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_SPREADSHEETML; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.util.Internal; import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst; import org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument; /** * Table of strings shared across all sheets in a workbook. *
* A workbook may contain thousands of cells containing string (non-numeric) data. Furthermore this data is very * likely to be repeated across many rows or columns. The goal of implementing a single string table that is shared * across the workbook is to improve performance in opening and saving the file by only reading and writing the * repetitive information once. *
** Consider for example a workbook summarizing information for cities within various countries. There may be a * column for the name of the country, a column for the name of each city in that country, and a column * containing the data for each city. In this case the country name is repetitive, being duplicated in many cells. * In many cases the repetition is extensive, and a tremendous savings is realized by making use of a shared string * table when saving the workbook. When displaying text in the spreadsheet, the cell table will just contain an * index into the string table as the value of a cell, instead of the full string. *
** The shared string table contains all the necessary information for displaying the string: the text, formatting * properties, and phonetic properties (for East Asian languages). *
*/ public class SharedStringsTable extends POIXMLDocumentPart implements SharedStrings, Closeable { /** * Array of individual string items in the Shared String table. */ private final Liststrings
arrays
*/
private final Map
* If the Shared String table already contains this CTRst
bean, its index is returned.
* Otherwise a new entry is aded.
*
* If the Shared String table already contains this string entry, its index is returned. * Otherwise a new entry is added. *
* * @param string the entry to add * @since POI 4.0.0 * @return index the index of added entry */ public int addSharedStringItem(RichTextString string) { if(!(string instanceof XSSFRichTextString)){ throw new IllegalArgumentException("Only XSSFRichTextString argument is supported"); } return addEntry(((XSSFRichTextString) string).getCTRst()); } /** * Provide access to the strings in the SharedStringsTable * * @return list of shared string instances */ public ListXSSFWorkbook#close()
.
* * This implementation is empty but subclasses may need to implement some logic. *
* * @since 4.0.0 * @throws IOException if an error occurs while closing. */ @Override public void close() throws IOException {} }