unfinished release guide. It would be nice to have a html version.
[poi.git] / src / scratchpad / ooxml-src / org / apache / poi / hssf / HSSFXML.java
blob3766a046a1bbb213680329f09263ab8a1f851072
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 ==================================================================== */
17 package org.apache.poi.hssf;
19 import java.io.IOException;
21 import org.apache.poi.hssf.model.SharedStringsTable;
22 import org.apache.poi.hxf.HXFDocument;
23 import org.apache.xmlbeans.XmlException;
24 import org.openxml4j.exceptions.OpenXML4JException;
25 import org.openxml4j.opc.Package;
26 import org.openxml4j.opc.PackagePart;
27 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
28 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheets;
29 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
30 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
31 import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
32 import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument;
34 /**
35 * Experimental class to do low level processing
36 * of xlsx files.
38 * If you are using these low level classes, then you
39 * will almost certainly need to refer to the OOXML
40 * specifications from
41 * http://www.ecma-international.org/publications/standards/Ecma-376.htm
43 * WARNING - APIs expected to change rapidly
45 public class HSSFXML extends HXFDocument {
46 public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
47 public static final String SHEET_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
48 public static final String SHARED_STRINGS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
49 public static final String SHARED_STRINGS_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";
51 private WorkbookDocument workbookDoc;
52 private SharedStringsTable sharedStrings;
54 public HSSFXML(Package container) throws OpenXML4JException, IOException, XmlException {
55 super(container, MAIN_CONTENT_TYPE);
57 workbookDoc =
58 WorkbookDocument.Factory.parse(basePart.getInputStream());
60 PackagePart ssPart = getSinglePartByRelationType(SHARED_STRINGS_RELATION_TYPE, basePart);
61 if (ssPart != null) {
62 sharedStrings = new SharedStringsTable(ssPart);
63 } else {
68 /**
69 * Returns the low level workbook base object
71 public CTWorkbook getWorkbook() {
72 return workbookDoc.getWorkbook();
74 /**
75 * Returns the references from the workbook to its
76 * sheets.
77 * You'll need these to figure out the sheet ordering,
78 * and to get at the actual sheets themselves
80 public CTSheets getSheetReferences() {
81 return getWorkbook().getSheets();
83 /**
84 * Returns the low level (work)sheet object from
85 * the supplied sheet reference
87 public CTWorksheet getSheet(CTSheet sheet) throws IOException, XmlException {
88 PackagePart sheetPart =
89 getRelatedPackagePart(sheet.getId());
90 WorksheetDocument sheetDoc =
91 WorksheetDocument.Factory.parse(sheetPart.getInputStream());
92 return sheetDoc.getWorksheet();
95 /**
96 * Returns the shared string at the given index
98 public String getSharedString(int index) {
99 return this.sharedStrings.get(index);
101 protected SharedStringsTable _getSharedStringsTable() {
102 return sharedStrings;