aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/documentation/content/xdocs/status.xml2
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java65
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java6
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java34
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java52
-rwxr-xr-xtest-data/spreadsheet/47737.xlsxbin0 -> 11369 bytes
-rwxr-xr-xtest-data/spreadsheet/47813.xlsxbin0 -> 54880 bytes
7 files changed, 157 insertions, 2 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 632065a8ff..c409671616 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -33,6 +33,8 @@
<changes>
<release version="3.5-beta7" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">47813 - fixed problems with XSSFWorkbook.removeSheetAt when workbook contains chart</action>
+ <action dev="POI-DEVELOPERS" type="fix">47737 - adjust sheet indices of named ranges when deleting sheets</action>
<action dev="POI-DEVELOPERS" type="fix">47770 - built-in positive formats don't need starting '('</action>
<action dev="POI-DEVELOPERS" type="add">47771 - Added method setFunction(boolean) for defined names</action>
<action dev="POI-DEVELOPERS" type="add">47768 - Implementation of Excel "Days360" and "Npv" functions</action>
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java
new file mode 100755
index 0000000000..607249e1f9
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChartSheet.java
@@ -0,0 +1,65 @@
+/* ====================================================================
+ 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.usermodel;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+
+/**
+ * High level representation of of Sheet Parts that are of type 'chartsheet'.
+ *
+ * TODO: current verion extends XSSFSheet although both should extend AbstractSheet
+ *
+ * @author Yegor Kozlov
+ */
+public class XSSFChartSheet extends XSSFSheet {
+
+ protected CTChartsheet chartsheet;
+
+ protected XSSFChartSheet(PackagePart part, PackageRelationship rel) {
+ super(part, rel);
+ }
+
+ protected void read(InputStream is) throws IOException {
+ try {
+ chartsheet = ChartsheetDocument.Factory.parse(is).getChartsheet();
+ } catch (XmlException e){
+ throw new POIXMLException(e);
+ }
+ }
+
+ /**
+ * Provide access to the CTWorksheet bean holding this sheet's data
+ *
+ * @return the CTWorksheet bean holding this sheet's data
+ */
+ public CTChartsheet getCTChartsheet() {
+ return chartsheet;
+ }
+
+ @Override
+ protected void commit() throws IOException {
+
+ }
+
+} \ No newline at end of file
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
index 42cd41a3e3..ad3f98812d 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
@@ -90,6 +90,12 @@ public final class XSSFRelation extends POIXMLRelation {
"/xl/worksheets/sheet#.xml",
XSSFSheet.class
);
+ public static final XSSFRelation CHARTSHEET = new XSSFRelation(
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml",
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet",
+ "/xl/chartsheets/sheet#.xml",
+ XSSFChartSheet.class
+ );
public static final XSSFRelation SHARED_STRINGS = new XSSFRelation(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 622104e8a5..e761146d3e 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -781,10 +781,40 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
public void removeSheetAt(int index) {
validateSheetIndex(index);
+ onSheetDelete(index);
+
XSSFSheet sheet = getSheetAt(index);
removeRelation(sheet);
- this.sheets.remove(index);
- this.workbook.getSheets().removeSheet(index);
+ sheets.remove(index);
+ }
+
+ /**
+ * Gracefully remove references to the sheet being deleted
+ *
+ * @param index the 0-based index of the sheet to delete
+ */
+ private void onSheetDelete(int index) {
+ //delete the CTSheet reference from workbook.xml
+ workbook.getSheets().removeSheet(index);
+
+ //calculation chain is auxilary, remove it as it may contain orfan references to deleted cells
+ if(calcChain != null) {
+ removeRelation(calcChain);
+ calcChain = null;
+ }
+
+ //adjust indices of names ranges
+ for (Iterator<XSSFName> it = namedRanges.iterator(); it.hasNext();) {
+ XSSFName nm = it.next();
+ CTDefinedName ct = nm.getCTName();
+ if(!ct.isSetLocalSheetId()) continue;
+ if (ct.getLocalSheetId() == index) {
+ it.remove();
+ } else if (ct.getLocalSheetId() > index){
+ // Bump down by one, so still points at the same sheet
+ ct.setLocalSheetId(ct.getLocalSheetId()-1);
+ }
+ }
}
/**
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
index 9db76c04f9..b25cd26c9c 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
@@ -304,4 +304,56 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
assertEquals(crc0.getValue(), crc1.getValue());
}
+
+ /**
+ * When deleting a sheet make sure that we adjust sheet indices of named ranges
+ */
+ public void testBug47737() {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47737.xlsx");
+ assertEquals(2, wb.getNumberOfNames());
+ assertNotNull(wb.getCalculationChain());
+
+ XSSFName nm0 = wb.getNameAt(0);
+ assertTrue(nm0.getCTName().isSetLocalSheetId());
+ assertEquals(0, nm0.getCTName().getLocalSheetId());
+
+ XSSFName nm1 = wb.getNameAt(1);
+ assertTrue(nm1.getCTName().isSetLocalSheetId());
+ assertEquals(1, nm1.getCTName().getLocalSheetId());
+
+ wb.removeSheetAt(0);
+ assertEquals(1, wb.getNumberOfNames());
+ XSSFName nm2 = wb.getNameAt(0);
+ assertTrue(nm2.getCTName().isSetLocalSheetId());
+ assertEquals(0, nm2.getCTName().getLocalSheetId());
+ //calculation chain is removed as well
+ assertNull(wb.getCalculationChain());
+
+ }
+
+ /**
+ * Problems with XSSFWorkbook.removeSheetAt when workbook contains chart
+ */
+ public void testBug47813() {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47813.xlsx");
+ assertEquals(3, wb.getNumberOfSheets());
+ assertNotNull(wb.getCalculationChain());
+
+ assertEquals("Numbers", wb.getSheetName(0));
+ //the second sheet is of type 'chartsheet'
+ assertEquals("Chart", wb.getSheetName(1));
+ assertTrue(wb.getSheetAt(1) instanceof XSSFChartSheet);
+ assertEquals("SomeJunk", wb.getSheetName(2));
+
+ wb.removeSheetAt(2);
+ assertEquals(2, wb.getNumberOfSheets());
+ assertNull(wb.getCalculationChain());
+
+ wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ assertEquals(2, wb.getNumberOfSheets());
+ assertNull(wb.getCalculationChain());
+
+ assertEquals("Numbers", wb.getSheetName(0));
+ assertEquals("Chart", wb.getSheetName(1));
+ }
}
diff --git a/test-data/spreadsheet/47737.xlsx b/test-data/spreadsheet/47737.xlsx
new file mode 100755
index 0000000000..5737a595cb
--- /dev/null
+++ b/test-data/spreadsheet/47737.xlsx
Binary files differ
diff --git a/test-data/spreadsheet/47813.xlsx b/test-data/spreadsheet/47813.xlsx
new file mode 100755
index 0000000000..5ab22e3046
--- /dev/null
+++ b/test-data/spreadsheet/47813.xlsx
Binary files differ
Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
summaryrefslogtreecommitdiffstats
path: root/lib/l10n/sq.json
blob: b884ab5bfc3ec2b1f7aaec1dd3048ea3bfab1262 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210