+++ /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.ss.usermodel;
-
-public interface SharedStringSource {}
+++ /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.ss.usermodel;
-
-/**
- * Allows the getting and saving of shared strings
- */
-public interface SharedStringSource {
-
-}
--- /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.xssf.model;
+
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
+
+/**
+ * Allows the getting and saving of shared strings
+ */
+public interface SharedStringSource {
+ CTRst getEntryAt(int ref);
+ int addEntry(CTRst rst);
+}
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-import org.apache.poi.ss.usermodel.SharedStringSource;
-import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
/**
sst.setSiArray(ctr);
doc.save(out, options);
}
-
}
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.RichTextString;
-import org.apache.poi.ss.usermodel.SharedStringSource;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.StylesSource;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.xssf.model.SharedStringsTable;
+import org.apache.poi.xssf.model.SharedStringSource;
import org.apache.poi.xssf.model.StylesTable;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
private final CTCell cell;
private final XSSFRow row;
private int cellNum;
- private SharedStringsTable sharedStringSource;
+ private SharedStringSource sharedStringSource;
private StylesTable stylesSource;
private POILogger logger = POILogFactory.getLogger(XSSFCell.class);
if (cell.getR() != null) {
this.cellNum = parseCellNum(cell.getR());
}
- this.sharedStringSource = (SharedStringsTable) row.getSheet().getWorkbook().getSharedStringSource();
+ this.sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource();
this.stylesSource = (StylesTable)row.getSheet().getWorkbook().getStylesSource();
}
import org.apache.poi.ss.usermodel.Palette;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.SharedStringSource;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.StylesSource;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.Control;
import org.apache.poi.xssf.model.Drawing;
+import org.apache.poi.xssf.model.SharedStringSource;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.XSSFModel;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.xssf;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+\r
+import org.apache.poi.hssf.HSSFTestDataSamples;\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+import org.apache.poi.ss.usermodel.Workbook;\r
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
+import org.openxml4j.exceptions.InvalidFormatException;\r
+import org.openxml4j.opc.Package;\r
+\r
+/**\r
+ * Centralises logic for finding/opening sample files in the src/testcases/org/apache/poi/hssf/hssf/data folder. \r
+ * \r
+ * @author Josh Micich\r
+ */\r
+public class XSSFTestDataSamples {\r
+ public static final XSSFWorkbook openSampleWorkbook(String sampleName) {\r
+ InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);\r
+ try {\r
+ Package pkg = Package.open(is);\r
+ return new XSSFWorkbook(pkg);\r
+ } catch (InvalidFormatException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IOException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+ public static <R extends Workbook> R writeOutAndReadBack(R wb) {\r
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);\r
+ Workbook result;\r
+ try {\r
+ wb.write(baos);\r
+ InputStream is = new ByteArrayInputStream(baos.toByteArray());\r
+ if (wb instanceof HSSFWorkbook) {\r
+ result = new HSSFWorkbook(is);\r
+ } else if (wb instanceof XSSFWorkbook) {\r
+ Package pkg = Package.open(is);\r
+ result = new XSSFWorkbook(pkg);\r
+ } else {\r
+ throw new RuntimeException("Unexpected workbook type (" \r
+ + wb.getClass().getName() + ")");\r
+ }\r
+ } catch (InvalidFormatException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IOException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ @SuppressWarnings("unchecked")\r
+ R r = (R) result;\r
+ return r;\r
+ }\r
+}\r
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.xssf.extractor;
-import java.io.File;
-import java.io.FileInputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import junit.framework.TestCase;
import org.apache.poi.POITextExtractor;
+import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.extractor.ExcelExtractor;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.xssf.XSSFTestDataSamples;
/**
- * Tests for XSSFExcelExtractor
+ * Tests for {@link XSSFExcelExtractor}
*/
-public class TestXSSFExcelExtractor extends TestCase {
- /**
- * A very simple file
- */
- private File xmlA;
- /**
- * A fairly complex file
- */
- private File xmlB;
-
- /**
- * A fairly simple file - ooxml
- */
- private File simpleXLSX;
- /**
- * A fairly simple file - ole2
- */
- private File simpleXLS;
+public final class TestXSSFExcelExtractor extends TestCase {
- protected void setUp() throws Exception {
- super.setUp();
-
- xmlA = new File(
- System.getProperty("HSSF.testdata.path") +
- File.separator + "sample.xlsx"
- );
- assertTrue(xmlA.exists());
- xmlB = new File(
- System.getProperty("HSSF.testdata.path") +
- File.separator + "AverageTaxRates.xlsx"
- );
- assertTrue(xmlB.exists());
-
- simpleXLSX = new File(
- System.getProperty("HSSF.testdata.path") +
- File.separator + "SampleSS.xlsx"
- );
- simpleXLS = new File(
- System.getProperty("HSSF.testdata.path") +
- File.separator + "SampleSS.xls"
- );
- assertTrue(simpleXLS.exists());
- assertTrue(simpleXLSX.exists());
+
+ private static final XSSFExcelExtractor getExtractor(String sampleName) {
+ return new XSSFExcelExtractor(XSSFTestDataSamples.openSampleWorkbook(sampleName));
}
/**
* Get text out of the simple file
*/
- public void testGetSimpleText() throws Exception {
- new XSSFExcelExtractor(xmlA.toString());
- new XSSFExcelExtractor(new XSSFWorkbook(xmlA.toString()));
-
- XSSFExcelExtractor extractor =
- new XSSFExcelExtractor(xmlA.toString());
+ public void testGetSimpleText() {
+ // a very simple file
+ XSSFExcelExtractor extractor = getExtractor("sample.xlsx");
extractor.getText();
String text = extractor.getText();
// Now without, will have text
extractor.setIncludeSheetNames(false);
text = extractor.getText();
+ String CHUNK1 =
+ "Lorem\t111\n" +
+ "ipsum\t222\n" +
+ "dolor\t333\n" +
+ "sit\t444\n" +
+ "amet\t555\n" +
+ "consectetuer\t666\n" +
+ "adipiscing\t777\n" +
+ "elit\t888\n" +
+ "Nunc\t999\n";
+ String CHUNK2 =
+ "The quick brown fox jumps over the lazy dog\n" +
+ "hello, xssf hello, xssf\n" +
+ "hello, xssf hello, xssf\n" +
+ "hello, xssf hello, xssf\n" +
+ "hello, xssf hello, xssf\n";
assertEquals(
- "Lorem\t111\n" +
- "ipsum\t222\n" +
- "dolor\t333\n" +
- "sit\t444\n" +
- "amet\t555\n" +
- "consectetuer\t666\n" +
- "adipiscing\t777\n" +
- "elit\t888\n" +
- "Nunc\t999\n" +
- "at\t4995\n" +
- "The quick brown fox jumps over the lazy dog\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n", text);
+ CHUNK1 +
+ "at\t4995\n" +
+ CHUNK2
+ , text);
// Now get formulas not their values
extractor.setFormulasNotResults(true);
text = extractor.getText();
assertEquals(
- "Lorem\t111\n" +
- "ipsum\t222\n" +
- "dolor\t333\n" +
- "sit\t444\n" +
- "amet\t555\n" +
- "consectetuer\t666\n" +
- "adipiscing\t777\n" +
- "elit\t888\n" +
- "Nunc\t999\n" +
- "at\tSUM(B1:B9)\n" +
- "The quick brown fox jumps over the lazy dog\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n", text);
+ CHUNK1 +
+ "at\tSUM(B1:B9)\n" +
+ CHUNK2, text);
// With sheet names too
extractor.setIncludeSheetNames(true);
text = extractor.getText();
assertEquals(
"Sheet1\n" +
- "Lorem\t111\n" +
- "ipsum\t222\n" +
- "dolor\t333\n" +
- "sit\t444\n" +
- "amet\t555\n" +
- "consectetuer\t666\n" +
- "adipiscing\t777\n" +
- "elit\t888\n" +
- "Nunc\t999\n" +
- "at\tSUM(B1:B9)\n" +
+ CHUNK1 +
+ "at\tSUM(B1:B9)\n" +
"rich test\n" +
- "The quick brown fox jumps over the lazy dog\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n" +
- "hello, xssf\thello, xssf\n" +
+ CHUNK2 +
"Sheet3\n"
, text);
}
- public void testGetComplexText() throws Exception {
- new XSSFExcelExtractor(xmlB.toString());
-
- XSSFExcelExtractor extractor =
- new XSSFExcelExtractor(new XSSFWorkbook(xmlB.toString()));
+ public void testGetComplexText() {
+ // A fairly complex file
+ XSSFExcelExtractor extractor = getExtractor("AverageTaxRates.xlsx");
extractor.getText();
String text = extractor.getText();
* ExcelExtractor does, when we're both passed
* the same file, just saved as xls and xlsx
*/
- public void testComparedToOLE2() throws Exception {
- XSSFExcelExtractor ooxmlExtractor =
- new XSSFExcelExtractor(simpleXLSX.toString());
+ public void testComparedToOLE2() {
+ // A fairly simple file - ooxml
+ XSSFExcelExtractor ooxmlExtractor = getExtractor("SampleSS.xlsx");
+
ExcelExtractor ole2Extractor =
- new ExcelExtractor(new HSSFWorkbook(
- new FileInputStream(simpleXLS)));
+ new ExcelExtractor(HSSFTestDataSamples.openSampleWorkbook("SampleSS.xls"));
POITextExtractor[] extractors =
new POITextExtractor[] { ooxmlExtractor, ole2Extractor };
/**
* From bug #45540
*/
- public void testHeaderFooter() throws Exception {
+ public void testHeaderFooter() {
String[] files = new String[] {
"45540_classic_Header.xlsx", "45540_form_Header.xlsx",
"45540_classic_Footer.xlsx", "45540_form_Footer.xlsx",
};
- for(String file : files) {
- File xml = new File(
- System.getProperty("HSSF.testdata.path") +
- File.separator + file
- );
- assertTrue(xml.exists());
-
- XSSFExcelExtractor extractor =
- new XSSFExcelExtractor(new XSSFWorkbook(xml.toString()));
+ for(String sampleName : files) {
+ XSSFExcelExtractor extractor = getExtractor(sampleName);
String text = extractor.getText();
- assertTrue("Unable to find expected word in text from " + file + "\n" + text, text.contains("testdoc"));
- assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
+ assertTrue("Unable to find expected word in text from " + sampleName + "\n" + text, text.contains("testdoc"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
}
}
/**
* From bug #45544
*/
- public void testComments() throws Exception {
- File xml = new File(
- System.getProperty("HSSF.testdata.path") +
- File.separator + "45544.xlsx"
- );
- assertTrue(xml.exists());
+ public void testComments() {
- XSSFExcelExtractor extractor =
- new XSSFExcelExtractor(new XSSFWorkbook(xml.toString()));
+ XSSFExcelExtractor extractor = getExtractor("45544.xlsx");
String text = extractor.getText();
// No comments there yet
\r
import java.io.ByteArrayInputStream;\r
import java.io.ByteArrayOutputStream;\r
-import java.io.File;\r
import java.io.IOException;\r
import java.util.List;\r
\r
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;\r
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.poi.xssf.XSSFTestDataSamples;\r
import org.apache.poi.xssf.usermodel.XSSFRichTextString;\r
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;\r
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;\r
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;\r
-\r
-import junit.framework.TestCase;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;\r
\r
/**\r
- * Test SharedStringsTable, the cache of strings in a workbook\r
+ * Test {@link SharedStringsTable}, the cache of strings in a workbook\r
*\r
* @author Yegor Kozlov\r
*/\r
-public class TestSharedStringsTable extends TestCase {\r
- private File xml;\r
- \r
- protected void setUp() throws Exception {\r
- xml = new File(\r
- System.getProperty("HSSF.testdata.path") +\r
- File.separator + "sample.xlsx"\r
- );\r
- assertTrue(xml.exists());\r
- }\r
-\r
- public void testCreateNew() throws Exception {\r
+public final class TestSharedStringsTable extends TestCase {\r
+\r
+ public void testCreateNew() {\r
SharedStringsTable sst = new SharedStringsTable();\r
\r
CTRst st;\r
assertEquals("Second string", new XSSFRichTextString(sst.getEntryAt(2)).toString());\r
}\r
\r
- public void testReadWrite() throws Exception {\r
- XSSFWorkbook wb = new XSSFWorkbook(xml.getPath());\r
+ public void testReadWrite() {\r
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");\r
SharedStringsTable sst1 = (SharedStringsTable)wb.getSharedStringSource();\r
\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- sst1.writeTo(out);\r
-\r
//serialize, read back and compare with the original\r
- SharedStringsTable sst2 = new SharedStringsTable(new ByteArrayInputStream(out.toByteArray()));\r
+ SharedStringsTable sst2;\r
+ try {\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ sst1.writeTo(out);\r
+ sst2 = new SharedStringsTable(new ByteArrayInputStream(out.toByteArray()));\r
+ } catch (IOException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
assertEquals(sst1.getCount(), sst2.getCount());\r
assertEquals(sst1.getUniqueCount(), sst2.getUniqueCount());\r
\r
package org.apache.poi.xssf.usermodel;
-import java.io.File;
-import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.SharedStringSource;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CommentsTable;
+import org.apache.poi.xssf.model.SharedStringSource;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
-
-public class TestXSSFCell extends TestCase {
+/**
+ * Tests for {@link XSSFCell}
+ *
+ */
+public final class TestXSSFCell extends TestCase {
private static final String TEST_C10_AUTHOR = "test C10 author";
assertEquals("Foo2", cell.getRichStringCellValue().getString());
}
- public void testSetGetStringShared() throws Exception {
+ public void testSetGetStringShared() {
XSSFRow row = createParentObjects();
XSSFCell cell = new XSSFCell(row);
/**
* Test that empty cells (no v element) return default values.
*/
- public void testGetEmptyCellValue() throws Exception {
+ public void testGetEmptyCellValue() {
XSSFRow row = createParentObjects();
XSSFCell cell = new XSSFCell(row);
cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
}
public static class DummySharedStringSource implements SharedStringSource {
- ArrayList<String> strs = new ArrayList<String>();
- public String getSharedStringAt(int idx) {
+ ArrayList<CTRst> strs = new ArrayList<CTRst>();
+ public CTRst getEntryAt(int idx) {
return strs.get(idx);
}
- public synchronized int putSharedString(String s) {
+ public synchronized int addEntry(CTRst s) {
if(strs.contains(s)) {
return strs.indexOf(s);
}
// Create C10 cell
Row row = sheet.createRow(9);
- Cell cell = row.createCell((short)2);
- Cell cell3 = row.createCell((short)3);
+ row.createCell(2);
+ row.createCell(3);
// Set a comment for C10 cell
// Create C10 cell
Row row = sheet.createRow(9);
- Cell cell = row.createCell((short)2);
- Cell cell3 = row.createCell((short)3);
+ Cell cell = row.createCell(2);
+ row.createCell(3);
// Create a comment
Comment comment = comments.addComment();
assertEquals("A1", ctWorksheet.getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
}
+
/**
* Tests that cell formatting stuff works as expected
*/
- public void testCellFormatting() throws Exception {
+ public void testCellFormatting() {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
CreationHelper creationHelper = workbook.getCreationHelper();
// Save, re-load, and test again
- File tmp = File.createTempFile("poi", "xlsx");
- FileOutputStream out = new FileOutputStream(tmp);
- workbook.write(out);
- out.close();
-
- Workbook wb2 = new XSSFWorkbook(tmp.toString());
+ Workbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
Cell c2 = wb2.getSheetAt(0).getRow(0).getCell(0);
assertEquals(new Date(654321), c2.getDateCellValue());
assertEquals("yyyy/mm/dd", c2.getCellStyle().getDataFormatString());
}
- private XSSFRow createParentObjects() {
+ private static XSSFRow createParentObjects() {
XSSFWorkbook wb = new XSSFWorkbook();
wb.setSharedStringSource(new DummySharedStringSource());
XSSFSheet sheet = new XSSFSheet(wb);
* Test to ensure we can only assign cell styles that belong
* to our workbook, and not those from other workbooks.
*/
- public void testCellStyleWorkbookMatch() throws Exception {
+ public void testCellStyleWorkbookMatch() {
XSSFWorkbook wbA = new XSSFWorkbook();
XSSFWorkbook wbB = new XSSFWorkbook();
- XSSFCellStyle styA = (XSSFCellStyle)wbA.createCellStyle();
- XSSFCellStyle styB = (XSSFCellStyle)wbB.createCellStyle();
+ XSSFCellStyle styA = wbA.createCellStyle();
+ XSSFCellStyle styB = wbB.createCellStyle();
styA.verifyBelongsToStylesSource(wbA.getStylesSource());
styB.verifyBelongsToStylesSource(wbB.getStylesSource());