/**
* Throw when an invalid operation is done.
- *
- * @author Julien Chable
- * @version 1.0
*/
@SuppressWarnings("serial")
-public final class InvalidOperationException extends OpenXML4JRuntimeException{
-
+public class InvalidOperationException extends OpenXML4JRuntimeException{
public InvalidOperationException(String message){
super(message);
}
--- /dev/null
+/* ====================================================================
+ 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.openxml4j.exceptions;
+
+import org.apache.poi.openxml4j.opc.PackagePart;
+
+/**
+ * Throw when trying to create a {@link PackagePart} but one
+ * already exists with that name.
+ */
+@SuppressWarnings("serial")
+public final class PartAlreadyExistsException extends InvalidOperationException {
+ public PartAlreadyExistsException(String message){
+ super(message);
+ }
+}
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
+import org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException;
import org.apache.poi.openxml4j.opc.internal.ContentType;
import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
// Check if the specified part name already exists
if (partList.containsKey(partName)
&& !partList.get(partName).isDeleted()) {
- throw new InvalidOperationException(
+ throw new PartAlreadyExistsException(
"A part with the name '"
+ partName.getName()
+ "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame;
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
/**
package org.apache.poi.openxml4j.opc.compliance;
-import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
+import org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException;
import org.apache.poi.openxml4j.opc.ContentTypes;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.openxml4j.opc.TargetMode;
-import org.apache.poi.POIDataSamples;
/**
* Test Open Packaging Convention package model compliance.
pkg.createPart(name1, ContentTypes.XML);
try {
pkg.createPart(name2, ContentTypes.XML);
- } catch (InvalidOperationException e) {
+ } catch (PartAlreadyExistsException e) {
return;
}
fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
assertEquals(rels0.get(0).getPackageRelationship(), rels1.get(0).getPackageRelationship());
}
+
+ /**
+ * Add comments to Sheet 1, when Sheet 2 already has
+ * comments (so /xl/comments1.xml is taken)
+ */
+ public void DISABLEDtest51850() {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51850.xlsx");
+ XSSFSheet sh1 = wb.getSheetAt(0);
+ XSSFSheet sh2 = wb.getSheetAt(1);
+
+ // Sheet 2 has comments
+ assertNotNull(sh2.getCommentsTable(false));
+
+ // Sheet 1 doesn't (yet)
+ assertNull(sh1.getCommentsTable(false));
+
+ // Try to add comments to Sheet 1
+ CreationHelper factory = wb.getCreationHelper();
+ Drawing drawing = sh1.createDrawingPatriarch();
+
+ ClientAnchor anchor = factory.createClientAnchor();
+ anchor.setCol1(0);
+ anchor.setCol2(4);
+ anchor.setRow1(0);
+ anchor.setRow2(1);
+
+ Comment excelComment = drawing.createCellComment(anchor);
+ excelComment.setString(
+ factory.createRichTextString("I like this cell. It's my favourite."));
+ excelComment.setAuthor("Bob T. Fish");
+
+ Cell c = sh1.getRow(0).getCell(4);
+ c.setCellComment(excelComment);
+ }
}