System.out.println("Cell found with value " + numrec.getValue()
+ " at row " + numrec.getRow() + " and column " + numrec.getColumn());
break;
- // SSTRecords store a array of unique strings used in Excel.
+ // SSTRecords store an array of unique strings used in Excel.
case SSTRecord.sid:
sstrec = (SSTRecord) record;
for (int k = 0; k < sstrec.getNumUniqueStrings(); k++)
String formatString = InCellLists.BULLET_CHARACTER + " @";
int formatIndex = format.getFormat(formatString);
- // Construct an HSSFCellStyle and set it's data formt to use the
+ // Construct an HSSFCellStyle and set its data format to use the
// object created above.
HSSFCellStyle bulletStyle = workbook.createCellStyle();
bulletStyle.setDataFormat((short)formatIndex);
int increment) {
StringBuilder buffer = new StringBuilder();
int itemNumber = startingValue;
- // Note that again, an HSSFCellStye object is required and that
- // it's wrap text property should be set to 'true'
+ // Note that again, an HSSFCellStyle object is required and that
+ // its wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
// Note that the basic method is identical to the listInCell() method
HSSFCell cell) {
StringBuilder buffer = new StringBuilder();
// Note that again, an HSSFCellStye object is required and that
- // it's wrap text property should be set to 'true'
+ // its wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
// Note that the basic method is identical to the listInCell() method
HSSFCell cell) {
StringBuilder buffer = new StringBuilder();
// Note that again, an HSSFCellStye object is required and that
- // it's wrap text property should be set to 'true'
+ // its wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
// Step through the ArrayList of MultilLevelListItem instances.
StringBuilder buffer = new StringBuilder();
int highLevelItemNumber = highLevelStartingValue;
// Note that again, an HSSFCellStye object is required and that
- // it's wrap text property should be set to 'true'
+ // its wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
// Step through the ArrayList of MultilLevelListItem instances.
HSSFCell cell) {
StringBuilder buffer = new StringBuilder();
// Note that again, an HSSFCellStye object is required and that
- // it's wrap text property should be set to 'true'
+ // its wrap text property should be set to 'true'
HSSFCellStyle wrapStyle = workbook.createCellStyle();
wrapStyle.setWrapText(true);
// Step through the ArrayList of MultilLevelListItem instances.
* to reveal problems which are introduced, but not covered (yet) by unit tests.
*
* This test looks for any file under the test-data directory and tries to do some useful
- * processing with it based on it's type.
+ * processing with it based on its type.
*
* The test is implemented as a junit {@link ParameterizedTest} test, which leads
* to one test-method call for each file (currently around 950 files are handled).
*
- * There is a a mapping of extension to implementations of the interface
+ * There is a mapping of extension to implementations of the interface
* {@link FileHandler} which defines how the file is loaded and which actions are
* tried with the file.
*
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
/**
- * Represents a immutable MIME ContentType value (RFC 2616 §3.7)
+ * Represents an immutable MIME ContentType value (RFC 2616 §3.7)
* <p>
* media-type = type "/" subtype *( ";" parameter ) type = token<br>
* subtype = token<br>
/**
* <p>This class is the default entry point for XML signatures and can be used for
- * validating an existing signed office document and signing a office document.</p>
+ * validating an existing signed office document and signing an office document.</p>
*
* <p><b>Validating a signed office document</b></p>
*
}
/**
- * background does not have a associated transform, therefore we return null
+ * background does not have an associated transform, therefore we return null
*
* @param create ignored
*
}
/**
- * Set a error value for the cell
+ * Set an error value for the cell
*
* @param value the error value to set this cell to. For formulas, we'll set the
* precalculated value , for errors we'll set
"in the range [0," + _writer.getLastFlushedRow() + "] that is already written to disk.");
}
- // attempt to overwrite a existing row in the input template
+ // attempt to overwrite an existing row in the input template
if(_sh.getPhysicalNumberOfRows() > 0 && rownum <= _sh.getLastRowNum() ) {
throw new IllegalArgumentException(
"Attempting to write a row["+rownum+"] " +
}
/**
- * Set a error value for the cell
+ * Set an error value for the cell
*
* @param errorCode the error value to set this cell to. For formulas, we'll set the
* precalculated value , for errors we'll set
}
/**
- * Set a error value for the cell
+ * Set an error value for the cell
*
* @param error the error value to set this cell to. For formulas, we'll set the
* precalculated value , for errors we'll set
}
/**
- * Set the background fill color represented as a indexed color value.
+ * Set the background fill color represented as an indexed color value.
* <p>
* For example:
* <pre>
}
/**
- * Set the foreground fill color as a indexed color value
+ * Set the foreground fill color as an indexed color value
* <br>
* <i>Note: Ensure Foreground color is set prior to background color.</i>
* @param fg the color to use
}
/**
- * Set the color to use for the left border as a indexed color value
+ * Set the color to use for the left border as an indexed color value
*
* @param color the index of the color definition
* @see org.apache.poi.ss.usermodel.IndexedColors
}
/**
- * @return true if the ctColor has a alpha
+ * @return true if the ctColor has an alpha
*/
public boolean hasAlpha() {
return ctColor.isSetRgb() && ctColor.getRgb().length == 4;
}
/**
- * Return a object representing a collection of shared objects used for styling content,
+ * Return an object representing a collection of shared objects used for styling content,
* e.g. fonts, cell styles, colors, etc.
*/
public StylesTable getStylesSource() {
}
/**
- * Set the background fill color represented as a indexed color value.
+ * Set the background fill color represented as an indexed color value.
*
* @param index - the color to use
*/
}
/**
- * Set the foreground fill color as a indexed color value
+ * Set the foreground fill color as an indexed color value
*
* @param index - the color to use
*/
}
/**
- * copies content of a paragraph to a existing paragraph in the list paragraphs at position pos
+ * copies content of a paragraph to an existing paragraph in the list paragraphs at position pos
*/
public void setParagraph(XWPFParagraph paragraph, int pos) {
paragraphs.set(pos, paragraph);
ArchiveEntry entree;
while ((entree = zis.getNextEntry()) != null) {
- /* Create a array for the current entry */
+ /* Create an array for the current entry */
UnsynchronizedByteArrayOutputStream byteArray = new UnsynchronizedByteArrayOutputStream();
IOUtils.copy(zis, byteArray);
zipContent.put(entree.getName(), byteArray);
XSLFTextShape sh2 = (XSLFTextShape)shapes1.get(1);
assertEquals(
- "Text in a autoshape is white\n" +
+ "Text in an autoshape is white\n" +
"Fill: RGB(148, 198,0)", sh2.getText());
XSLFTextRun r2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
assertEquals("Century Gothic", r2.getFontFamily());
assertFalse(sheet.iterator().hasNext(), "Row iterator for charts sheets should return zero rows");
- //access to a arbitrary row
+ //access to an arbitrary row
assertNull(sheet.getRow(1));
//some basic get* accessors
if (dataI > -1) {
// copy the last read byte into the dictionary.
// the example data compressor used self references, so we don't wait for filling the dictionary
- // until we know if it's a un-/compressed token.
+ // until we know if it's an un-/compressed token.
dict[(posInp++) & DICT_MASK] = (byte)dataI;
}
// This is an unsigned byte read from the stream
* uniquely contains fonts based on their typeface, i.e. calling the method with FontInfo
* objects having the same name results in the same HSLFFontInfo reference.
*
- * @param fontInfo the FontInfo configuration, can be a instance of {@link HSLFFontInfo},
+ * @param fontInfo the FontInfo configuration, can be an instance of {@link HSLFFontInfo},
* {@link HSLFFontInfoPredefined} or a custom implementation
* @return the register HSLFFontInfo object
*/
}
/**
- * Add a embedded object to this presentation
+ * Add an embedded object to this presentation
*
* @return 0-based index of the embedded object
*/
}
/**
- * Sets color of the text, as a int bgr.
+ * Sets color of the text, as an int bgr.
* (PowerPoint stores as BlueGreenRed, not the more
* usual RedGreenBlue)
* @see Color
private DocumentProperties _dop;
/**
- * Contains text of the document wrapped in a obfuscated Word data
+ * Contains text of the document wrapped in an obfuscated Word data
* structure
*/
private ComplexFileTable _cft;
/*
* clx (encoding of the sprm lists for a complex file and piece table
- * for a any file) Written immediately after the end of the previously
+ * for an any file) Written immediately after the end of the previously
* recorded structure. This is recorded in all Word documents
*
* Microsoft Office Word 97-2007 Binary File Format (.doc)
* If an implementation doesn't provide a property, the getter will return {@code null} -
* if the value is unset, a default value will be returned.<p>
*
- * Setting a unsupported property results in an {@link UnsupportedOperationException}.
+ * Setting an unsupported property results in an {@link UnsupportedOperationException}.
*
* @since POI 3.17-beta2
*
import org.apache.poi.util.LittleEndian;
/**
- * This record is used whenever a escher record is encountered that
+ * This record is used whenever an escher record is encountered that
* we do not explicitly support.
*/
public final class UnknownEscherRecord extends EscherRecord {
*/
int offFix = (int)LittleEndian.getUInt(src, offset + ClassID.LENGTH);
- // some input files have a invalid (padded?) offset, which need to be fixed
+ // some input files have an invalid (padded?) offset, which need to be fixed
// search for beginning of size field
if (src[offFix] == 0) {
for (int i=0; i<3 && src[offFix] == 0; i++,offFix++);
/**
* For OLE and DDE, links can be either 'automatic' or 'manual'
*
- * @return {@code true} if this is a automatic link
+ * @return {@code true} if this is an automatic link
*/
public boolean isAutomaticLink() {
return (field_1_option_flag & OPT_AUTOMATIC_LINK) != 0;
*
* @return all byte data for the current record
*
- * @deprecated POI 2.0 Best to write a input stream that wraps this one
+ * @deprecated POI 2.0 Best to write an input stream that wraps this one
* where there is special sub record that may overlap continue
* records.
*/
import org.apache.poi.util.LittleEndianOutput;
/**
- * The area record is used to define a area chart.
+ * The area record is used to define an area chart.
*/
public final class AreaRecord extends StandardRecord {
public static final short sid = 0x101A;
}
/**
- * set a error value for the cell
+ * set an error value for the cell
*
* @param errorCode the error value to set this cell to. For formulas, we'll set the
* precalculated value , for errors we'll set
setCellErrorValue(error);
}
/**
- * set a error value for the cell
+ * set an error value for the cell
*
* @param error the error value to set this cell to. For formulas, we'll set the
* precalculated value , for errors we'll set
}
/**
- * Returns a unmodifiable list of all shapes contained by the patriarch.
+ * Returns an unmodifiable list of all shapes contained by the patriarch.
*/
@Override
public List<HSSFShape> getChildren() {
import org.apache.poi.util.StringUtil;
/**
- * Represents a escher picture. Eg. A GIF, JPEG etc...
+ * Represents an escher picture. Eg. A GIF, JPEG etc...
*/
public class HSSFPicture extends HSSFSimpleShape implements Picture {
}
/**
- * Return a output stream for encrypted data.
+ * Return an output stream for encrypted data.
*
* @param dir the node to write to
* @return encrypted stream
* <p>
* The area inside the polygon is defined using an
* even-odd fill rule, also known as the alternating rule.
- * @param xPoints a an array of <code>x</code> coordinates.
- * @param yPoints a an array of <code>y</code> coordinates.
- * @param nPoints a the total number of points.
+ * @param xPoints an array of <code>x</code> coordinates.
+ * @param yPoints an array of <code>y</code> coordinates.
+ * @param nPoints the total number of points.
* @see Graphics#drawPolygon(int[], int[], int)
*/
public void fillPolygon(int[] xPoints, int[] yPoints,
* 1 ≤ <i>i</i> ≤ <code>nPoints</code>.
* The figure is automatically closed by drawing a line connecting
* the final point to the first point, if those points are different.
- * @param xPoints a an array of <code>x</code> coordinates.
- * @param yPoints a an array of <code>y</code> coordinates.
- * @param nPoints a the total number of points.
+ * @param xPoints an array of <code>x</code> coordinates.
+ * @param yPoints an array of <code>y</code> coordinates.
+ * @param nPoints the total number of points.
* @see Graphics#fillPolygon(int[],int[],int)
* @see Graphics#drawPolyline
*/
public interface IAdjustableShape {
/**
*
- * @param name name of a adjust value, e.g. adj1
+ * @param name name of an adjust value, e.g. adj1
* @return adjust guide defined in the shape or null
*/
GuideIf getAdjustValue(String name);
}
/**
- * Creates a elapsed time formatter.
+ * Creates an elapsed time formatter.
*
* @param pattern The pattern to parse.
*/
}
/**
- * Evaluate for NETWORKDAYS. Given two dates and a optional date or interval of holidays, determines how many working days are there
+ * Evaluate for NETWORKDAYS. Given two dates and an optional date or interval of holidays, determines how many working days are there
* between those dates.
*
* @return {@link ValueEval} for the number of days between two dates.
/**
* Deleted Area 3D Ptg - 3D referecnce (Sheet + Area)<p>
- * Defined a area in Extern Sheet.
+ * Defined an area in Extern Sheet.
*
* @version 1.0-pre
*/
void setCellValue(boolean value);
/**
- * Set a error value for the cell
+ * Set an error value for the cell
*
* @param value the error value to set this cell to. For formulas, we'll set the
* precalculated value , for errors we'll set
* @param name the name of the property
* @param object the value of the property
* @return {@code true}, if the element was handled and output produced,
- * The provided methods can be overridden and a implementation can return {@code false},
+ * The provided methods can be overridden and an implementation can return {@code false},
* if the element hasn't been written to the stream
*/
boolean print(GenericRecordJsonWriter record, String name, Object object);
* @param name the name of the property
* @param object the value of the property
* @return {@code true}, if the element was handled and output produced,
- * The provided methods can be overridden and a implementation can return {@code false},
+ * The provided methods can be overridden and an implementation can return {@code false},
* if the element hasn't been written to the stream
*/
boolean print(GenericRecordXmlWriter record, String name, Object object);
}
- /* assert shape properties when reading shapes from a existing workbook */
+ /* assert shape properties when reading shapes from an existing workbook */
@Test
void testReadExistingRectangle() throws IOException {
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("drawings.xls")) {
--- /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.hssf.usermodel;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.Ole10Native;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.jupiter.api.Test;
+
+final class TestOLE2Embedding {
+
+ @Test
+ void testEmbedding() throws Exception {
+ // This used to break, until bug #43116 was fixed
+ try (HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls")) {
+ // Check we can get at the Escher layer still
+ assertDoesNotThrow(workbook::getAllPictures);
+ }
+ }
+
+ @Test
+ void testEmbeddedObjects() throws Exception {
+ try (HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls")) {
+ List<HSSFObjectData> objects = workbook.getAllEmbeddedObjects();
+ assertEquals(2, objects.size(), "Wrong number of objects");
+ assertEquals("MBD06CAB431", objects.get(0).getDirectory().getName(), "Wrong name for first object");
+ assertEquals("MBD06CAC85A", objects.get(1).getDirectory().getName(), "Wrong name for second object");
+ }
+ }
+
+ @Test
+ void testReallyEmbedSomething() throws Exception {
+ try (HSSFWorkbook wb1 = new HSSFWorkbook();
+ POIFSFileSystem pptPoifs = getSamplePPT();
+ POIFSFileSystem xlsPoifs = getSampleXLS()) {
+ HSSFSheet sheet = wb1.createSheet();
+ HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+
+ byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
+ byte[] picturePPT = POIDataSamples.getSlideShowInstance().readFile("clock.jpg");
+ int imgIdx = wb1.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
+
+ int pptIdx = wb1.addOlePackage(pptPoifs, "Sample-PPT", "sample.ppt", "sample.ppt");
+ int imgPPT = wb1.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
+ int xlsIdx = wb1.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
+ int txtIdx = wb1.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
+
+ int rowoffset = 5;
+ int coloffset = 5;
+
+ CreationHelper ch = wb1.getCreationHelper();
+ HSSFClientAnchor anchor = (HSSFClientAnchor) ch.createClientAnchor();
+ anchor.setAnchor((short) (2 + coloffset), 1 + rowoffset, 0, 0, (short) (3 + coloffset), 5 + rowoffset, 0, 0);
+ anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
+
+ patriarch.createObjectData(anchor, pptIdx, imgPPT);
+
+ anchor = (HSSFClientAnchor) ch.createClientAnchor();
+ anchor.setAnchor((short) (5 + coloffset), 1 + rowoffset, 0, 0, (short) (6 + coloffset), 5 + rowoffset, 0, 0);
+ anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
+
+ patriarch.createObjectData(anchor, xlsIdx, imgIdx);
+
+ anchor = (HSSFClientAnchor) ch.createClientAnchor();
+ anchor.setAnchor((short) (3 + coloffset), 10 + rowoffset, 0, 0, (short) (5 + coloffset), 11 + rowoffset, 0, 0);
+ anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
+
+ patriarch.createObjectData(anchor, txtIdx, imgIdx);
+
+ anchor = (HSSFClientAnchor) ch.createClientAnchor();
+ anchor.setAnchor((short) (1 + coloffset), -2 + rowoffset, 0, 0, (short) (7 + coloffset), 14 + rowoffset, 0, 0);
+ anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
+
+ HSSFSimpleShape circle = patriarch.createSimpleShape(anchor);
+ circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
+ circle.setNoFill(true);
+
+ try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
+ UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0);
+ Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory());
+ bos.reset();
+ pptPoifs.writeFilesystem(bos);
+ assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
+
+ od = wb2.getAllEmbeddedObjects().get(1);
+ ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory());
+ bos.reset();
+ xlsPoifs.writeFilesystem(bos);
+ assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
+
+ od = wb2.getAllEmbeddedObjects().get(2);
+ ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory());
+ assertArrayEquals(ole10.getDataBuffer(), getSampleTXT());
+ }
+ }
+ }
+
+ static POIFSFileSystem getSamplePPT() throws IOException {
+ // scratchpad classes are not available, so we use something pre-cooked
+ InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("with_textbox.ppt");
+ POIFSFileSystem poifs = new POIFSFileSystem(is);
+ is.close();
+
+ return poifs;
+ }
+
+ static POIFSFileSystem getSampleXLS() throws IOException {
+ UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ HSSFSheet sheet = wb.createSheet();
+ sheet.createRow(5).createCell(2).setCellValue("yo dawg i herd you like embeddet objekts, so we put an ole in your ole so you can save a file while you save a file");
+
+ wb.write(bos);
+ }
+
+ return new POIFSFileSystem(bos.toInputStream());
+ }
+
+ static byte[] getSampleTXT() {
+ return "All your base are belong to us".getBytes(LocaleUtil.CHARSET_1252);
+ }
+}
\ No newline at end of file
+++ /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.hssf.usermodel;
-
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-
-import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
-import org.apache.poi.POIDataSamples;
-import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.Ole10Native;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
-import org.apache.poi.ss.usermodel.CreationHelper;
-import org.apache.poi.util.LocaleUtil;
-import org.junit.jupiter.api.Test;
-
-final class TestOLE2Embeding {
-
- @Test
- void testEmbeding() throws Exception {
- // This used to break, until bug #43116 was fixed
- try (HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls")) {
- // Check we can get at the Escher layer still
- assertDoesNotThrow(workbook::getAllPictures);
- }
- }
-
- @Test
- void testEmbeddedObjects() throws Exception {
- try (HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ole2-embedding.xls")) {
- List<HSSFObjectData> objects = workbook.getAllEmbeddedObjects();
- assertEquals(2, objects.size(), "Wrong number of objects");
- assertEquals("MBD06CAB431", objects.get(0).getDirectory().getName(), "Wrong name for first object");
- assertEquals("MBD06CAC85A", objects.get(1).getDirectory().getName(), "Wrong name for second object");
- }
- }
-
- @Test
- void testReallyEmbedSomething() throws Exception {
- try (HSSFWorkbook wb1 = new HSSFWorkbook();
- POIFSFileSystem pptPoifs = getSamplePPT();
- POIFSFileSystem xlsPoifs = getSampleXLS()) {
- HSSFSheet sheet = wb1.createSheet();
- HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
-
- byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
- byte[] picturePPT = POIDataSamples.getSlideShowInstance().readFile("clock.jpg");
- int imgIdx = wb1.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
-
- int pptIdx = wb1.addOlePackage(pptPoifs, "Sample-PPT", "sample.ppt", "sample.ppt");
- int imgPPT = wb1.addPicture(picturePPT, HSSFWorkbook.PICTURE_TYPE_JPEG);
- int xlsIdx = wb1.addOlePackage(xlsPoifs, "Sample-XLS", "sample.xls", "sample.xls");
- int txtIdx = wb1.addOlePackage(getSampleTXT(), "Sample-TXT", "sample.txt", "sample.txt");
-
- int rowoffset = 5;
- int coloffset = 5;
-
- CreationHelper ch = wb1.getCreationHelper();
- HSSFClientAnchor anchor = (HSSFClientAnchor) ch.createClientAnchor();
- anchor.setAnchor((short) (2 + coloffset), 1 + rowoffset, 0, 0, (short) (3 + coloffset), 5 + rowoffset, 0, 0);
- anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
-
- patriarch.createObjectData(anchor, pptIdx, imgPPT);
-
- anchor = (HSSFClientAnchor) ch.createClientAnchor();
- anchor.setAnchor((short) (5 + coloffset), 1 + rowoffset, 0, 0, (short) (6 + coloffset), 5 + rowoffset, 0, 0);
- anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
-
- patriarch.createObjectData(anchor, xlsIdx, imgIdx);
-
- anchor = (HSSFClientAnchor) ch.createClientAnchor();
- anchor.setAnchor((short) (3 + coloffset), 10 + rowoffset, 0, 0, (short) (5 + coloffset), 11 + rowoffset, 0, 0);
- anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
-
- patriarch.createObjectData(anchor, txtIdx, imgIdx);
-
- anchor = (HSSFClientAnchor) ch.createClientAnchor();
- anchor.setAnchor((short) (1 + coloffset), -2 + rowoffset, 0, 0, (short) (7 + coloffset), 14 + rowoffset, 0, 0);
- anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
-
- HSSFSimpleShape circle = patriarch.createSimpleShape(anchor);
- circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
- circle.setNoFill(true);
-
- try (HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
- HSSFObjectData od = wb2.getAllEmbeddedObjects().get(0);
- Ole10Native ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory());
- bos.reset();
- pptPoifs.writeFilesystem(bos);
- assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
-
- od = wb2.getAllEmbeddedObjects().get(1);
- ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory());
- bos.reset();
- xlsPoifs.writeFilesystem(bos);
- assertArrayEquals(ole10.getDataBuffer(), bos.toByteArray());
-
- od = wb2.getAllEmbeddedObjects().get(2);
- ole10 = Ole10Native.createFromEmbeddedOleObject((DirectoryNode) od.getDirectory());
- assertArrayEquals(ole10.getDataBuffer(), getSampleTXT());
- }
- }
- }
-
- static POIFSFileSystem getSamplePPT() throws IOException {
- // scratchpad classes are not available, so we use something pre-cooked
- InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("with_textbox.ppt");
- POIFSFileSystem poifs = new POIFSFileSystem(is);
- is.close();
-
- return poifs;
- }
-
- static POIFSFileSystem getSampleXLS() throws IOException {
- UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
- try (HSSFWorkbook wb = new HSSFWorkbook()) {
- HSSFSheet sheet = wb.createSheet();
- sheet.createRow(5).createCell(2).setCellValue("yo dawg i herd you like embeddet objekts, so we put a ole in your ole so you can save a file while you save a file");
-
- wb.write(bos);
- }
-
- return new POIFSFileSystem(bos.toInputStream());
- }
-
- static byte[] getSampleTXT() {
- return "All your base are belong to us".getBytes(LocaleUtil.CHARSET_1252);
- }
-}
\ No newline at end of file
try {
fe.evaluateInCell(cellB1);
} catch (IllegalStateException e) {
- if (e.getMessage().equalsIgnoreCase("Cannot get a numeric value from a error formula cell")) {
+ if (e.getMessage().equalsIgnoreCase("Cannot get a numeric value from an error formula cell")) {
fail("Identified bug 46479a");
}
}
assertEquals(5, s.getRow(4).getPhysicalNumberOfCells());
// Shift rows 1-3 down 3 in the current one. This tests when
- // 1 row is blank. Write to a another temp file
+ // 1 row is blank. Write to another temp file
s.shiftRows(0, 2, 3);
try (Workbook wb3 = _testDataProvider.writeOutAndReadBack(wb2)) {
// Read and ensure things are where they should be