@Override
public String toString() {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append("[NAME]\n");
sb.append(" .option flags = ").append(HexDump.shortToHex(field_1_option_flag)).append("\n");
Ptg[] ptgs = field_13_name_definition.getTokens();
sb.append(" .Formula (nTokens=").append(ptgs.length).append("):") .append("\n");
for (Ptg ptg : ptgs) {
- sb.append(" " + ptg).append(ptg.getRVAType()).append("\n");
+ sb.append(" ").append(ptg).append(ptg.getRVAType()).append("\n");
}
sb.append(" .Menu text = ").append(field_14_custom_menu_text).append("\n");
import java.util.Locale;
import org.apache.poi.POIXMLDocumentPart;
-import org.apache.poi.POIXMLDocumentPart.RelationPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
}
/**
- * @param part
- * @throws IOException
+ * @param part The part used to initialize the table
+ * @throws IOException If reading data from the part fails.
* @since POI 3.14-Beta1
*/
public XSSFTable(PackagePart part) throws IOException {
}
/**
- * read table XML
- * @param is
- * @throws IOException
+ * Read table XML from an {@link InputStream}
+ * @param is The stream which provides the XML data for the table.
+ * @throws IOException If reading from the stream fails
*/
public void readFrom(InputStream is) throws IOException {
try {
}
/**
- * write table XML to stream
- * @param out
- * @throws IOException
+ * write table XML to an {@link OutputStream}
+ * @param out The stream to write the XML data to
+ * @throws IOException If writing to the stream fails.
*/
public void writeTo(OutputStream out) throws IOException {
updateHeaders();
/**
* Changes the name of the Table
- * @param newName
+ * @param newName The name of the table.
*/
public void setName(String newName) {
if (newName == null) {
/**
* Changes the name of the Table
- * @param newStyleName
+ * @param newStyleName The name of the style.
* @since 3.17 beta 1
*/
public void setStyleName(String newStyleName) {
* The next call to {@link #getStartCellReference()} and
* {@link #getEndCellReference()} will synchronize the
* cell references with the underlying <code>CTTable</code>.
- * Thus, {@link #updateReferences()} is inexpensive.
+ * Thus this method is inexpensive.
*
* @since POI 3.15 beta 3
*/
* "Found unreadable content" message on startup.
*
* If calling both {@link #updateReferences()} and
- * {@link #updateHeaders()}, {@link #updateReferences()}
+ * this method, {@link #updateReferences()}
* should be called first.
*
* Note that a Table <em>must</em> have a header. To reproduce
/**
* Note: This is misleading. The Spec indicates this is true if the totals row
* has <b><i>ever</i></b> been shown, not whether or not it is currently displayed.
- * Use {@link #getTotalsRowCount()} > 0 to decide whether or not the totals row is visible.
+ * Use {@link #getTotalsRowCount()} > 0 to decide whether or not the totals row is visible.
* @since 3.15 beta 2
* @see #getTotalsRowCount()
*/
/**
* @return 0 for no totals rows, 1 for totals row shown.
- * Values > 1 are not currently used by Excel up through 2016, and the OOXML spec
+ * Values > 1 are not currently used by Excel up through 2016, and the OOXML spec
* doesn't define how they would be implemented.
* @since 3.17 beta 1
*/
/**
* @return 0 for no header rows, 1 for table headers shown.
- * Values > 1 might be used by Excel for pivot tables?
+ * Values > 1 might be used by Excel for pivot tables?
* @since 3.17 beta 1
*/
public int getHeaderRowCount() {
* Returns the bullet size that is to be used within a paragraph.
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
- * If bulletSize >= 0, then bulletSize is a percentage of the font size.
- * If bulletSize < 0, then it specifies the size in points
+ * If bulletSize >= 0, then bulletSize is a percentage of the font size.
+ * If bulletSize < 0, then it specifies the size in points
* </p>
*
* @return the bullet size
* Sets the bullet size that is to be used within a paragraph.
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
- * If bulletSize >= 0, then bulletSize is a percentage of the font size.
- * If bulletSize < 0, then it specifies the size in points
+ * If bulletSize >= 0, then bulletSize is a percentage of the font size.
+ * If bulletSize < 0, then it specifies the size in points
* </p>
*/
public void setBulletFontSize(double bulletSize){
* This element specifies the vertical line spacing that is to be used within a paragraph.
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
- * If linespacing >= 0, then linespacing is a percentage of normal line height
- * If linespacing < 0, the absolute value of linespacing is the spacing in points
+ * If linespacing >= 0, then linespacing is a percentage of normal line height
+ * If linespacing < 0, the absolute value of linespacing is the spacing in points
* </p>
* Examples:
* <pre><code>
* Returns the vertical line spacing that is to be used within a paragraph.
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
- * If linespacing >= 0, then linespacing is a percentage of normal line height.
- * If linespacing < 0, the absolute value of linespacing is the spacing in points
+ * If linespacing >= 0, then linespacing is a percentage of normal line height.
+ * If linespacing < 0, the absolute value of linespacing is the spacing in points
* </p>
*
* @return the vertical line spacing.
* Set the amount of vertical white space that will be present before the paragraph.
* This space is specified in either percentage or points:
* <p>
- * If spaceBefore >= 0, then space is a percentage of normal line height.
- * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
+ * If spaceBefore >= 0, then space is a percentage of normal line height.
+ * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
* </p>
* Examples:
* <pre><code>
* The amount of vertical white space before the paragraph
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
- * If spaceBefore >= 0, then space is a percentage of normal line height.
- * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
+ * If spaceBefore >= 0, then space is a percentage of normal line height.
+ * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
* </p>
*
* @return the vertical white space before the paragraph
* Set the amount of vertical white space that will be present after the paragraph.
* This space is specified in either percentage or points:
* <p>
- * If spaceAfter >= 0, then space is a percentage of normal line height.
- * If spaceAfter < 0, the absolute value of linespacing is the spacing in points
+ * If spaceAfter >= 0, then space is a percentage of normal line height.
+ * If spaceAfter < 0, the absolute value of linespacing is the spacing in points
* </p>
* Examples:
* <pre><code>
* The amount of vertical white space after the paragraph
* This may be specified in two different ways, percentage spacing and font point spacing:
* <p>
- * If spaceBefore >= 0, then space is a percentage of normal line height.
- * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
+ * If spaceBefore >= 0, then space is a percentage of normal line height.
+ * If spaceBefore < 0, the absolute value of linespacing is the spacing in points
* </p>
*
* @return the vertical white space after the paragraph
if (props.isSetBuChar() || props.isSetBuAutoNum()) {
setValue(true);
return true;
- } else {
+ } /*else {
// Excel treats text with buFont but no char/autonum
// as not bulleted
// Possibly the font is just used if bullets turned on again?
- }
+ }*/
}
return false;
}
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
/**
* Tests to verify that we can read a simple msg file, that is in plain/text
* format with no attachments or extra recipents.
*/
-public final class TestSimpleFileRead extends TestCase {
+public final class TestSimpleFileRead {
private final MAPIMessage mapiMessage;
/**
* Initialize this test, load up the blank.msg mapi message.
- * @throws Exception
*/
public TestSimpleFileRead() throws IOException {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
*
*/
+ @Test
public void testReadDisplayCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayCC();
String expected = "";
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
*/
+ @Test
public void testReadDisplayTo() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayTo();
String expected = "travis@overwrittenstack.com";
/**
* Test to see if we can read the From Chunk.
- * @throws ChunkNotFoundException
- *
*/
+ @Test
public void testReadDisplayFrom() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayFrom();
String expected = "Travis Ferguson";
/**
* Test to see if we can read the CC Chunk.
- * @throws ChunkNotFoundException
- *
*/
+ @Test
public void testReadDisplayBCC() throws ChunkNotFoundException {
String obtained = mapiMessage.getDisplayBCC();
String expected = "";
/**
* Check if we can read the body of the blank message, we expect "".
- *
- * @throws Exception
*/
+ @Test
public void testReadBody() throws Exception {
String obtained = mapiMessage.getTextBody();
String expected = "This is a test message.";
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
*/
+ @Test
public void testReadSubject() throws Exception {
String obtained = mapiMessage.getSubject();
String expected = "test message";
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
*/
+ @Test
public void testReadConversationTopic() throws Exception {
String obtained = mapiMessage.getConversationTopic();
TestCase.assertEquals("test message", obtained);
/**
* Check if we can read the subject line of the blank message, we expect ""
- *
- * @throws Exception
*/
+ @Test
public void testReadMessageClass() throws Exception {
MAPIMessage.MESSAGE_CLASS obtained = mapiMessage.getMessageClassEnum();
TestCase.assertEquals(MAPIMessage.MESSAGE_CLASS.NOTE, obtained);
/**
* Check the various message classes
- *
- * @throws Exception
*/
@Test
public void testReadMessageClass2() throws Exception {
for (String messageClass : new String[]{
"Appointment", "Contact", "Post", "StickyNote", "Task"
}) {
- MAPIMessage.MESSAGE_CLASS mc = new MAPIMessage(
- POIDataSamples.getHSMFInstance().getFile("msgClass"+messageClass+".msg")
- ).getMessageClassEnum();
- assertTrue( mc + " but expected " + messageClass,
- messageClass.equalsIgnoreCase(mc.toString().replaceAll("_", "")));
+ try (MAPIMessage mapiMessage = new MAPIMessage(
+ POIDataSamples.getHSMFInstance().getFile("msgClass" + messageClass + ".msg"))) {
+ MAPIMessage.MESSAGE_CLASS mc = mapiMessage.getMessageClassEnum();
+ assertTrue(mc + " but expected " + messageClass,
+ messageClass.equalsIgnoreCase(mc.toString().replaceAll("_", "")));
+ }
}
}
}
wb.close();
}
-
@Test
public void getSetMargin() throws IOException {
baseTestGetSetMargin(new double[]{0.75, 0.75, 1.0, 1.0, 0.3, 0.3});
/**
- * Test WSBboolRecord fields get set in the user model.
+ * Test WSBoolRecord fields get set in the user model.
*/
@Test
public void wsBool() throws IOException {
(WSBoolRecord) s.getSheet().findFirstRecordBySid(WSBoolRecord.sid);
// Check defaults
+ assertNotNull(record);
assertTrue(record.getAlternateExpression());
assertTrue(record.getAlternateFormula());
assertFalse(record.getAutobreaks());
sheet.setZoom(75);
assertTrue(sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid) > 0);
SCLRecord sclRecord = (SCLRecord) sheet.getSheet().findFirstRecordBySid(SCLRecord.sid);
- assertEquals(75, 100*sclRecord.getNumerator()/sclRecord.getDenominator());
+ assertNotNull(sclRecord);
+ short numerator = sclRecord.getNumerator();
+ assertEquals(75, 100* numerator /sclRecord.getDenominator());
int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid);
int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid);
// Details checks
HSSFCellStyle bs = wbSimple.getSheetAt(0).getColumnStyle(1);
+ assertNotNull(bs);
assertEquals(62, bs.getIndex());
assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", bs.getDataFormatString());
assertEquals("Calibri", bs.getFont(wbSimple).getFontName());
HSSFCellStyle cs = wbComplex.getSheetAt(0).getColumnStyle(1);
+ assertNotNull(cs);
assertEquals(62, cs.getIndex());
assertEquals("#,##0.0_ ;\\-#,##0.0\\ ", cs.getDataFormatString());
assertEquals("Arial", cs.getFont(wbComplex).getFontName());
sh = wb2.getSheetAt(0);
ish = sh.getSheet();
ObjRecord objRecord = (ObjRecord)ish.findFirstRecordBySid(ObjRecord.sid);
+ assertNotNull(objRecord);
List<SubRecord> subRecords = objRecord.getSubRecords();
assertEquals(3, subRecords.size());
assertTrue(subRecords.get(0) instanceof CommonObjectDataSubRecord );
package org.apache.poi.hssf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.io.IOException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
-import org.apache.poi.ss.usermodel.CellType;
-import org.apache.poi.ss.usermodel.Name;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.junit.Test;
+import static org.junit.Assert.*;
+
/**
* Class to test Workbook functionality
*/
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- for (int rownum = 0; rownum < 100; rownum++) {
- HSSFRow r = s.createRow(rownum);
+ populateSheet(s);
- for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- HSSFCell c = r.createCell(cellnum);
- c.setCellValue(rownum * 10000 + cellnum
- + ((( double ) rownum / 1000)
- + (( double ) cellnum / 10000)));
- c = r.createCell(cellnum + 1);
- c.setCellValue(new HSSFRichTextString("TEST"));
- }
- }
-
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
sanityChecker.checkHSSFWorkbook(wb1);
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- for (int rownum = 0; rownum < 100; rownum++) {
- HSSFRow r = s.createRow(rownum);
+ populateSheet(s);
- for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- HSSFCell c = r.createCell(cellnum);
- c.setCellValue(rownum * 10000 + cellnum
- + ((( double ) rownum / 1000)
- + (( double ) cellnum / 10000)));
- c = r.createCell(cellnum + 1);
- c.setCellValue(new HSSFRichTextString("TEST"));
- }
- }
for (int rownum = 0; rownum < 25; rownum++) {
HSSFRow r = s.getRow(rownum);
s.removeRow(r);
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- for (int rownum = 0; rownum < 100; rownum++) {
- HSSFRow r = s.createRow(rownum);
+ populateSheet(s);
- for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- HSSFCell c = r.createCell(cellnum);
- c.setCellValue(rownum * 10000 + cellnum
- + ((( double ) rownum / 1000)
- + (( double ) cellnum / 10000)));
- c = r.createCell(cellnum + 1);
- c.setCellValue(new HSSFRichTextString("TEST"));
- }
- }
s.addMergedRegion(new CellRangeAddress(0, 10, 0, 10));
s.addMergedRegion(new CellRangeAddress(30, 40, 5, 15));
sanityChecker.checkHSSFWorkbook(wb1);
confirmRegion(new CellRangeAddress(0, 10, 0, 10), r1);
confirmRegion(new CellRangeAddress(30, 40,5, 15), r2);
-
+
wb2.close();
wb1.close();
}
+ private void populateSheet(Sheet s) {
+ for (int rownum = 0; rownum < 100; rownum++) {
+ Row r = s.createRow(rownum);
+
+ for (int cellnum = 0; cellnum < 50; cellnum += 2) {
+ Cell c = r.createCell(cellnum);
+ c.setCellValue(rownum * 10000 + cellnum
+ + ((( double ) rownum / 1000)
+ + (( double ) cellnum / 10000)));
+ c = r.createCell(cellnum + 1);
+ c.setCellValue(new HSSFRichTextString("TEST"));
+ }
+ }
+ }
+
private static void confirmRegion(CellRangeAddress ra, CellRangeAddress rb) {
assertEquals(ra.getFirstRow(), rb.getFirstRow());
assertEquals(ra.getLastRow(), rb.getLastRow());
/**
* Test the backup field gets set as expected.
- * @throws IOException
*/
@Test
public void testBackupRecord() throws IOException {
* This tests is for bug [ #506658 ] Repeating output.
*
* We need to make sure only one LabelSSTRecord is produced.
- * @throws IOException
*/
@Test
public void testRepeatingBug() throws IOException {
cell.setCellValue(new HSSFRichTextString("Class"));
cell = row.createCell(2);
+ assertNotNull(cell);
RecordCounter rc = new RecordCounter();
sheet.getSheet().visitContainedRecords(rc, 0);
try {
sheet.setRepeatingColumns(cra);
fail("invalid start index is ignored");
- } catch (IllegalArgumentException e) {}
+ } catch (IllegalArgumentException e) {
+ // expected here
+ }
try {
sheet.setRepeatingRows(cra);
fail("invalid start index is ignored");
- } catch (IllegalArgumentException e) {}
+ } catch (IllegalArgumentException e) {
+ // expected here
+ }
sheet.setRepeatingColumns(null);
sheet.setRepeatingRows(null);
workbook.close();
}
- @Test
- public void testAddMergedRegionWithRegion() throws IOException {
- HSSFWorkbook wb1 = new HSSFWorkbook();
- HSSFSheet s = wb1.createSheet();
-
- for (int rownum = 0; rownum < 100; rownum++) {
- HSSFRow r = s.createRow(rownum);
-
- for (int cellnum = 0; cellnum < 50; cellnum += 2) {
- HSSFCell c = r.createCell(cellnum);
- c.setCellValue(rownum * 10000 + cellnum
- + ((( double ) rownum / 1000)
- + (( double ) cellnum / 10000)));
- c = r.createCell(cellnum + 1);
- c.setCellValue(new HSSFRichTextString("TEST"));
- }
- }
- s.addMergedRegion(new CellRangeAddress(0, 10, 0, 10));
- s.addMergedRegion(new CellRangeAddress(30, 40, 5, 15));
- sanityChecker.checkHSSFWorkbook(wb1);
- HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
-
- s = wb2.getSheetAt(0);
- CellRangeAddress r1 = s.getMergedRegion(0);
- CellRangeAddress r2 = s.getMergedRegion(1);
-
- confirmRegion(new CellRangeAddress(0, 10, 0, 10), r1);
- confirmRegion(new CellRangeAddress(30, 40,5, 15), r2);
-
- wb2.close();
- wb1.close();
- }
-
@Test
public void testBug58085RemoveSheetWithNames() throws Exception {
HSSFWorkbook wb1 = new HSSFWorkbook();
package org.apache.poi.ss.usermodel;
import org.apache.poi.common.usermodel.HyperlinkType;
-import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.util.CellAddress;
import static org.junit.Assume.assumeTrue;
/**
- * Common superclass for testing {@link HSSFCell}, org.apache.poi.xssf.usermodel.XSSFCell and
- * org.apache.poi.xssf.streaming.SXSSFCell
+ * Common superclass for testing {@link org.apache.poi.hssf.usermodel.HSSFCell},
+ * {@link org.apache.poi.xssf.usermodel.XSSFCell} and
+ * {@link org.apache.poi.xssf.streaming.SXSSFCell}
*/
public abstract class BaseTestSheet {
private static final int ROW_COUNT = 40000;