1 /* ====================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ==================================================================== */
18 package org
.apache
.poi
.hssf
.model
;
20 import java
.io
.IOException
;
21 import java
.io
.OutputStream
;
22 import java
.util
.LinkedList
;
24 import org
.apache
.xmlbeans
.XmlException
;
25 import org
.openxml4j
.opc
.PackagePart
;
26 import org
.openxmlformats
.schemas
.spreadsheetml
.x2006
.main
.CTRst
;
27 import org
.openxmlformats
.schemas
.spreadsheetml
.x2006
.main
.CTSst
;
28 import org
.openxmlformats
.schemas
.spreadsheetml
.x2006
.main
.SstDocument
;
31 public class SharedStringsTable
extends LinkedList
<String
> {
32 public static final String MAIN_SML_NS_URI
= "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
34 private SstDocument doc
;
35 private PackagePart part
;
37 public SharedStringsTable(PackagePart part
) throws IOException
, XmlException
{
39 doc
= SstDocument
.Factory
.parse(
46 CTRst
[] sts
= doc
.getSst().getSiArray();
47 for (int i
= 0; i
< sts
.length
; i
++) {
53 * Writes the current shared strings table into
54 * the associated OOXML PackagePart
56 public void write() throws IOException
{
57 CTSst sst
= doc
.getSst();
59 // Remove the old list
60 for(int i
=sst
.sizeOfSiArray() - 1; i
>=0; i
--) {
65 for(String s
: this) {
66 sst
.addNewSi().setT(s
);
70 sst
.setCount(this.size());
71 sst
.setUniqueCount(this.size());
74 OutputStream out
= part
.getOutputStream();