- removed deprecated and confusing methods in XSSFColor

- sonar fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1708236 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-10-12 20:43:42 +00:00
parent 7fbf591db5
commit 5fd71db914
17 changed files with 1174 additions and 946 deletions

View File

@ -149,7 +149,7 @@ public class ToHtml {
if (wb instanceof HSSFWorkbook) if (wb instanceof HSSFWorkbook)
helper = new HSSFHtmlHelper((HSSFWorkbook) wb); helper = new HSSFHtmlHelper((HSSFWorkbook) wb);
else if (wb instanceof XSSFWorkbook) else if (wb instanceof XSSFWorkbook)
helper = new XSSFHtmlHelper((XSSFWorkbook) wb); helper = new XSSFHtmlHelper();
else else
throw new IllegalArgumentException( throw new IllegalArgumentException(
"unknown workbook type: " + wb.getClass().getSimpleName()); "unknown workbook type: " + wb.getClass().getSimpleName());

View File

@ -17,13 +17,10 @@
package org.apache.poi.ss.examples.html; package org.apache.poi.ss.examples.html;
import java.util.Formatter; import java.util.Formatter;
import java.util.Map;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor; import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/** /**
* Implementation of {@link HtmlHelper} for XSSF files. * Implementation of {@link HtmlHelper} for XSSF files.
@ -31,14 +28,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* @author Ken Arnold, Industrious Media LLC * @author Ken Arnold, Industrious Media LLC
*/ */
public class XSSFHtmlHelper implements HtmlHelper { public class XSSFHtmlHelper implements HtmlHelper {
private final XSSFWorkbook wb;
private static final Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
public XSSFHtmlHelper(XSSFWorkbook wb) {
this.wb = wb;
}
public void colorStyles(CellStyle style, Formatter out) { public void colorStyles(CellStyle style, Formatter out) {
XSSFCellStyle cs = (XSSFCellStyle) style; XSSFCellStyle cs = (XSSFCellStyle) style;
styleColor(out, "background-color", cs.getFillForegroundXSSFColor()); styleColor(out, "background-color", cs.getFillForegroundXSSFColor());
@ -46,10 +35,11 @@ public class XSSFHtmlHelper implements HtmlHelper {
} }
private void styleColor(Formatter out, String attr, XSSFColor color) { private void styleColor(Formatter out, String attr, XSSFColor color) {
if (color == null || color.isAuto()) if (color == null || color.isAuto()) {
return; return;
}
byte[] rgb = color.getRgb(); byte[] rgb = color.getRGB();
if (rgb == null) { if (rgb == null) {
return; return;
} }
@ -58,7 +48,7 @@ public class XSSFHtmlHelper implements HtmlHelper {
// support it will ignore the rgba specification and stick with the // support it will ignore the rgba specification and stick with the
// solid color, which is declared first // solid color, which is declared first
out.format(" %s: #%02x%02x%02x;%n", attr, rgb[0], rgb[1], rgb[2]); out.format(" %s: #%02x%02x%02x;%n", attr, rgb[0], rgb[1], rgb[2]);
byte[] argb = color.getARgb(); byte[] argb = color.getARGB();
if (argb == null) { if (argb == null) {
return; return;
} }

File diff suppressed because it is too large Load Diff

View File

@ -20,13 +20,15 @@ package org.apache.poi.hssf.usermodel;
import java.awt.Font; import java.awt.Font;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/** /**
* Allows the user to lookup the font metrics for a particular font without * Allows the user to lookup the font metrics for a particular font without
* actually having the font on the system. The font details are loaded as a * actually having the font on the system. The font details are loaded as a
@ -35,11 +37,14 @@ import java.util.Properties;
* font. Use a multiplier for other sizes. * font. Use a multiplier for other sizes.
*/ */
final class StaticFontMetrics { final class StaticFontMetrics {
private static final POILogger LOGGER = POILogFactory.getLogger(StaticFontMetrics.class);
/** The font metrics property file we're using */ /** The font metrics property file we're using */
private static Properties fontMetricsProps; private static Properties fontMetricsProps;
/** Our cache of font details we've already looked up */ /** Our cache of font details we've already looked up */
private static Map<String, FontDetails> fontDetailsMap = new HashMap<String, FontDetails>(); private static final Map<String, FontDetails> fontDetailsMap = new HashMap<String, FontDetails>();
private StaticFontMetrics() {}
/** /**
* Retrieves the fake font details for a given font. * Retrieves the fake font details for a given font.
* *
@ -47,47 +52,15 @@ final class StaticFontMetrics {
* the font to lookup. * the font to lookup.
* @return the fake font. * @return the fake font.
*/ */
public static FontDetails getFontDetails(Font font) { public static synchronized FontDetails getFontDetails(Font font) {
// If we haven't already identified out font metrics file, // If we haven't already identified out font metrics file,
// figure out which one to use and load it // figure out which one to use and load it
if (fontMetricsProps == null) { if (fontMetricsProps == null) {
InputStream metricsIn = null; try {
try { fontMetricsProps = loadMetrics();
fontMetricsProps = new Properties(); } catch (IOException e) {
throw new RuntimeException("Could not load font metrics", e);
// Check to see if the font metric file was specified }
// as a system property
String propFileName = null;
try {
propFileName = System.getProperty("font.metrics.filename");
} catch (SecurityException e) {
}
if (propFileName != null) {
File file = new File(propFileName);
if (!file.exists())
throw new FileNotFoundException(
"font_metrics.properties not found at path "
+ file.getAbsolutePath());
metricsIn = new FileInputStream(file);
} else {
// Use the built-in font metrics file off the classpath
metricsIn = FontDetails.class.getResourceAsStream("/font_metrics.properties");
if (metricsIn == null)
throw new FileNotFoundException(
"font_metrics.properties not found in classpath");
}
fontMetricsProps.load(metricsIn);
} catch (IOException e) {
throw new RuntimeException("Could not load font metrics: " + e.getMessage());
} finally {
if (metricsIn != null) {
try {
metricsIn.close();
} catch (IOException ignore) {
}
}
}
} }
// Grab the base name of the font they've asked about // Grab the base name of the font they've asked about
@ -97,28 +70,73 @@ final class StaticFontMetrics {
// Others have different font instances for bold etc // Others have different font instances for bold etc
// (eg font.dialog.plain.* vs font.Californian FB Bold.*) // (eg font.dialog.plain.* vs font.Californian FB Bold.*)
String fontStyle = ""; String fontStyle = "";
if (font.isPlain()) if (font.isPlain()) {
fontStyle += "plain"; fontStyle += "plain";
if (font.isBold()) }
if (font.isBold()) {
fontStyle += "bold"; fontStyle += "bold";
if (font.isItalic()) }
if (font.isItalic()) {
fontStyle += "italic"; fontStyle += "italic";
}
// Do we have a definition for this font with just the name? // Do we have a definition for this font with just the name?
// If not, check with the font style added // If not, check with the font style added
if (fontMetricsProps.get(FontDetails.buildFontHeightProperty(fontName)) == null String fontHeight = FontDetails.buildFontHeightProperty(fontName);
&& fontMetricsProps.get(FontDetails.buildFontHeightProperty(fontName + "." String styleHeight = FontDetails.buildFontHeightProperty(fontName + "." + fontStyle);
+ fontStyle)) != null) {
if (fontMetricsProps.get(fontHeight) == null
&& fontMetricsProps.get(styleHeight) != null) {
// Need to add on the style to the font name // Need to add on the style to the font name
fontName += "." + fontStyle; fontName += "." + fontStyle;
} }
// Get the details on this font // Get the details on this font
if (fontDetailsMap.get(fontName) == null) { FontDetails fontDetails = fontDetailsMap.get(fontName);
FontDetails fontDetails = FontDetails.create(fontName, fontMetricsProps); if (fontDetails == null) {
fontDetails = FontDetails.create(fontName, fontMetricsProps);
fontDetailsMap.put(fontName, fontDetails); fontDetailsMap.put(fontName, fontDetails);
return fontDetails;
} }
return fontDetailsMap.get(fontName); return fontDetails;
}
private static Properties loadMetrics() throws IOException {
// Check to see if the font metric file was specified
// as a system property
File propFile = null;
try {
String propFileName = System.getProperty("font.metrics.filename");
if (propFileName != null) {
propFile = new File(propFileName);
if (!propFile.exists()) {
LOGGER.log(POILogger.WARN, "font_metrics.properties not found at path "+propFile.getAbsolutePath());
propFile = null;
}
}
} catch (SecurityException e) {
LOGGER.log(POILogger.WARN, "Can't access font.metrics.filename system property", e);
}
InputStream metricsIn = null;
try {
if (propFile != null) {
metricsIn = new FileInputStream(propFile);
} else {
// Use the built-in font metrics file off the classpath
metricsIn = FontDetails.class.getResourceAsStream("/font_metrics.properties");
if (metricsIn == null) {
String err = "font_metrics.properties not found in classpath";
throw new IOException(err);
}
}
Properties props = new Properties();
props.load(metricsIn);
return props;
} finally {
if (metricsIn != null) {
metricsIn.close();
}
}
} }
} }

View File

@ -99,31 +99,33 @@ public class FractionFormat extends Format {
public String format(Number num) { public String format(Number num) {
double doubleValue = num.doubleValue(); final double doubleValue = num.doubleValue();
boolean isNeg = (doubleValue < 0.0f) ? true : false; final boolean isNeg = (doubleValue < 0.0f) ? true : false;
double absDoubleValue = Math.abs(doubleValue); final double absDoubleValue = Math.abs(doubleValue);
double wholePart = Math.floor(absDoubleValue); final double wholePart = Math.floor(absDoubleValue);
double decPart = absDoubleValue - wholePart; final double decPart = absDoubleValue - wholePart;
if (wholePart + decPart == 0) { if (wholePart + decPart == 0) {
return "0"; return "0";
} }
//if the absolute value is smaller than 1 over the exact or maxDenom // if the absolute value is smaller than 1 over the exact or maxDenom
//you can stop here and return "0" // you can stop here and return "0"
if (absDoubleValue < (1/Math.max(exactDenom, maxDenom))){ // reciprocal is result of an int devision ... and so it's nearly always 0
return "0"; // double reciprocal = 1/Math.max(exactDenom, maxDenom);
} // if (absDoubleValue < reciprocal) {
// return "0";
// }
//this is necessary to prevent overflow in the maxDenom calculation //this is necessary to prevent overflow in the maxDenom calculation
if (wholePart+(int)decPart == wholePart+decPart){ if (Double.compare(decPart, 0) == 0){
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (isNeg){ if (isNeg){
sb.append("-"); sb.append("-");
} }
sb.append(Integer.toString((int)wholePart)); sb.append((int)wholePart);
return sb.toString(); return sb.toString();
} }

View File

@ -23,4 +23,8 @@ public final class InvalidFormatException extends OpenXML4JException{
public InvalidFormatException(String message){ public InvalidFormatException(String message){
super(message); super(message);
} }
public InvalidFormatException(String message, Throwable cause){
super(message,cause);
}
} }

View File

@ -31,4 +31,8 @@ public class OpenXML4JException extends Exception {
public OpenXML4JException(String msg) { public OpenXML4JException(String msg) {
super(msg); super(msg);
} }
public OpenXML4JException(String msg, Throwable cause) {
super(msg, cause);
}
} }

View File

@ -21,7 +21,6 @@ import java.io.ByteArrayOutputStream;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -33,6 +32,7 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -92,7 +92,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
/** /**
* Part marshallers by content type. * Part marshallers by content type.
*/ */
protected Hashtable<ContentType, PartMarshaller> partMarshallers; protected Map<ContentType, PartMarshaller> partMarshallers;
/** /**
* Default part marshaller. * Default part marshaller.
@ -102,7 +102,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
/** /**
* Part unmarshallers by content type. * Part unmarshallers by content type.
*/ */
protected Hashtable<ContentType, PartUnmarshaller> partUnmarshallers; protected Map<ContentType, PartUnmarshaller> partUnmarshallers;
/** /**
* Core package properties. * Core package properties.
@ -167,7 +167,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
throw new OpenXML4JRuntimeException( throw new OpenXML4JRuntimeException(
"Package.init() : this exception should never happen, " + "Package.init() : this exception should never happen, " +
"if you read this message please send a mail to the developers team. : " + "if you read this message please send a mail to the developers team. : " +
e.getMessage() e.getMessage(),
e
); );
} }
} }
@ -215,12 +216,14 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
*/ */
public static OPCPackage open(String path, PackageAccess access) public static OPCPackage open(String path, PackageAccess access)
throws InvalidFormatException { throws InvalidFormatException {
if (path == null || "".equals(path.trim())) if (path == null || "".equals(path.trim())) {
throw new IllegalArgumentException("'path' must be given"); throw new IllegalArgumentException("'path' must be given");
}
File file = new File(path); File file = new File(path);
if (file.exists() && file.isDirectory()) if (file.exists() && file.isDirectory()) {
throw new IllegalArgumentException("path must not be a directory"); throw new IllegalArgumentException("path must not be a directory");
}
OPCPackage pack = new ZipPackage(path, access); OPCPackage pack = new ZipPackage(path, access);
if (pack.partList == null && access != PackageAccess.WRITE) { if (pack.partList == null && access != PackageAccess.WRITE) {
@ -318,8 +321,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* @return A newly created PackageBase ready to use. * @return A newly created PackageBase ready to use.
*/ */
public static OPCPackage create(File file) { public static OPCPackage create(File file) {
if (file == null || (file.exists() && file.isDirectory())) if (file == null || (file.exists() && file.isDirectory())) {
throw new IllegalArgumentException("file"); throw new IllegalArgumentException("file");
}
if (file.exists()) { if (file.exists()) {
throw new InvalidOperationException( throw new InvalidOperationException(
@ -457,8 +461,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
*/ */
public void addThumbnail(String path) throws IOException { public void addThumbnail(String path) throws IOException {
// Check parameter // Check parameter
if ("".equals(path)) if ("".equals(path)) {
throw new IllegalArgumentException("path"); throw new IllegalArgumentException("path");
}
// Get the filename from the path // Get the filename from the path
String filename = path String filename = path
@ -478,7 +483,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
+ path.substring(path.lastIndexOf(".") + 1)); + path.substring(path.lastIndexOf(".") + 1));
} catch (InvalidFormatException e2) { } catch (InvalidFormatException e2) {
throw new InvalidOperationException( throw new InvalidOperationException(
"Can't add a thumbnail file named '" + filename + "'"); "Can't add a thumbnail file named '" + filename + "'", e2);
} }
} }
@ -511,9 +516,10 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* @see org.apache.poi.openxml4j.opc.PackageAccess * @see org.apache.poi.openxml4j.opc.PackageAccess
*/ */
void throwExceptionIfReadOnly() throws InvalidOperationException { void throwExceptionIfReadOnly() throws InvalidOperationException {
if (packageAccess == PackageAccess.READ) if (packageAccess == PackageAccess.READ) {
throw new InvalidOperationException( throw new InvalidOperationException(
"Operation not allowed, document open in read only mode!"); "Operation not allowed, document open in read only mode!");
}
} }
/** /**
@ -526,9 +532,10 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* @see org.apache.poi.openxml4j.opc.PackageAccess * @see org.apache.poi.openxml4j.opc.PackageAccess
*/ */
void throwExceptionIfWriteOnly() throws InvalidOperationException { void throwExceptionIfWriteOnly() throws InvalidOperationException {
if (packageAccess == PackageAccess.WRITE) if (packageAccess == PackageAccess.WRITE) {
throw new InvalidOperationException( throw new InvalidOperationException(
"Operation not allowed, document open in write only mode!"); "Operation not allowed, document open in write only mode!");
}
} }
/** /**
@ -557,8 +564,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
public PackagePart getPart(PackagePartName partName) { public PackagePart getPart(PackagePartName partName) {
throwExceptionIfWriteOnly(); throwExceptionIfWriteOnly();
if (partName == null) if (partName == null) {
throw new IllegalArgumentException("partName"); throw new IllegalArgumentException("partName");
}
// If the partlist is null, then we parse the package. // If the partlist is null, then we parse the package.
if (partList == null) { if (partList == null) {
@ -581,8 +589,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
public ArrayList<PackagePart> getPartsByContentType(String contentType) { public ArrayList<PackagePart> getPartsByContentType(String contentType) {
ArrayList<PackagePart> retArr = new ArrayList<PackagePart>(); ArrayList<PackagePart> retArr = new ArrayList<PackagePart>();
for (PackagePart part : partList.values()) { for (PackagePart part : partList.values()) {
if (part.getContentType().equals(contentType)) if (part.getContentType().equals(contentType)) {
retArr.add(part); retArr.add(part);
}
} }
Collections.sort(retArr); Collections.sort(retArr);
return retArr; return retArr;
@ -599,8 +608,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
*/ */
public ArrayList<PackagePart> getPartsByRelationshipType( public ArrayList<PackagePart> getPartsByRelationshipType(
String relationshipType) { String relationshipType) {
if (relationshipType == null) if (relationshipType == null) {
throw new IllegalArgumentException("relationshipType"); throw new IllegalArgumentException("relationshipType");
}
ArrayList<PackagePart> retArr = new ArrayList<PackagePart>(); ArrayList<PackagePart> retArr = new ArrayList<PackagePart>();
for (PackageRelationship rel : getRelationshipsByType(relationshipType)) { for (PackageRelationship rel : getRelationshipsByType(relationshipType)) {
PackagePart part = getPart(rel); PackagePart part = getPart(rel);
@ -686,13 +696,14 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
PackagePart[] parts = this.getPartsImpl(); PackagePart[] parts = this.getPartsImpl();
this.partList = new PackagePartCollection(); this.partList = new PackagePartCollection();
for (PackagePart part : parts) { for (PackagePart part : parts) {
if (partList.containsKey(part._partName)) if (partList.containsKey(part._partName)) {
throw new InvalidFormatException( throw new InvalidFormatException(
"A part with the name '" + "A part with the name '" +
part._partName + part._partName +
"' already exist : Packages shall not contain equivalent " + "' already exist : Packages shall not contain equivalent " +
"part names and package implementers shall neither create " + "part names and package implementers shall neither create " +
"nor recognize packages with equivalent part names. [M1.12]"); "nor recognize packages with equivalent part names. [M1.12]");
}
// Check OPC compliance rule M4.1 // Check OPC compliance rule M4.1
if (part.getContentType().equals( if (part.getContentType().equals(
@ -729,13 +740,13 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
+ part._partName); + part._partName);
continue; continue;
} catch (InvalidOperationException invoe) { } catch (InvalidOperationException invoe) {
throw new InvalidFormatException(invoe.getMessage()); throw new InvalidFormatException(invoe.getMessage(), invoe);
} }
} else { } else {
try { try {
partList.put(part._partName, part); partList.put(part._partName, part);
} catch (InvalidOperationException e) { } catch (InvalidOperationException e) {
throw new InvalidFormatException(e.getMessage()); throw new InvalidFormatException(e.getMessage(), e);
} }
} }
} }
@ -813,9 +824,10 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
// Note - POI will read files with more than one Core Properties, which // Note - POI will read files with more than one Core Properties, which
// Office sometimes produces, but is strict on generation // Office sometimes produces, but is strict on generation
if (contentType.equals(ContentTypes.CORE_PROPERTIES_PART)) { if (contentType.equals(ContentTypes.CORE_PROPERTIES_PART)) {
if (this.packageProperties != null) if (this.packageProperties != null) {
throw new InvalidOperationException( throw new InvalidOperationException(
"OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !"); "OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !");
}
} }
/* End check OPC compliance */ /* End check OPC compliance */
@ -929,8 +941,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
*/ */
public void removePart(PackagePartName partName) { public void removePart(PackagePartName partName) {
throwExceptionIfReadOnly(); throwExceptionIfReadOnly();
if (partName == null || !this.containPart(partName)) if (partName == null || !this.containPart(partName)) {
throw new IllegalArgumentException("partName"); throw new IllegalArgumentException("partName");
}
// Delete the specified part from the package. // Delete the specified part from the package.
if (this.partList.containsKey(partName)) { if (this.partList.containsKey(partName)) {
@ -964,8 +977,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
clearRelationships(); clearRelationships();
} else if (containPart(sourcePartName)) { } else if (containPart(sourcePartName)) {
PackagePart part = getPart(sourcePartName); PackagePart part = getPart(sourcePartName);
if (part != null) if (part != null) {
part.clearRelationships(); part.clearRelationships();
}
} }
} }
@ -1019,8 +1033,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* Name of the part to delete * Name of the part to delete
*/ */
public void deletePart(PackagePartName partName) { public void deletePart(PackagePartName partName) {
if (partName == null) if (partName == null) {
throw new IllegalArgumentException("partName"); throw new IllegalArgumentException("partName");
}
// Remove the part // Remove the part
this.removePart(partName); this.removePart(partName);
@ -1039,8 +1054,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* Name of the part to delete * Name of the part to delete
*/ */
public void deletePartRecursive(PackagePartName partName) { public void deletePartRecursive(PackagePartName partName) {
if (partName == null || !this.containPart(partName)) if (partName == null || !this.containPart(partName)) {
throw new IllegalArgumentException("partName"); throw new IllegalArgumentException("partName");
}
PackagePart partToDelete = this.getPart(partName); PackagePart partToDelete = this.getPart(partName);
// Remove the part // Remove the part
@ -1064,8 +1080,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
// Remove the relationships part // Remove the relationships part
PackagePartName relationshipPartName = PackagingURIHelper PackagePartName relationshipPartName = PackagingURIHelper
.getRelationshipPartName(partName); .getRelationshipPartName(partName);
if (relationshipPartName != null && containPart(relationshipPartName)) if (relationshipPartName != null && containPart(relationshipPartName)) {
this.removePart(relationshipPartName); this.removePart(relationshipPartName);
}
} }
/** /**
@ -1115,9 +1132,10 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
// relationship for a package to be an error. If present, the // relationship for a package to be an error. If present, the
// relationship shall target the Core Properties part. // relationship shall target the Core Properties part.
if (relationshipType.equals(PackageRelationshipTypes.CORE_PROPERTIES) if (relationshipType.equals(PackageRelationshipTypes.CORE_PROPERTIES)
&& this.packageProperties != null) && this.packageProperties != null) {
throw new InvalidOperationException( throw new InvalidOperationException(
"OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead."); "OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.");
}
/* /*
* Check rule M1.25: The Relationships part shall not have relationships * Check rule M1.25: The Relationships part shall not have relationships
@ -1311,8 +1329,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
*/ */
public boolean isRelationshipExists(PackageRelationship rel) { public boolean isRelationshipExists(PackageRelationship rel) {
for (PackageRelationship r : this.getRelationships()) { for (PackageRelationship r : this.getRelationships()) {
if (r == rel) if (r == rel) {
return true; return true;
}
} }
return false; return false;
} }
@ -1360,7 +1379,11 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* The content type associated with the marshaller to remove. * The content type associated with the marshaller to remove.
*/ */
public void removeMarshaller(String contentType) { public void removeMarshaller(String contentType) {
partMarshallers.remove(contentType); try {
partMarshallers.remove(new ContentType(contentType));
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
}
} }
/** /**
@ -1370,7 +1393,11 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* The content type associated with the unmarshaller to remove. * The content type associated with the unmarshaller to remove.
*/ */
public void removeUnmarshaller(String contentType) { public void removeUnmarshaller(String contentType) {
partUnmarshallers.remove(contentType); try {
partUnmarshallers.remove(new ContentType(contentType));
} catch (InvalidFormatException e) {
throw new RuntimeException(e);
}
} }
/* Accesseurs */ /* Accesseurs */
@ -1403,8 +1430,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* @see #save(OutputStream) * @see #save(OutputStream)
*/ */
public void save(File targetFile) throws IOException { public void save(File targetFile) throws IOException {
if (targetFile == null) if (targetFile == null) {
throw new IllegalArgumentException("targetFile"); throw new IllegalArgumentException("targetFile");
}
this.throwExceptionIfReadOnly(); this.throwExceptionIfReadOnly();
@ -1421,13 +1449,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
fos = new FileOutputStream(targetFile); fos = new FileOutputStream(targetFile);
} catch (FileNotFoundException e) {
throw new IOException(e.getLocalizedMessage());
}
try {
this.save(fos); this.save(fos);
} finally { } finally {
fos.close(); if (fos != null) fos.close();
} }
} }

View File

@ -93,13 +93,16 @@ public class XSSFColor extends ExtendedColor {
* A boolean value indicating if the ctColor has a tint or not * A boolean value indicating if the ctColor has a tint or not
*/ */
public boolean hasTint() { public boolean hasTint() {
if (! ctColor.isSetRgb()) return false; if (! ctColor.isSetRgb()) {
return false;
}
return ctColor.getRgb().length == 4; return ctColor.getRgb().length == 4;
} }
/** /**
* Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors. * Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.
*/ */
@Override
public short getIndex() { public short getIndex() {
return (short)ctColor.getIndexed(); return (short)ctColor.getIndexed();
} }
@ -121,9 +124,12 @@ public class XSSFColor extends ExtendedColor {
* Standard Red Green Blue ctColor value (RGB). * Standard Red Green Blue ctColor value (RGB).
* If there was an A (Alpha) value, it will be stripped. * If there was an A (Alpha) value, it will be stripped.
*/ */
@Override
public byte[] getRGB() { public byte[] getRGB() {
byte[] rgb = getRGBOrARGB(); byte[] rgb = getRGBOrARGB();
if(rgb == null) return null; if(rgb == null) {
return null;
}
if(rgb.length == 4) { if(rgb.length == 4) {
// Need to trim off the alpha // Need to trim off the alpha
@ -134,19 +140,16 @@ public class XSSFColor extends ExtendedColor {
return rgb; return rgb;
} }
} }
/**
* @deprecated use {@link #getRGB()}
*/
public byte[] getRgb() {
return getRGB();
}
/** /**
* Standard Alpha Red Green Blue ctColor value (ARGB). * Standard Alpha Red Green Blue ctColor value (ARGB).
*/ */
@Override
public byte[] getARGB() { public byte[] getARGB() {
byte[] rgb = getRGBOrARGB(); byte[] rgb = getRGBOrARGB();
if(rgb == null) return null; if(rgb == null) {
return null;
}
if(rgb.length == 3) { if(rgb.length == 3) {
// Pad with the default Alpha // Pad with the default Alpha
@ -158,34 +161,16 @@ public class XSSFColor extends ExtendedColor {
return rgb; return rgb;
} }
} }
/**
* @deprecated Use {@link #getARGB()}
*/
public byte[] getARgb() {
return getARGB();
}
@Override
protected byte[] getStoredRBG() { protected byte[] getStoredRBG() {
return ctColor.getRgb(); return ctColor.getRgb();
} }
/**
* Standard Red Green Blue ctColor value (RGB) with applied tint.
* Alpha values are ignored.
*/
public byte[] getRgbWithTint() {
return getRGBWithTint();
}
/**
* Standard Alpha Red Green Blue ctColor value (ARGB).
*/
public void setRgb(byte[] rgb) {
setRGB(rgb);
}
/** /**
* Standard Alpha Red Green Blue ctColor value (ARGB). * Standard Alpha Red Green Blue ctColor value (ARGB).
*/ */
@Override
public void setRGB(byte[] rgb) { public void setRGB(byte[] rgb) {
ctColor.setRgb(rgb); ctColor.setRgb(rgb);
} }
@ -194,6 +179,7 @@ public class XSSFColor extends ExtendedColor {
* Index into the <clrScheme> collection, referencing a particular <sysClr> or * Index into the <clrScheme> collection, referencing a particular <sysClr> or
* <srgbClr> value expressed in the Theme part. * <srgbClr> value expressed in the Theme part.
*/ */
@Override
public int getTheme() { public int getTheme() {
return (int)ctColor.getTheme(); return (int)ctColor.getTheme();
} }
@ -247,6 +233,7 @@ public class XSSFColor extends ExtendedColor {
* *
* @return the tint value * @return the tint value
*/ */
@Override
public double getTint() { public double getTint() {
return ctColor.getTint(); return ctColor.getTint();
} }
@ -292,6 +279,7 @@ public class XSSFColor extends ExtendedColor {
* *
* @param tint the tint value * @param tint the tint value
*/ */
@Override
public void setTint(double tint) { public void setTint(double tint) {
ctColor.setTint(tint); ctColor.setTint(tint);
} }
@ -313,12 +301,16 @@ public class XSSFColor extends ExtendedColor {
return (XSSFColor)color; return (XSSFColor)color;
} }
@Override
public int hashCode(){ public int hashCode(){
return ctColor.toString().hashCode(); return ctColor.toString().hashCode();
} }
@Override
public boolean equals(Object o){ public boolean equals(Object o){
if(o == null || !(o instanceof XSSFColor)) return false; if(!(o instanceof XSSFColor)) {
return false;
}
XSSFColor cf = (XSSFColor)o; XSSFColor cf = (XSSFColor)o;
return ctColor.toString().equals(cf.getCTColor().toString()); return ctColor.toString().equals(cf.getCTColor().toString());

View File

@ -50,7 +50,9 @@ import org.apache.poi.POIXMLProperties;
import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
@ -62,7 +64,29 @@ import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.Function; import org.apache.poi.ss.formula.functions.Function;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
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.DataFormat;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.DateUtil;
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;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.CellReference;
@ -74,6 +98,7 @@ import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CalculationChain; import org.apache.poi.xssf.model.CalculationChain;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.apache.xmlbeans.XmlException;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcCell; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcCell;
@ -93,7 +118,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* open resulting file in Excel to check results! * open resulting file in Excel to check results!
*/ */
@Test @Test
public void bug15375_2() throws Exception { public void bug15375_2() throws IOException {
bug15375(1000); bug15375(1000);
} }
@ -102,7 +127,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* the wrong sheet name * the wrong sheet name
*/ */
@Test @Test
public void bug45430() throws Exception { public void bug45430() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("45430.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("45430.xlsx");
assertFalse(wb.isMacroEnabled()); assertFalse(wb.isMacroEnabled());
assertEquals(3, wb.getNumberOfNames()); assertEquals(3, wb.getNumberOfNames());
@ -133,9 +158,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
/** /**
* We should carry vba macros over after save * We should carry vba macros over after save
* @throws InvalidFormatException
*/ */
@Test @Test
public void bug45431() throws Exception { public void bug45431() throws IOException, InvalidFormatException {
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("45431.xlsm"); XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("45431.xlsm");
OPCPackage pkg1 = wb1.getPackage(); OPCPackage pkg1 = wb1.getPackage();
assertTrue(wb1.isMacroEnabled()); assertTrue(wb1.isMacroEnabled());
@ -190,7 +216,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug47504() throws Exception { public void bug47504() throws IOException {
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("47504.xlsx"); XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("47504.xlsx");
assertEquals(1, wb1.getNumberOfSheets()); assertEquals(1, wb1.getNumberOfSheets());
XSSFSheet sh = wb1.getSheetAt(0); XSSFSheet sh = wb1.getSheetAt(0);
@ -218,7 +244,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* read the file despite the naughtyness * read the file despite the naughtyness
*/ */
@Test @Test
public void bug49020() throws Exception { public void bug49020() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("BrNotClosed.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("BrNotClosed.xlsx");
wb.close(); wb.close();
} }
@ -227,7 +253,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* ensure that CTPhoneticPr is loaded by the ooxml test suite so that it is included in poi-ooxml-schemas * ensure that CTPhoneticPr is loaded by the ooxml test suite so that it is included in poi-ooxml-schemas
*/ */
@Test @Test
public void bug49325() throws Exception { public void bug49325() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49325.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49325.xlsx");
CTWorksheet sh = wb.getSheetAt(0).getCTWorksheet(); CTWorksheet sh = wb.getSheetAt(0).getCTWorksheet();
assertNotNull(sh.getPhoneticPr()); assertNotNull(sh.getPhoneticPr());
@ -239,7 +265,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* should return that sheet index properly * should return that sheet index properly
*/ */
@Test @Test
public void bug48923() throws Exception { public void bug48923() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48923.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48923.xlsx");
assertEquals(4, wb.getNumberOfNames()); assertEquals(4, wb.getNumberOfNames());
@ -280,7 +306,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* TODO: delete this test case when MROUND and VAR are implemented * TODO: delete this test case when MROUND and VAR are implemented
*/ */
@Test @Test
public void bug48539() throws Exception { public void bug48539() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48539.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48539.xlsx");
try { try {
assertEquals(3, wb.getNumberOfSheets()); assertEquals(3, wb.getNumberOfSheets());
@ -325,7 +351,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* a theme is used * a theme is used
*/ */
@Test @Test
public void bug48779() throws Exception { public void bug48779() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0); XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
XSSFCellStyle cs = cell.getCellStyle(); XSSFCellStyle cs = cell.getCellStyle();
@ -363,7 +389,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* for integers * for integers
*/ */
@Test @Test
public void bug47490() throws Exception { public void bug47490() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("GeneralFormatTests.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("GeneralFormatTests.xlsx");
Sheet s = wb.getSheetAt(1); Sheet s = wb.getSheetAt(1);
Row r; Row r;
@ -402,7 +428,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* The OPC spec tolerates both of these peculiarities, so does POI * The OPC spec tolerates both of these peculiarities, so does POI
*/ */
@Test @Test
public void bug49609() throws Exception { public void bug49609() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49609.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49609.xlsx");
assertEquals("FAM", wb.getSheetName(0)); assertEquals("FAM", wb.getSheetName(0));
assertEquals("Cycle", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue()); assertEquals("Cycle", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue());
@ -411,7 +437,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug49783() throws Exception { public void bug49783() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("49783.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("49783.xlsx");
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
@ -445,7 +471,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* with something like "helloworld" ! * with something like "helloworld" !
*/ */
@Test @Test
public void bug49941() throws Exception { public void bug49941() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook(); XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet s = wb1.createSheet(); XSSFSheet s = wb1.createSheet();
XSSFRow r = s.createRow(0); XSSFRow r = s.createRow(0);
@ -524,7 +550,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Repeatedly writing the same file which has styles * Repeatedly writing the same file which has styles
*/ */
@Test @Test
public void bug49940() throws Exception { public void bug49940() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("styles.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("styles.xlsx");
assertEquals(3, wb.getNumberOfSheets()); assertEquals(3, wb.getNumberOfSheets());
assertEquals(10, wb.getStylesSource().getNumCellStyles()); assertEquals(10, wb.getStylesSource().getNumCellStyles());
@ -554,7 +580,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* entry. * entry.
*/ */
@Test @Test
public void bug49966() throws Exception { public void bug49966() throws IOException {
XSSFWorkbook wb1 = XSSFTestDataSamples XSSFWorkbook wb1 = XSSFTestDataSamples
.openSampleWorkbook("shared_formulas.xlsx"); .openSampleWorkbook("shared_formulas.xlsx");
XSSFSheet sheet = wb1.getSheetAt(0); XSSFSheet sheet = wb1.getSheetAt(0);
@ -610,7 +636,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug49966Row() throws Exception { public void bug49966Row() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples XSSFWorkbook wb = XSSFTestDataSamples
.openSampleWorkbook("shared_formulas.xlsx"); .openSampleWorkbook("shared_formulas.xlsx");
XSSFSheet sheet = wb.getSheetAt(0); XSSFSheet sheet = wb.getSheetAt(0);
@ -630,7 +656,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug49156() throws Exception { public void bug49156() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("49156.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("49156.xlsx");
FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
@ -649,7 +675,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Newlines are valid characters in a formula * Newlines are valid characters in a formula
*/ */
@Test @Test
public void bug50440And51875() throws Exception { public void bug50440And51875() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("NewlineInFormulas.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("NewlineInFormulas.xlsx");
Sheet s = wb.getSheetAt(0); Sheet s = wb.getSheetAt(0);
Cell c = s.getRow(0).getCell(0); Cell c = s.getRow(0).getCell(0);
@ -676,7 +702,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Moving a cell comment from one cell to another * Moving a cell comment from one cell to another
*/ */
@Test @Test
public void bug50795() throws Exception { public void bug50795() throws IOException {
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("50795.xlsx"); XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("50795.xlsx");
XSSFSheet sheet = wb1.getSheetAt(0); XSSFSheet sheet = wb1.getSheetAt(0);
XSSFRow row = sheet.getRow(0); XSSFRow row = sheet.getRow(0);
@ -738,7 +764,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* For those cases, ensure we don't break on reading the colour * For those cases, ensure we don't break on reading the colour
*/ */
@Test @Test
public void bug50299() throws Exception { public void bug50299() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx");
// Check all the colours // Check all the colours
@ -769,9 +795,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
/** /**
* Excel .xls style indexed colours in a .xlsx file * Excel .xls style indexed colours in a .xlsx file
*/ */
@SuppressWarnings("deprecation")
@Test @Test
public void bug50786() throws Exception { public void bug50786() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50786-indexed_colours.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50786-indexed_colours.xlsx");
XSSFSheet s = wb.getSheetAt(0); XSSFSheet s = wb.getSheetAt(0);
XSSFRow r = s.getRow(2); XSSFRow r = s.getRow(2);
@ -784,7 +809,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
XSSFCellStyle cs = c.getCellStyle(); XSSFCellStyle cs = c.getCellStyle();
assertEquals(42, cs.getFillForegroundColor()); assertEquals(42, cs.getFillForegroundColor());
assertEquals(42, cs.getFillForegroundColorColor().getIndexed()); assertEquals(42, cs.getFillForegroundColorColor().getIndexed());
assertNotNull(cs.getFillForegroundColorColor().getRgb()); assertNotNull(cs.getFillForegroundColorColor().getRGB());
assertEquals("FFCCFFCC", cs.getFillForegroundColorColor().getARGBHex()); assertEquals("FFCCFFCC", cs.getFillForegroundColorColor().getARGBHex());
wb.close(); wb.close();
} }
@ -794,7 +819,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* should still be able to get colours * should still be able to get colours
*/ */
@Test @Test
public void bug50846() throws Exception { public void bug50846() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50846-border_colours.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50846-border_colours.xlsx");
XSSFSheet sheet = wb.getSheetAt(0); XSSFSheet sheet = wb.getSheetAt(0);
@ -823,9 +848,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* then being set explicitly still should allow the * then being set explicitly still should allow the
* fetching of the RGB. * fetching of the RGB.
*/ */
@SuppressWarnings("deprecation")
@Test @Test
public void bug50784() throws Exception { public void bug50784() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50784-font_theme_colours.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50784-font_theme_colours.xlsx");
XSSFSheet s = wb.getSheetAt(0); XSSFSheet s = wb.getSheetAt(0);
XSSFRow r = s.getRow(0); XSSFRow r = s.getRow(0);
@ -836,7 +860,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
XSSFColor colr = fr.getXSSFColor(); XSSFColor colr = fr.getXSSFColor();
// No theme, has colours // No theme, has colours
assertEquals(0, colr.getTheme()); assertEquals(0, colr.getTheme());
assertNotNull( colr.getRgb() ); assertNotNull( colr.getRGB() );
// Column 0 has a font with colours from a theme // Column 0 has a font with colours from a theme
XSSFCell ct = r.getCell(0); XSSFCell ct = r.getCell(0);
@ -845,8 +869,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
// Has a theme, which has the colours on it // Has a theme, which has the colours on it
assertEquals(9, colt.getTheme()); assertEquals(9, colt.getTheme());
XSSFColor themeC = wb.getTheme().getThemeColor(colt.getTheme()); XSSFColor themeC = wb.getTheme().getThemeColor(colt.getTheme());
assertNotNull( themeC.getRgb() ); assertNotNull( themeC.getRGB() );
assertNotNull( colt.getRgb() ); assertNotNull( colt.getRGB() );
assertEquals( themeC.getARGBHex(), colt.getARGBHex() ); // The same colour assertEquals( themeC.getARGBHex(), colt.getARGBHex() ); // The same colour
wb.close(); wb.close();
} }
@ -856,7 +880,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* a rich text string * a rich text string
*/ */
@Test @Test
public void bug48877() throws Exception { public void bug48877() throws IOException {
String text = "Use \n with word wrap on to create a new line.\n" + String text = "Use \n with word wrap on to create a new line.\n" +
"This line finishes with two trailing spaces. "; "This line finishes with two trailing spaces. ";
@ -929,7 +953,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Adding sheets when one has a table, then re-ordering * Adding sheets when one has a table, then re-ordering
*/ */
@Test @Test
public void bug50867() throws Exception { public void bug50867() throws IOException {
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("50867_with_table.xlsx"); XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("50867_with_table.xlsx");
assertEquals(3, wb1.getNumberOfSheets()); assertEquals(3, wb1.getNumberOfSheets());
@ -1051,7 +1075,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Test @Test
public void bug49253() throws Exception { public void bug49253() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook(); XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFWorkbook wb2 = new XSSFWorkbook(); XSSFWorkbook wb2 = new XSSFWorkbook();
@ -1096,7 +1120,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Default Column style * Default Column style
*/ */
@Test @Test
public void bug51037() throws Exception { public void bug51037() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet s = wb.createSheet(); XSSFSheet s = wb.createSheet();
@ -1175,7 +1199,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Something with the SharedStringsTable currently breaks... * Something with the SharedStringsTable currently breaks...
*/ */
@Test @Test
public void bug46662() throws Exception { public void bug46662() throws IOException {
// New file // New file
XSSFWorkbook wb1 = new XSSFWorkbook(); XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFTestDataSamples.writeOutAndReadBack(wb1).close(); XSSFTestDataSamples.writeOutAndReadBack(wb1).close();
@ -1198,7 +1222,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Colours and styles when the list has gaps in it * Colours and styles when the list has gaps in it
*/ */
@Test @Test
public void bug51222() throws Exception { public void bug51222() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51222.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51222.xlsx");
XSSFSheet s = wb.getSheetAt(0); XSSFSheet s = wb.getSheetAt(0);
@ -1239,7 +1263,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug51470() throws Exception { public void bug51470() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51470.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51470.xlsx");
XSSFSheet sh0 = wb.getSheetAt(0); XSSFSheet sh0 = wb.getSheetAt(0);
XSSFSheet sh1 = wb.cloneSheet(0); XSSFSheet sh1 = wb.cloneSheet(0);
@ -1257,7 +1281,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* comments (so /xl/comments1.xml is taken) * comments (so /xl/comments1.xml is taken)
*/ */
@Test @Test
public void bug51850() throws Exception { public void bug51850() throws IOException {
XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("51850.xlsx"); XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("51850.xlsx");
XSSFSheet sh1 = wb1.getSheetAt(0); XSSFSheet sh1 = wb1.getSheetAt(0);
XSSFSheet sh2 = wb1.getSheetAt(1); XSSFSheet sh2 = wb1.getSheetAt(1);
@ -1322,7 +1346,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Sheet names with a , in them * Sheet names with a , in them
*/ */
@Test @Test
public void bug51963() throws Exception { public void bug51963() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51963.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51963.xlsx");
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
assertEquals("Abc,1", sheet.getSheetName()); assertEquals("Abc,1", sheet.getSheetName());
@ -1345,7 +1369,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* DISABLED As we can't currently evaluate these * DISABLED As we can't currently evaluate these
*/ */
@Ignore @Ignore
public void bug48703() throws Exception { public void bug48703() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48703.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48703.xlsx");
XSSFSheet sheet = wb.getSheetAt(0); XSSFSheet sheet = wb.getSheetAt(0);
@ -1375,7 +1399,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Bugzilla 51710: problems reading shared formuals from .xlsx * Bugzilla 51710: problems reading shared formuals from .xlsx
*/ */
@Test @Test
public void bug51710() throws Exception { public void bug51710() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("51710.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("51710.xlsx");
final String[] columns = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N"}; final String[] columns = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N"};
@ -1407,7 +1431,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Bug 53101: * Bug 53101:
*/ */
@Test @Test
public void bug5301() throws Exception { public void bug5301() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53101.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53101.xlsx");
FormulaEvaluator evaluator = FormulaEvaluator evaluator =
wb.getCreationHelper().createFormulaEvaluator(); wb.getCreationHelper().createFormulaEvaluator();
@ -1428,7 +1452,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug54436() throws Exception { public void bug54436() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("54436.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("54436.xlsx");
if(!WorkbookEvaluator.getSupportedFunctionNames().contains("GETPIVOTDATA")){ if(!WorkbookEvaluator.getSupportedFunctionNames().contains("GETPIVOTDATA")){
Function func = new Function() { Function func = new Function() {
@ -1449,7 +1473,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* error message when called via WorkbookFactory with no password * error message when called via WorkbookFactory with no password
*/ */
@Test(expected=EncryptedDocumentException.class) @Test(expected=EncryptedDocumentException.class)
public void bug55692_poifs() throws Exception { public void bug55692_poifs() throws IOException {
// Via a POIFSFileSystem // Via a POIFSFileSystem
POIFSFileSystem fsP = new POIFSFileSystem( POIFSFileSystem fsP = new POIFSFileSystem(
POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx")); POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
@ -1461,7 +1485,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug55692_stream() throws Exception { public void bug55692_stream() throws IOException, InvalidFormatException {
// Directly on a Stream, will go via NPOIFS and spot it's // Directly on a Stream, will go via NPOIFS and spot it's
// actually a .xlsx file encrypted with the default password, and open // actually a .xlsx file encrypted with the default password, and open
Workbook wb = WorkbookFactory.create( Workbook wb = WorkbookFactory.create(
@ -1472,7 +1496,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug55692_npoifs() throws Exception { public void bug55692_npoifs() throws IOException {
// Via a NPOIFSFileSystem, will spot it's actually a .xlsx file // Via a NPOIFSFileSystem, will spot it's actually a .xlsx file
// encrypted with the default password, and open // encrypted with the default password, and open
NPOIFSFileSystem fsNP = new NPOIFSFileSystem( NPOIFSFileSystem fsNP = new NPOIFSFileSystem(
@ -1485,7 +1509,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug53282() throws Exception { public void bug53282() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53282b.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53282b.xlsx");
Cell c = wb.getSheetAt(0).getRow(1).getCell(0); Cell c = wb.getSheetAt(0).getRow(1).getCell(0);
assertEquals("#@_#", c.getStringCellValue()); assertEquals("#@_#", c.getStringCellValue());
@ -1499,7 +1523,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* due to a lack of Styles Table * due to a lack of Styles Table
*/ */
@Test @Test
public void bug56278() throws Exception { public void bug56278() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56278.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56278.xlsx");
assertEquals(0, wb.getSheetIndex("Market Rates")); assertEquals(0, wb.getSheetIndex("Market Rates"));
@ -1511,7 +1535,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug56315() throws Exception { public void bug56315() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56315.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56315.xlsx");
Cell c = wb.getSheetAt(0).getRow(1).getCell(0); Cell c = wb.getSheetAt(0).getRow(1).getCell(0);
CellValue cv = wb.getCreationHelper().createFormulaEvaluator().evaluate(c); CellValue cv = wb.getCreationHelper().createFormulaEvaluator().evaluate(c);
@ -1521,7 +1545,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug56468() throws Exception { public void bug56468() throws IOException, InterruptedException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet(); XSSFSheet sheet = wb.createSheet();
XSSFRow row = sheet.createRow(0); XSSFRow row = sheet.createRow(0);
@ -1615,7 +1639,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* SUMIF was throwing a NPE on some formulas * SUMIF was throwing a NPE on some formulas
*/ */
@Test @Test
public void testBug56420SumIfNPE() throws Exception { public void testBug56420SumIfNPE() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56420.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56420.xlsx");
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
@ -1679,7 +1703,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* with DataFormatter * with DataFormatter
*/ */
@Test @Test
public void bug56702() throws Exception { public void bug56702() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56702.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56702.xlsx");
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
@ -1754,9 +1778,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
FileOutputStream fileOutStream = new FileOutputStream(outFile); FileOutputStream fileOutStream = new FileOutputStream(outFile);
wb.write(fileOutStream); try {
fileOutStream.close(); wb.write(fileOutStream);
//System.out.println("File \""+outFile.getName()+"\" has been saved successfully"); } finally {
fileOutStream.close();
}
FileInputStream is = new FileInputStream(outFile); FileInputStream is = new FileInputStream(outFile);
try { try {
@ -1773,7 +1799,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
assertNotNull(newWB.getSheet("test")); assertNotNull(newWB.getSheet("test"));
} finally { } finally {
newWB.close(); if (newWB != null) {
newWB.close();
}
} }
} finally { } finally {
is.close(); is.close();
@ -1781,28 +1809,28 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void testBug56688_1() throws Exception { public void testBug56688_1() throws IOException {
XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_1.xlsx"); XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_1.xlsx");
checkValue(excel, "-1.0"); /* Not 0.0 because POI sees date "0" minus one month as invalid date, which is -1! */ checkValue(excel, "-1.0"); /* Not 0.0 because POI sees date "0" minus one month as invalid date, which is -1! */
excel.close(); excel.close();
} }
@Test @Test
public void testBug56688_2() throws Exception { public void testBug56688_2() throws IOException {
XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_2.xlsx"); XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_2.xlsx");
checkValue(excel, "#VALUE!"); checkValue(excel, "#VALUE!");
excel.close(); excel.close();
} }
@Test @Test
public void testBug56688_3() throws Exception { public void testBug56688_3() throws IOException {
XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_3.xlsx"); XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_3.xlsx");
checkValue(excel, "#VALUE!"); checkValue(excel, "#VALUE!");
excel.close(); excel.close();
} }
@Test @Test
public void testBug56688_4() throws Exception { public void testBug56688_4() throws IOException {
XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_4.xlsx"); XSSFWorkbook excel = XSSFTestDataSamples.openSampleWorkbook("56688_4.xlsx");
Calendar calendar = LocaleUtil.getLocaleCalendar(); Calendar calendar = LocaleUtil.getLocaleCalendar();
@ -1855,7 +1883,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* function in another file * function in another file
*/ */
@Test @Test
public void bug56502() throws Exception { public void bug56502() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56502.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56502.xlsx");
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
@ -1876,7 +1904,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug54764() throws Exception { public void bug54764() throws IOException, OpenXML4JException, XmlException {
OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("54764.xlsx"); OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("54764.xlsx");
// Check the core properties - will be found but empty, due // Check the core properties - will be found but empty, due
@ -1914,7 +1942,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* poi-ooxml-schemas jar * poi-ooxml-schemas jar
*/ */
@Test @Test
public void bug57176() throws Exception { public void bug57176() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57176.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57176.xlsx");
CTDefinedNames definedNames = wb.getCTWorkbook().getDefinedNames(); CTDefinedNames definedNames = wb.getCTWorkbook().getDefinedNames();
List<CTDefinedName> definedNameList = definedNames.getDefinedNameList(); List<CTDefinedName> definedNameList = definedNames.getDefinedNameList();
@ -1929,9 +1957,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
/** /**
* .xlsb files are not supported, but we should generate a helpful * .xlsb files are not supported, but we should generate a helpful
* error message if given one * error message if given one
* @throws InvalidFormatException
* @throws
*/ */
@Test @Test
public void bug56800_xlsb() throws Exception { public void bug56800_xlsb() throws IOException, InvalidFormatException {
// Can be opened at the OPC level // Can be opened at the OPC level
OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("Simple.xlsb"); OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("Simple.xlsb");
@ -1987,7 +2017,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void test57196_Detail() throws Exception { public void test57196_Detail() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("Sheet1"); XSSFSheet sheet = wb.createSheet("Sheet1");
XSSFRow row = sheet.createRow(0); XSSFRow row = sheet.createRow(0);
@ -2001,7 +2031,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void test57196_Detail2() throws Exception { public void test57196_Detail2() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("Sheet1"); XSSFSheet sheet = wb.createSheet("Sheet1");
XSSFRow row = sheet.createRow(0); XSSFRow row = sheet.createRow(0);
@ -2015,7 +2045,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void test57196_WorkbookEvaluator() throws Exception { public void test57196_WorkbookEvaluator() throws IOException {
String previousLogger = System.getProperty("org.apache.poi.util.POILogger"); String previousLogger = System.getProperty("org.apache.poi.util.POILogger");
//System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger"); //System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger");
//System.setProperty("poi.log.level", "3"); //System.setProperty("poi.log.level", "3");
@ -2098,10 +2128,11 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
/** /**
* A .xlsx file with no Shared Strings table should open fine * A .xlsx file with no Shared Strings table should open fine
* in read-only mode * in read-only mode
* @throws InvalidFormatException
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
@Test @Test
public void bug57482() throws Exception { public void bug57482() throws IOException, InvalidFormatException {
for (PackageAccess access : new PackageAccess[] { for (PackageAccess access : new PackageAccess[] {
PackageAccess.READ_WRITE, PackageAccess.READ PackageAccess.READ_WRITE, PackageAccess.READ
}) { }) {
@ -2109,12 +2140,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
OPCPackage pkg = OPCPackage.open(file, access); OPCPackage pkg = OPCPackage.open(file, access);
try { try {
// Try to open it and read the contents // Try to open it and read the contents
XSSFWorkbook wb = new XSSFWorkbook(pkg); XSSFWorkbook wb1 = new XSSFWorkbook(pkg);
assertNotNull(wb.getSharedStringSource()); assertNotNull(wb1.getSharedStringSource());
assertEquals(0, wb.getSharedStringSource().getCount()); assertEquals(0, wb1.getSharedStringSource().getCount());
DataFormatter fmt = new DataFormatter(); DataFormatter fmt = new DataFormatter();
XSSFSheet s = wb.getSheetAt(0); XSSFSheet s = wb1.getSheetAt(0);
assertEquals("1", fmt.formatCellValue(s.getRow(0).getCell(0))); assertEquals("1", fmt.formatCellValue(s.getRow(0).getCell(0)));
assertEquals("11", fmt.formatCellValue(s.getRow(0).getCell(1))); assertEquals("11", fmt.formatCellValue(s.getRow(0).getCell(1)));
assertEquals("5", fmt.formatCellValue(s.getRow(4).getCell(0))); assertEquals("5", fmt.formatCellValue(s.getRow(4).getCell(0)));
@ -2125,25 +2156,32 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
// Try to write-out and read again, should only work // Try to write-out and read again, should only work
// in read-write mode, not read-only mode // in read-write mode, not read-only mode
XSSFWorkbook wb2 = null;
try { try {
wb = XSSFTestDataSamples.writeOutAndReadBack(wb); wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
if (access == PackageAccess.READ)
fail("Shouln't be able to write from read-only mode");
} catch (InvalidOperationException e) {
if (access == PackageAccess.READ) { if (access == PackageAccess.READ) {
// Expected fail("Shouln't be able to write from read-only mode");
} else { }
// Check again
s = wb2.getSheetAt(0);
assertEquals("1", fmt.formatCellValue(s.getRow(0).getCell(0)));
assertEquals("11", fmt.formatCellValue(s.getRow(0).getCell(1)));
assertEquals("5", fmt.formatCellValue(s.getRow(4).getCell(0)));
assertEquals("Testing", fmt.formatCellValue(s.getRow(0).getCell(3)));
} catch (InvalidOperationException e) {
if (access == PackageAccess.READ_WRITE) {
// Shouldn't occur in write-mode // Shouldn't occur in write-mode
throw e; throw e;
} }
} finally {
if (wb2 != null) {
wb2.getPackage().revert();
}
} }
// Check again wb1.getPackage().revert();
s = wb.getSheetAt(0);
assertEquals("1", fmt.formatCellValue(s.getRow(0).getCell(0)));
assertEquals("11", fmt.formatCellValue(s.getRow(0).getCell(1)));
assertEquals("5", fmt.formatCellValue(s.getRow(4).getCell(0)));
assertEquals("Testing", fmt.formatCellValue(s.getRow(0).getCell(3)));
} finally { } finally {
pkg.revert(); pkg.revert();
} }
@ -2154,7 +2192,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* "Unknown error type: -60" fetching formula error value * "Unknown error type: -60" fetching formula error value
*/ */
@Test @Test
public void bug57535() throws Exception { public void bug57535() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57535.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57535.xlsx");
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
evaluator.clearAllCachedResultValues(); evaluator.clearAllCachedResultValues();
@ -2334,7 +2372,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
*/ */
@Test @Test
@Ignore("XMLBeans namespace mis-match on ooxml-strict files") @Ignore("XMLBeans namespace mis-match on ooxml-strict files")
public void test57699() throws Exception { public void test57699() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.strict.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.strict.xlsx");
assertEquals(3, wb.getNumberOfSheets()); assertEquals(3, wb.getNumberOfSheets());
// TODO Check sheet contents // TODO Check sheet contents
@ -2400,7 +2438,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Excel treats this as not-bulleted, so now do we * Excel treats this as not-bulleted, so now do we
*/ */
@Test @Test
public void testBug57826() throws Exception { public void testBug57826() throws IOException {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("57826.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("57826.xlsx");
assertTrue("no sheets in workbook", workbook.getNumberOfSheets() >= 1); assertTrue("no sheets in workbook", workbook.getNumberOfSheets() >= 1);
@ -2440,7 +2478,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void bug57642() throws Exception { public void bug57642() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet s = wb.createSheet("TestSheet"); XSSFSheet s = wb.createSheet("TestSheet");
XSSFCell c = s.createRow(0).createCell(0); XSSFCell c = s.createRow(0).createCell(0);
@ -2460,9 +2498,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
/** /**
* .xlsx supports 64000 cell styles, the style indexes after * .xlsx supports 64000 cell styles, the style indexes after
* 32,767 must not be -32,768, then -32,767, -32,766 * 32,767 must not be -32,768, then -32,767, -32,766
* @throws InvalidFormatException
*/ */
@Test @Test
public void bug57880() throws Exception { public void bug57880() throws IOException, InvalidFormatException {
int numStyles = 33000; int numStyles = 33000;
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
//XSSFSheet s = wb.createSheet("TestSheet"); //XSSFSheet s = wb.createSheet("TestSheet");
@ -2529,10 +2568,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
data.put("4", new Object[] {4, "John", "Adwards"}); data.put("4", new Object[] {4, "John", "Adwards"});
data.put("5", new Object[] {2, "Brian", "Schultz"}); data.put("5", new Object[] {2, "Brian", "Schultz"});
Set<String> keyset = data.keySet();
int rownum = 1; int rownum = 1;
for (String key : keyset) for (Map.Entry<String,Object[]> me : data.entrySet()) {
{
final Row row; final Row row;
if(createRow) { if(createRow) {
row = sheet.createRow(rownum++); row = sheet.createRow(rownum++);
@ -2541,10 +2578,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
assertNotNull(row); assertNotNull(row);
Object [] objArr = data.get(key);
int cellnum = 0; int cellnum = 0;
for (Object obj : objArr) for (Object obj : me.getValue()) {
{
Cell cell = row.getCell(cellnum); Cell cell = row.getCell(cellnum);
if(cell == null){ if(cell == null){
cell = row.createCell(cellnum); cell = row.createCell(cellnum);
@ -2577,13 +2612,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertFalse(calc.getR().equals("A6")); assertFalse(calc.getR().equals("A6"));
} }
/*FileOutputStream out = new FileOutputStream(new File("C:\\temp\\56574.xlsx"));
try {
wb.write(out);
} finally {
out.close();
}*/
Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb); Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
Sheet sheetBack = wbBack.getSheet("Func"); Sheet sheetBack = wbBack.getSheet("Func");
assertNotNull(sheetBack); assertNotNull(sheetBack);
@ -2607,14 +2635,14 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* Excel 2007 generated Macro-Enabled .xlsm file * Excel 2007 generated Macro-Enabled .xlsm file
*/ */
@Test @Test
public void bug57181() throws Exception { public void bug57181() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57181.xlsm"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57181.xlsm");
assertEquals(9, wb.getNumberOfSheets()); assertEquals(9, wb.getNumberOfSheets());
wb.close(); wb.close();
} }
@Test @Test
public void bug52111() throws Exception { public void bug52111() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("Intersection-52111-xssf.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("Intersection-52111-xssf.xlsx");
Sheet s = wb.getSheetAt(0); Sheet s = wb.getSheetAt(0);
assertFormula(wb, s.getRow(2).getCell(0), "(C2:D3 D3:E4)", "4.0"); assertFormula(wb, s.getRow(2).getCell(0), "(C2:D3 D3:E4)", "4.0");
@ -2641,7 +2669,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void test48962() throws Exception { public void test48962() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("48962.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("48962.xlsx");
Sheet sh = wb.getSheetAt(0); Sheet sh = wb.getSheetAt(0);
Row row = sh.getRow(1); Row row = sh.getRow(1);
@ -2666,7 +2694,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void test50755_workday_formula_example() throws Exception { public void test50755_workday_formula_example() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50755_workday_formula_example.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50755_workday_formula_example.xlsx");
Sheet sheet = wb.getSheet("Sheet1"); Sheet sheet = wb.getSheet("Sheet1");
for(Row aRow : sheet) { for(Row aRow : sheet) {
@ -2684,7 +2712,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void test51626() throws Exception { public void test51626() throws IOException, InvalidFormatException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("51626.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("51626.xlsx");
assertNotNull(wb); assertNotNull(wb);
wb.close(); wb.close();
@ -2765,7 +2793,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
} }
@Test @Test
public void test55406() throws Exception { public void test55406() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("55406_Conditional_formatting_sample.xlsx"); Workbook wb = XSSFTestDataSamples.openSampleWorkbook("55406_Conditional_formatting_sample.xlsx");
Sheet sheet = wb.getSheetAt(0); Sheet sheet = wb.getSheetAt(0);
Cell cellA1 = sheet.getRow(0).getCell(0); Cell cellA1 = sheet.getRow(0).getCell(0);

View File

@ -17,9 +17,15 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import java.io.IOException; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase; import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@ -36,10 +42,20 @@ import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.StylesTable; import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder; import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignment;
public class TestXSSFCellStyle extends TestCase { public class TestXSSFCellStyle {
private StylesTable stylesTable; private StylesTable stylesTable;
private CTBorder ctBorderA; private CTBorder ctBorderA;
private CTFill ctFill; private CTFill ctFill;
@ -50,8 +66,8 @@ public class TestXSSFCellStyle extends TestCase {
private XSSFCellStyle cellStyle; private XSSFCellStyle cellStyle;
private CTStylesheet ctStylesheet; private CTStylesheet ctStylesheet;
@Override @Before
protected void setUp() { public void setUp() {
stylesTable = new StylesTable(); stylesTable = new StylesTable();
ctStylesheet = stylesTable.getCTStylesheet(); ctStylesheet = stylesTable.getCTStylesheet();
@ -93,6 +109,7 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STPatternType.INT_DARK_GRAY, stylesTable.getFillAt(1).getCTFill().getPatternFill().getPatternType().intValue()); assertEquals(STPatternType.INT_DARK_GRAY, stylesTable.getFillAt(1).getCTFill().getPatternFill().getPatternType().intValue());
} }
@Test
public void testGetSetBorderBottom() { public void testGetSetBorderBottom() {
//default values //default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderBottom()); assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderBottom());
@ -127,6 +144,7 @@ public class TestXSSFCellStyle extends TestCase {
assertFalse(ctBorder.isSetBottom()); assertFalse(ctBorder.isSetBottom());
} }
@Test
public void testGetSetBorderRight() { public void testGetSetBorderRight() {
//default values //default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderRight()); assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderRight());
@ -161,7 +179,8 @@ public class TestXSSFCellStyle extends TestCase {
assertFalse(ctBorder.isSetRight()); assertFalse(ctBorder.isSetRight());
} }
public void testGetSetBorderLeft() { @Test
public void testGetSetBorderLeft() {
//default values //default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderLeft()); assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderLeft());
@ -195,7 +214,8 @@ public class TestXSSFCellStyle extends TestCase {
assertFalse(ctBorder.isSetLeft()); assertFalse(ctBorder.isSetLeft());
} }
public void testGetSetBorderTop() { @Test
public void testGetSetBorderTop() {
//default values //default values
assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderTop());
@ -229,7 +249,8 @@ public class TestXSSFCellStyle extends TestCase {
assertFalse(ctBorder.isSetTop()); assertFalse(ctBorder.isSetTop());
} }
public void testGetSetBorderThin() { @Test
public void testGetSetBorderThin() {
cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setBorderTop(CellStyle.BORDER_THIN);
assertEquals(CellStyle.BORDER_THIN, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_THIN, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -239,7 +260,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.THIN, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.THIN, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderMedium() { @Test
public void testGetSetBorderMedium() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM); cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -249,7 +271,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderThick() { @Test
public void testGetSetBorderThick() {
cellStyle.setBorderTop(CellStyle.BORDER_THICK); cellStyle.setBorderTop(CellStyle.BORDER_THICK);
assertEquals(CellStyle.BORDER_THICK, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_THICK, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -259,7 +282,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.THICK, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.THICK, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderHair() { @Test
public void testGetSetBorderHair() {
cellStyle.setBorderTop(CellStyle.BORDER_HAIR); cellStyle.setBorderTop(CellStyle.BORDER_HAIR);
assertEquals(CellStyle.BORDER_HAIR, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_HAIR, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -269,7 +293,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.HAIR, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.HAIR, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderDotted() { @Test
public void testGetSetBorderDotted() {
cellStyle.setBorderTop(CellStyle.BORDER_DOTTED); cellStyle.setBorderTop(CellStyle.BORDER_DOTTED);
assertEquals(CellStyle.BORDER_DOTTED, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_DOTTED, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -279,7 +304,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.DOTTED, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.DOTTED, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderDashed() { @Test
public void testGetSetBorderDashed() {
cellStyle.setBorderTop(CellStyle.BORDER_DASHED); cellStyle.setBorderTop(CellStyle.BORDER_DASHED);
assertEquals(CellStyle.BORDER_DASHED, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_DASHED, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -289,7 +315,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.DASHED, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.DASHED, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderDashDot() { @Test
public void testGetSetBorderDashDot() {
cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT); cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT);
assertEquals(CellStyle.BORDER_DASH_DOT, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_DASH_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -299,7 +326,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.DASH_DOT, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.DASH_DOT, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderDashDotDot() { @Test
public void testGetSetBorderDashDotDot() {
cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT_DOT); cellStyle.setBorderTop(CellStyle.BORDER_DASH_DOT_DOT);
assertEquals(CellStyle.BORDER_DASH_DOT_DOT, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_DASH_DOT_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -309,7 +337,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.DASH_DOT_DOT, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.DASH_DOT_DOT, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderMediumDashDot() { @Test
public void testGetSetBorderMediumDashDot() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASH_DOT); cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASH_DOT);
assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -319,7 +348,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.MEDIUM_DASH_DOT, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.MEDIUM_DASH_DOT, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderMediumDashDotDot() { @Test
public void testGetSetBorderMediumDashDotDot() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT); cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT);
assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_MEDIUM_DASH_DOT_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -329,7 +359,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.MEDIUM_DASH_DOT_DOT, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.MEDIUM_DASH_DOT_DOT, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderMediumDashed() { @Test
public void testGetSetBorderMediumDashed() {
cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED); cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED);
assertEquals(CellStyle.BORDER_MEDIUM_DASHED, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_MEDIUM_DASHED, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -339,7 +370,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.MEDIUM_DASHED, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.MEDIUM_DASHED, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderSlantDashDot() { @Test
public void testGetSetBorderSlantDashDot() {
cellStyle.setBorderTop(CellStyle.BORDER_SLANTED_DASH_DOT); cellStyle.setBorderTop(CellStyle.BORDER_SLANTED_DASH_DOT);
assertEquals(CellStyle.BORDER_SLANTED_DASH_DOT, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_SLANTED_DASH_DOT, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -349,7 +381,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.SLANT_DASH_DOT, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.SLANT_DASH_DOT, ctBorder.getTop().getStyle());
} }
public void testGetSetBorderDouble() { @Test
public void testGetSetBorderDouble() {
cellStyle.setBorderTop(CellStyle.BORDER_DOUBLE); cellStyle.setBorderTop(CellStyle.BORDER_DOUBLE);
assertEquals(CellStyle.BORDER_DOUBLE, cellStyle.getBorderTop()); assertEquals(CellStyle.BORDER_DOUBLE, cellStyle.getBorderTop());
int borderId = (int)cellStyle.getCoreXf().getBorderId(); int borderId = (int)cellStyle.getCoreXf().getBorderId();
@ -359,7 +392,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STBorderStyle.DOUBLE, ctBorder.getTop().getStyle()); assertEquals(STBorderStyle.DOUBLE, ctBorder.getTop().getStyle());
} }
public void testGetSetBottomBorderColor() { @Test
public void testGetSetBottomBorderColor() {
//defaults //defaults
assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getBottomBorderColor()); assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getBottomBorderColor());
assertNull(cellStyle.getBottomBorderXSSFColor()); assertNull(cellStyle.getBottomBorderXSSFColor());
@ -389,7 +423,7 @@ public class TestXSSFCellStyle extends TestCase {
clr = new XSSFColor(java.awt.Color.CYAN); clr = new XSSFColor(java.awt.Color.CYAN);
cellStyle.setBottomBorderColor(clr); cellStyle.setBottomBorderColor(clr);
assertEquals(clr.getCTColor().toString(), cellStyle.getBottomBorderXSSFColor().getCTColor().toString()); assertEquals(clr.getCTColor().toString(), cellStyle.getBottomBorderXSSFColor().getCTColor().toString());
byte[] rgb = cellStyle.getBottomBorderXSSFColor().getRgb(); byte[] rgb = cellStyle.getBottomBorderXSSFColor().getRGB();
assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF)); assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
//another border was added to the styles table //another border was added to the styles table
assertEquals(num + 1, stylesTable.getBorders().size()); assertEquals(num + 1, stylesTable.getBorders().size());
@ -399,7 +433,8 @@ public class TestXSSFCellStyle extends TestCase {
assertNull(cellStyle.getBottomBorderXSSFColor()); assertNull(cellStyle.getBottomBorderXSSFColor());
} }
public void testGetSetTopBorderColor() { @Test
public void testGetSetTopBorderColor() {
//defaults //defaults
assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getTopBorderColor()); assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getTopBorderColor());
assertNull(cellStyle.getTopBorderXSSFColor()); assertNull(cellStyle.getTopBorderXSSFColor());
@ -429,7 +464,7 @@ public class TestXSSFCellStyle extends TestCase {
clr = new XSSFColor(java.awt.Color.CYAN); clr = new XSSFColor(java.awt.Color.CYAN);
cellStyle.setTopBorderColor(clr); cellStyle.setTopBorderColor(clr);
assertEquals(clr.getCTColor().toString(), cellStyle.getTopBorderXSSFColor().getCTColor().toString()); assertEquals(clr.getCTColor().toString(), cellStyle.getTopBorderXSSFColor().getCTColor().toString());
byte[] rgb = cellStyle.getTopBorderXSSFColor().getRgb(); byte[] rgb = cellStyle.getTopBorderXSSFColor().getRGB();
assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF)); assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
//another border was added to the styles table //another border was added to the styles table
assertEquals(num + 1, stylesTable.getBorders().size()); assertEquals(num + 1, stylesTable.getBorders().size());
@ -439,7 +474,8 @@ public class TestXSSFCellStyle extends TestCase {
assertNull(cellStyle.getTopBorderXSSFColor()); assertNull(cellStyle.getTopBorderXSSFColor());
} }
public void testGetSetLeftBorderColor() { @Test
public void testGetSetLeftBorderColor() {
//defaults //defaults
assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getLeftBorderColor()); assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getLeftBorderColor());
assertNull(cellStyle.getLeftBorderXSSFColor()); assertNull(cellStyle.getLeftBorderXSSFColor());
@ -469,7 +505,7 @@ public class TestXSSFCellStyle extends TestCase {
clr = new XSSFColor(java.awt.Color.CYAN); clr = new XSSFColor(java.awt.Color.CYAN);
cellStyle.setLeftBorderColor(clr); cellStyle.setLeftBorderColor(clr);
assertEquals(clr.getCTColor().toString(), cellStyle.getLeftBorderXSSFColor().getCTColor().toString()); assertEquals(clr.getCTColor().toString(), cellStyle.getLeftBorderXSSFColor().getCTColor().toString());
byte[] rgb = cellStyle.getLeftBorderXSSFColor().getRgb(); byte[] rgb = cellStyle.getLeftBorderXSSFColor().getRGB();
assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF)); assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
//another border was added to the styles table //another border was added to the styles table
assertEquals(num + 1, stylesTable.getBorders().size()); assertEquals(num + 1, stylesTable.getBorders().size());
@ -479,7 +515,8 @@ public class TestXSSFCellStyle extends TestCase {
assertNull(cellStyle.getLeftBorderXSSFColor()); assertNull(cellStyle.getLeftBorderXSSFColor());
} }
public void testGetSetRightBorderColor() { @Test
public void testGetSetRightBorderColor() {
//defaults //defaults
assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getRightBorderColor()); assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getRightBorderColor());
assertNull(cellStyle.getRightBorderXSSFColor()); assertNull(cellStyle.getRightBorderXSSFColor());
@ -509,7 +546,7 @@ public class TestXSSFCellStyle extends TestCase {
clr = new XSSFColor(java.awt.Color.CYAN); clr = new XSSFColor(java.awt.Color.CYAN);
cellStyle.setRightBorderColor(clr); cellStyle.setRightBorderColor(clr);
assertEquals(clr.getCTColor().toString(), cellStyle.getRightBorderXSSFColor().getCTColor().toString()); assertEquals(clr.getCTColor().toString(), cellStyle.getRightBorderXSSFColor().getCTColor().toString());
byte[] rgb = cellStyle.getRightBorderXSSFColor().getRgb(); byte[] rgb = cellStyle.getRightBorderXSSFColor().getRGB();
assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF)); assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
//another border was added to the styles table //another border was added to the styles table
assertEquals(num + 1, stylesTable.getBorders().size()); assertEquals(num + 1, stylesTable.getBorders().size());
@ -519,7 +556,8 @@ public class TestXSSFCellStyle extends TestCase {
assertNull(cellStyle.getRightBorderXSSFColor()); assertNull(cellStyle.getRightBorderXSSFColor());
} }
public void testGetSetFillBackgroundColor() { @Test
public void testGetSetFillBackgroundColor() {
assertEquals(IndexedColors.AUTOMATIC.getIndex(), cellStyle.getFillBackgroundColor()); assertEquals(IndexedColors.AUTOMATIC.getIndex(), cellStyle.getFillBackgroundColor());
assertNull(cellStyle.getFillBackgroundXSSFColor()); assertNull(cellStyle.getFillBackgroundXSSFColor());
@ -541,15 +579,15 @@ public class TestXSSFCellStyle extends TestCase {
int fillId = (int)cellStyle.getCoreXf().getFillId(); int fillId = (int)cellStyle.getCoreXf().getFillId();
assertTrue(fillId > 0); assertTrue(fillId > 0);
//check changes in the underlying xml bean //check changes in the underlying xml bean
CTFill ctFill = stylesTable.getFillAt(fillId).getCTFill(); CTFill ctFill2 = stylesTable.getFillAt(fillId).getCTFill();
assertEquals(IndexedColors.RED.getIndex(), ctFill.getPatternFill().getBgColor().getIndexed()); assertEquals(IndexedColors.RED.getIndex(), ctFill2.getPatternFill().getBgColor().getIndexed());
//setting XSSFColor //setting XSSFColor
num = stylesTable.getFills().size(); num = stylesTable.getFills().size();
clr = new XSSFColor(java.awt.Color.CYAN); clr = new XSSFColor(java.awt.Color.CYAN);
cellStyle.setFillBackgroundColor(clr); cellStyle.setFillBackgroundColor(clr);
assertEquals(clr.getCTColor().toString(), cellStyle.getFillBackgroundXSSFColor().getCTColor().toString()); assertEquals(clr.getCTColor().toString(), cellStyle.getFillBackgroundXSSFColor().getCTColor().toString());
byte[] rgb = cellStyle.getFillBackgroundXSSFColor().getRgb(); byte[] rgb = cellStyle.getFillBackgroundXSSFColor().getRGB();
assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF)); assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
//another border was added to the styles table //another border was added to the styles table
assertEquals(num + 1, stylesTable.getFills().size()); assertEquals(num + 1, stylesTable.getFills().size());
@ -560,7 +598,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(IndexedColors.AUTOMATIC.getIndex(), cellStyle.getFillBackgroundColor()); assertEquals(IndexedColors.AUTOMATIC.getIndex(), cellStyle.getFillBackgroundColor());
} }
public void testDefaultStyles() throws IOException { @Test
public void testDefaultStyles() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook(); XSSFWorkbook wb1 = new XSSFWorkbook();
@ -569,6 +608,7 @@ public class TestXSSFCellStyle extends TestCase {
assertNull(style1.getFillBackgroundXSSFColor()); assertNull(style1.getFillBackgroundXSSFColor());
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb1)); assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb1));
wb1.close();
//compatibility with HSSF //compatibility with HSSF
HSSFWorkbook wb2 = new HSSFWorkbook(); HSSFWorkbook wb2 = new HSSFWorkbook();
@ -589,8 +629,8 @@ public class TestXSSFCellStyle extends TestCase {
wb2.close(); wb2.close();
} }
@Test
public void testGetFillForegroundColor() { public void testGetFillForegroundColor() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
StylesTable styles = wb.getStylesSource(); StylesTable styles = wb.getStylesSource();
assertEquals(1, wb.getNumCellStyles()); assertEquals(1, wb.getNumCellStyles());
@ -624,9 +664,11 @@ public class TestXSSFCellStyle extends TestCase {
} }
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
wb.close();
} }
public void testGetFillPattern() { @Test
public void testGetFillPattern() {
assertEquals(STPatternType.INT_DARK_GRAY-1, cellStyle.getFillPattern()); assertEquals(STPatternType.INT_DARK_GRAY-1, cellStyle.getFillPattern());
@ -637,8 +679,8 @@ public class TestXSSFCellStyle extends TestCase {
int fillId = (int)cellStyle.getCoreXf().getFillId(); int fillId = (int)cellStyle.getCoreXf().getFillId();
assertTrue(fillId > 0); assertTrue(fillId > 0);
//check changes in the underlying xml bean //check changes in the underlying xml bean
CTFill ctFill = stylesTable.getFillAt(fillId).getCTFill(); CTFill ctFill2 = stylesTable.getFillAt(fillId).getCTFill();
assertEquals(STPatternType.SOLID, ctFill.getPatternFill().getPatternType()); assertEquals(STPatternType.SOLID, ctFill2.getPatternFill().getPatternType());
//setting the same fill multiple time does not update the styles table //setting the same fill multiple time does not update the styles table
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@ -649,16 +691,18 @@ public class TestXSSFCellStyle extends TestCase {
cellStyle.setFillPattern(CellStyle.NO_FILL); cellStyle.setFillPattern(CellStyle.NO_FILL);
assertEquals(CellStyle.NO_FILL, cellStyle.getFillPattern()); assertEquals(CellStyle.NO_FILL, cellStyle.getFillPattern());
fillId = (int)cellStyle.getCoreXf().getFillId(); fillId = (int)cellStyle.getCoreXf().getFillId();
ctFill = stylesTable.getFillAt(fillId).getCTFill(); ctFill2 = stylesTable.getFillAt(fillId).getCTFill();
assertFalse(ctFill.getPatternFill().isSetPatternType()); assertFalse(ctFill2.getPatternFill().isSetPatternType());
} }
public void testGetFont() { @Test
public void testGetFont() {
assertNotNull(cellStyle.getFont()); assertNotNull(cellStyle.getFont());
} }
public void testGetSetHidden() { @Test
public void testGetSetHidden() {
assertFalse(cellStyle.getHidden()); assertFalse(cellStyle.getHidden());
cellStyle.setHidden(true); cellStyle.setHidden(true);
assertTrue(cellStyle.getHidden()); assertTrue(cellStyle.getHidden());
@ -666,7 +710,8 @@ public class TestXSSFCellStyle extends TestCase {
assertFalse(cellStyle.getHidden()); assertFalse(cellStyle.getHidden());
} }
public void testGetSetLocked() { @Test
public void testGetSetLocked() {
assertTrue(cellStyle.getLocked()); assertTrue(cellStyle.getLocked());
cellStyle.setLocked(true); cellStyle.setLocked(true);
assertTrue(cellStyle.getLocked()); assertTrue(cellStyle.getLocked());
@ -674,7 +719,8 @@ public class TestXSSFCellStyle extends TestCase {
assertFalse(cellStyle.getLocked()); assertFalse(cellStyle.getLocked());
} }
public void testGetSetIndent() { @Test
public void testGetSetIndent() {
assertEquals((short)0, cellStyle.getIndention()); assertEquals((short)0, cellStyle.getIndention());
cellStyle.setIndention((short)3); cellStyle.setIndention((short)3);
assertEquals((short)3, cellStyle.getIndention()); assertEquals((short)3, cellStyle.getIndention());
@ -682,7 +728,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals((short)13, cellStyle.getIndention()); assertEquals((short)13, cellStyle.getIndention());
} }
public void testGetSetAlignement() { @Test
public void testGetSetAlignement() {
assertNull(cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal()); assertNull(cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
assertEquals(HorizontalAlignment.GENERAL, cellStyle.getAlignmentEnum()); assertEquals(HorizontalAlignment.GENERAL, cellStyle.getAlignmentEnum());
@ -702,7 +749,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STHorizontalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal()); assertEquals(STHorizontalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
} }
public void testGetSetVerticalAlignment() { @Test
public void testGetSetVerticalAlignment() {
assertEquals(VerticalAlignment.BOTTOM, cellStyle.getVerticalAlignmentEnum()); assertEquals(VerticalAlignment.BOTTOM, cellStyle.getVerticalAlignmentEnum());
assertEquals(XSSFCellStyle.VERTICAL_BOTTOM, cellStyle.getVerticalAlignment()); assertEquals(XSSFCellStyle.VERTICAL_BOTTOM, cellStyle.getVerticalAlignment());
assertNull(cellStyle.getCellAlignment().getCTCellAlignment().getVertical()); assertNull(cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
@ -718,7 +766,8 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(STVerticalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getVertical()); assertEquals(STVerticalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
} }
public void testGetSetWrapText() { @Test
public void testGetSetWrapText() {
assertFalse(cellStyle.getWrapText()); assertFalse(cellStyle.getWrapText());
cellStyle.setWrapText(true); cellStyle.setWrapText(true);
assertTrue(cellStyle.getWrapText()); assertTrue(cellStyle.getWrapText());
@ -729,7 +778,8 @@ public class TestXSSFCellStyle extends TestCase {
/** /**
* Cloning one XSSFCellStyle onto Another, same XSSFWorkbook * Cloning one XSSFCellStyle onto Another, same XSSFWorkbook
*/ */
public void testCloneStyleSameWB() { @Test
public void testCloneStyleSameWB() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
assertEquals(1, wb.getNumberOfFonts()); assertEquals(1, wb.getNumberOfFonts());
@ -757,13 +807,18 @@ public class TestXSSFCellStyle extends TestCase {
assertTrue(18 == clone.getDataFormat()); assertTrue(18 == clone.getDataFormat());
assertEquals(2, wb.getNumberOfFonts()); assertEquals(2, wb.getNumberOfFonts());
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb);
assertNotNull(wb2);
wb2.close();
wb.close();
} }
/** /**
* Cloning one XSSFCellStyle onto Another, different XSSFWorkbooks * Cloning one XSSFCellStyle onto Another, different XSSFWorkbooks
*/ */
public void testCloneStyleDiffWB() { @Test
public void testCloneStyleDiffWB() throws IOException {
XSSFWorkbook wbOrig = new XSSFWorkbook(); XSSFWorkbook wbOrig = new XSSFWorkbook();
assertEquals(1, wbOrig.getNumberOfFonts()); assertEquals(1, wbOrig.getNumberOfFonts());
assertEquals(0, wbOrig.getStylesSource().getNumberFormats().size()); assertEquals(0, wbOrig.getStylesSource().getNumberFormats().size());
@ -803,7 +858,7 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(0, wbClone.getStylesSource().getNumberFormats().size()); assertEquals(0, wbClone.getStylesSource().getNumberFormats().size());
assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment()); assertFalse(HSSFCellStyle.ALIGN_RIGHT == clone.getAlignment());
assertFalse("TestingFont" == clone.getFont().getFontName()); assertNotEquals("TestingFont", clone.getFont().getFontName());
clone.cloneStyleFrom(orig); clone.cloneStyleFrom(orig);
@ -828,15 +883,25 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals(fmtClone.getFormat("Test##"), reload.getDataFormat()); assertEquals(fmtClone.getFormat("Test##"), reload.getDataFormat());
assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##")); assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##"));
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wbOrig)); XSSFWorkbook wbOrig2 = XSSFTestDataSamples.writeOutAndReadBack(wbOrig);
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wbClone)); assertNotNull(wbOrig2);
wbOrig2.close();
XSSFWorkbook wbClone2 = XSSFTestDataSamples.writeOutAndReadBack(wbClone);
assertNotNull(wbClone2);
wbClone2.close();
wbReload.close();
wbClone.close();
wbOrig.close();
} }
/** /**
* Avoid ArrayIndexOutOfBoundsException when creating cell style * Avoid ArrayIndexOutOfBoundsException when creating cell style
* in a workbook that has an empty xf table. * in a workbook that has an empty xf table.
*/ */
public void testBug52348() { @Test
public void testBug52348() throws IOException {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("52348.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("52348.xlsx");
StylesTable st = workbook.getStylesSource(); StylesTable st = workbook.getStylesSource();
assertEquals(0, st._getStyleXfsSize()); assertEquals(0, st._getStyleXfsSize());
@ -844,14 +909,18 @@ public class TestXSSFCellStyle extends TestCase {
XSSFCellStyle style = workbook.createCellStyle(); // no exception at this point XSSFCellStyle style = workbook.createCellStyle(); // no exception at this point
assertNull(style.getStyleXf()); assertNull(style.getStyleXf());
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(workbook)); XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
assertNotNull(wb2);
wb2.close();
workbook.close();
} }
/** /**
* Avoid ArrayIndexOutOfBoundsException when getting cell style * Avoid ArrayIndexOutOfBoundsException when getting cell style
* in a workbook that has an empty xf table. * in a workbook that has an empty xf table.
*/ */
public void testBug55650() { @Test
public void testBug55650() throws IOException {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("52348.xlsx"); XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("52348.xlsx");
StylesTable st = workbook.getStylesSource(); StylesTable st = workbook.getStylesSource();
assertEquals(0, st._getStyleXfsSize()); assertEquals(0, st._getStyleXfsSize());
@ -860,40 +929,55 @@ public class TestXSSFCellStyle extends TestCase {
XSSFCellStyle style = workbook.getSheetAt(0).getRow(0).getCell(0).getCellStyle(); XSSFCellStyle style = workbook.getSheetAt(0).getRow(0).getCell(0).getCellStyle();
assertNull(style.getStyleXf()); assertNull(style.getStyleXf());
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(workbook)); XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
assertNotNull(wb2);
wb2.close();
workbook.close();
} }
public void testShrinkToFit() { @Test
public void testShrinkToFit() throws IOException {
// Existing file // Existing file
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ShrinkToFit.xlsx"); XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("ShrinkToFit.xlsx");
Sheet s = wb.getSheetAt(0); Sheet s = wb1.getSheetAt(0);
Row r = s.getRow(0); Row r = s.getRow(0);
CellStyle cs = r.getCell(0).getCellStyle(); CellStyle cs = r.getCell(0).getCellStyle();
assertEquals(true, cs.getShrinkToFit()); assertEquals(true, cs.getShrinkToFit());
// New file // New file
XSSFWorkbook wbOrig = new XSSFWorkbook(); XSSFWorkbook wb2 = new XSSFWorkbook();
s = wbOrig.createSheet(); s = wb2.createSheet();
r = s.createRow(0); r = s.createRow(0);
cs = wbOrig.createCellStyle(); cs = wb2.createCellStyle();
cs.setShrinkToFit(false); cs.setShrinkToFit(false);
r.createCell(0).setCellStyle(cs); r.createCell(0).setCellStyle(cs);
cs = wbOrig.createCellStyle(); cs = wb2.createCellStyle();
cs.setShrinkToFit(true); cs.setShrinkToFit(true);
r.createCell(1).setCellStyle(cs); r.createCell(1).setCellStyle(cs);
// Write out, read, and check // Write out, read, and check
wb = XSSFTestDataSamples.writeOutAndReadBack(wbOrig); XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb2);
s = wb.getSheetAt(0); s = wb3.getSheetAt(0);
r = s.getRow(0); r = s.getRow(0);
assertEquals(false, r.getCell(0).getCellStyle().getShrinkToFit()); assertEquals(false, r.getCell(0).getCellStyle().getShrinkToFit());
assertEquals(true, r.getCell(1).getCellStyle().getShrinkToFit()); assertEquals(true, r.getCell(1).getCellStyle().getShrinkToFit());
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); XSSFWorkbook wb4 = XSSFTestDataSamples.writeOutAndReadBack(wb2);
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wbOrig)); assertNotNull(wb4);
wb4.close();
XSSFWorkbook wb5 = XSSFTestDataSamples.writeOutAndReadBack(wb3);
assertNotNull(wb5);
wb5.close();
wb3.close();
wb2.close();
wb1.close();
} }
@Test @Test
@ -902,31 +986,23 @@ public class TestXSSFCellStyle extends TestCase {
Sheet sheet = wb.createSheet(); Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0); Row row = sheet.createRow(0);
//CreationHelper ch = wb.getCreationHelper();
DataFormat format = wb.createDataFormat(); DataFormat format = wb.createDataFormat();
Cell cell = row.createCell(1); Cell cell = row.createCell(1);
cell.setCellValue("somevalue"); cell.setCellValue("somevalue");
CellStyle cellStyle = wb.createCellStyle(); CellStyle cellStyle2 = wb.createCellStyle();
cellStyle.setDataFormat(format.getFormat("###0")); cellStyle2.setDataFormat(format.getFormat("###0"));
cellStyle.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex()); cellStyle2.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
cellStyle.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex()); cellStyle2.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle2.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setAlignment(CellStyle.ALIGN_RIGHT); cellStyle2.setAlignment(CellStyle.ALIGN_RIGHT);
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP); cellStyle2.setVerticalAlignment(CellStyle.VERTICAL_TOP);
cell.setCellStyle(cellStyle); cell.setCellStyle(cellStyle2);
/*OutputStream stream = new FileOutputStream("C:\\temp\\CellColor.xlsx");
try {
wb.write(stream);
} finally {
stream.close();
}*/
Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb); Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
Cell cellBack = wbBack.getSheetAt(0).getRow(0).getCell(1); Cell cellBack = wbBack.getSheetAt(0).getRow(0).getCell(1);
assertNotNull(cellBack); assertNotNull(cellBack);

View File

@ -17,11 +17,16 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import junit.framework.TestCase; import static org.junit.Assert.*;
import java.io.IOException;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.Test;
public final class TestXSSFColor extends TestCase { public final class TestXSSFColor {
@Test
public void testIndexedColour() throws Exception { public void testIndexedColour() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
@ -35,8 +40,8 @@ public final class TestXSSFColor extends TestCase {
// Now check the XSSFColor // Now check the XSSFColor
// Note - 64 is a special "auto" one with no rgb equiv // Note - 64 is a special "auto" one with no rgb equiv
assertEquals(64, indexed.getIndexed()); assertEquals(64, indexed.getIndexed());
assertEquals(null, indexed.getRgb()); assertEquals(null, indexed.getRGB());
assertEquals(null, indexed.getRgbWithTint()); assertEquals(null, indexed.getRGBWithTint());
assertEquals(null, indexed.getARGBHex()); assertEquals(null, indexed.getARGBHex());
// Now move to one with indexed rgb values // Now move to one with indexed rgb values
@ -49,22 +54,25 @@ public final class TestXSSFColor extends TestCase {
assertEquals(59, indexed.getIndexed()); assertEquals(59, indexed.getIndexed());
assertEquals("FF333300", indexed.getARGBHex()); assertEquals("FF333300", indexed.getARGBHex());
assertEquals(3, indexed.getRgb().length); assertEquals(3, indexed.getRGB().length);
assertEquals(0x33, indexed.getRgb()[0]); assertEquals(0x33, indexed.getRGB()[0]);
assertEquals(0x33, indexed.getRgb()[1]); assertEquals(0x33, indexed.getRGB()[1]);
assertEquals(0x00, indexed.getRgb()[2]); assertEquals(0x00, indexed.getRGB()[2]);
assertEquals(4, indexed.getARgb().length); assertEquals(4, indexed.getARGB().length);
assertEquals(-1, indexed.getARgb()[0]); assertEquals(-1, indexed.getARGB()[0]);
assertEquals(0x33, indexed.getARgb()[1]); assertEquals(0x33, indexed.getARGB()[1]);
assertEquals(0x33, indexed.getARgb()[2]); assertEquals(0x33, indexed.getARGB()[2]);
assertEquals(0x00, indexed.getARgb()[3]); assertEquals(0x00, indexed.getARGB()[3]);
// You don't get tinted indexed colours, sorry... // You don't get tinted indexed colours, sorry...
assertEquals(null, indexed.getRgbWithTint()); assertEquals(null, indexed.getRGBWithTint());
wb.close();
} }
public void testRGBColour() throws Exception { @Test
public void testRGBColour() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx");
// Check the CTColor is as expected // Check the CTColor is as expected
@ -81,42 +89,45 @@ public final class TestXSSFColor extends TestCase {
assertEquals(-0.34999, rgb3.getTint(), 0.00001); assertEquals(-0.34999, rgb3.getTint(), 0.00001);
assertEquals("FFFFFFFF", rgb3.getARGBHex()); assertEquals("FFFFFFFF", rgb3.getARGBHex());
assertEquals(3, rgb3.getRgb().length); assertEquals(3, rgb3.getRGB().length);
assertEquals(-1, rgb3.getRgb()[0]); assertEquals(-1, rgb3.getRGB()[0]);
assertEquals(-1, rgb3.getRgb()[1]); assertEquals(-1, rgb3.getRGB()[1]);
assertEquals(-1, rgb3.getRgb()[2]); assertEquals(-1, rgb3.getRGB()[2]);
assertEquals(4, rgb3.getARgb().length); assertEquals(4, rgb3.getARGB().length);
assertEquals(-1, rgb3.getARgb()[0]); assertEquals(-1, rgb3.getARGB()[0]);
assertEquals(-1, rgb3.getARgb()[1]); assertEquals(-1, rgb3.getARGB()[1]);
assertEquals(-1, rgb3.getARgb()[2]); assertEquals(-1, rgb3.getARGB()[2]);
assertEquals(-1, rgb3.getARgb()[3]); assertEquals(-1, rgb3.getARGB()[3]);
// Tint doesn't have the alpha // Tint doesn't have the alpha
// tint = -0.34999 // tint = -0.34999
// 255 * (1 + tint) = 165 truncated // 255 * (1 + tint) = 165 truncated
// or (byte) -91 (which is 165 - 256) // or (byte) -91 (which is 165 - 256)
assertEquals(3, rgb3.getRgbWithTint().length); assertEquals(3, rgb3.getRGBWithTint().length);
assertEquals(-91, rgb3.getRgbWithTint()[0]); assertEquals(-91, rgb3.getRGBWithTint()[0]);
assertEquals(-91, rgb3.getRgbWithTint()[1]); assertEquals(-91, rgb3.getRGBWithTint()[1]);
assertEquals(-91, rgb3.getRgbWithTint()[2]); assertEquals(-91, rgb3.getRGBWithTint()[2]);
// Set the color to black (no theme). // Set the color to black (no theme).
rgb3.setRgb(new byte[] {0, 0, 0}); rgb3.setRGB(new byte[] {0, 0, 0});
assertEquals("FF000000", rgb3.getARGBHex()); assertEquals("FF000000", rgb3.getARGBHex());
assertEquals(0, rgb3.getCTColor().getRgb()[0]); assertEquals(0, rgb3.getCTColor().getRgb()[0]);
assertEquals(0, rgb3.getCTColor().getRgb()[1]); assertEquals(0, rgb3.getCTColor().getRgb()[1]);
assertEquals(0, rgb3.getCTColor().getRgb()[2]); assertEquals(0, rgb3.getCTColor().getRgb()[2]);
// Set another, is fine // Set another, is fine
rgb3.setRgb(new byte[] {16,17,18}); rgb3.setRGB(new byte[] {16,17,18});
assertEquals("FF101112", rgb3.getARGBHex()); assertEquals("FF101112", rgb3.getARGBHex());
assertEquals(0x10, rgb3.getCTColor().getRgb()[0]); assertEquals(0x10, rgb3.getCTColor().getRgb()[0]);
assertEquals(0x11, rgb3.getCTColor().getRgb()[1]); assertEquals(0x11, rgb3.getCTColor().getRgb()[1]);
assertEquals(0x12, rgb3.getCTColor().getRgb()[2]); assertEquals(0x12, rgb3.getCTColor().getRgb()[2]);
wb.close();
} }
public void testARGBColour() throws Exception { @Test
public void testARGBColour() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
// Check the CTColor is as expected // Check the CTColor is as expected
@ -128,35 +139,37 @@ public final class TestXSSFColor extends TestCase {
// Now check the XSSFColor // Now check the XSSFColor
assertEquals(0, rgb4.getIndexed()); assertEquals(0, rgb4.getIndexed());
assertEquals(0.0, rgb4.getTint()); assertEquals(0.0, rgb4.getTint(), 0);
assertEquals("FFFF0000", rgb4.getARGBHex()); assertEquals("FFFF0000", rgb4.getARGBHex());
assertEquals(3, rgb4.getRgb().length); assertEquals(3, rgb4.getRGB().length);
assertEquals(-1, rgb4.getRgb()[0]); assertEquals(-1, rgb4.getRGB()[0]);
assertEquals(0, rgb4.getRgb()[1]); assertEquals(0, rgb4.getRGB()[1]);
assertEquals(0, rgb4.getRgb()[2]); assertEquals(0, rgb4.getRGB()[2]);
assertEquals(4, rgb4.getARgb().length); assertEquals(4, rgb4.getARGB().length);
assertEquals(-1, rgb4.getARgb()[0]); assertEquals(-1, rgb4.getARGB()[0]);
assertEquals(-1, rgb4.getARgb()[1]); assertEquals(-1, rgb4.getARGB()[1]);
assertEquals(0, rgb4.getARgb()[2]); assertEquals(0, rgb4.getARGB()[2]);
assertEquals(0, rgb4.getARgb()[3]); assertEquals(0, rgb4.getARGB()[3]);
// Tint doesn't have the alpha // Tint doesn't have the alpha
assertEquals(3, rgb4.getRgbWithTint().length); assertEquals(3, rgb4.getRGBWithTint().length);
assertEquals(-1, rgb4.getRgbWithTint()[0]); assertEquals(-1, rgb4.getRGBWithTint()[0]);
assertEquals(0, rgb4.getRgbWithTint()[1]); assertEquals(0, rgb4.getRGBWithTint()[1]);
assertEquals(0, rgb4.getRgbWithTint()[2]); assertEquals(0, rgb4.getRGBWithTint()[2]);
// Turn on tinting, and check it behaves // Turn on tinting, and check it behaves
// TODO These values are suspected to be wrong... // TODO These values are suspected to be wrong...
rgb4.setTint(0.4); rgb4.setTint(0.4);
assertEquals(0.4, rgb4.getTint()); assertEquals(0.4, rgb4.getTint(), 0);
assertEquals(3, rgb4.getRgbWithTint().length); assertEquals(3, rgb4.getRGBWithTint().length);
assertEquals(-1, rgb4.getRgbWithTint()[0]); assertEquals(-1, rgb4.getRGBWithTint()[0]);
assertEquals(102, rgb4.getRgbWithTint()[1]); assertEquals(102, rgb4.getRGBWithTint()[1]);
assertEquals(102, rgb4.getRgbWithTint()[2]); assertEquals(102, rgb4.getRGBWithTint()[2]);
wb.close();
} }
} }

View File

@ -18,20 +18,26 @@
package org.apache.poi.xssf.usermodel.extensions; package org.apache.poi.xssf.usermodel.extensions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFColor; import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
import junit.framework.TestCase;
public class TestXSSFCellFill {
public class TestXSSFCellFill extends TestCase { @Test
public void testGetFillBackgroundColor() { public void testGetFillBackgroundColor() {
CTFill ctFill = CTFill.Factory.newInstance(); CTFill ctFill = CTFill.Factory.newInstance();
XSSFCellFill cellFill = new XSSFCellFill(ctFill); XSSFCellFill cellFill = new XSSFCellFill(ctFill);
@ -42,6 +48,7 @@ public class TestXSSFCellFill extends TestCase {
assertEquals(2, cellFill.getFillBackgroundColor().getIndexed()); assertEquals(2, cellFill.getFillBackgroundColor().getIndexed());
} }
@Test
public void testGetFillForegroundColor() { public void testGetFillForegroundColor() {
CTFill ctFill = CTFill.Factory.newInstance(); CTFill ctFill = CTFill.Factory.newInstance();
XSSFCellFill cellFill = new XSSFCellFill(ctFill); XSSFCellFill cellFill = new XSSFCellFill(ctFill);
@ -52,14 +59,16 @@ public class TestXSSFCellFill extends TestCase {
assertEquals(8, cellFill.getFillForegroundColor().getIndexed()); assertEquals(8, cellFill.getFillForegroundColor().getIndexed());
} }
@Test
public void testGetSetPatternType() { public void testGetSetPatternType() {
CTFill ctFill = CTFill.Factory.newInstance(); CTFill ctFill = CTFill.Factory.newInstance();
XSSFCellFill cellFill = new XSSFCellFill(ctFill); XSSFCellFill cellFill = new XSSFCellFill(ctFill);
CTPatternFill ctPatternFill = ctFill.addNewPatternFill(); CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
ctPatternFill.setPatternType(STPatternType.SOLID); ctPatternFill.setPatternType(STPatternType.SOLID);
//assertEquals(FillPatternType.SOLID_FOREGROUND.ordinal(), cellFill.getPatternType().ordinal()); assertEquals(FillPatternType.SOLID_FOREGROUND.ordinal(), cellFill.getPatternType().intValue()-1);
} }
@Test
public void testGetNotModifies() { public void testGetNotModifies() {
CTFill ctFill = CTFill.Factory.newInstance(); CTFill ctFill = CTFill.Factory.newInstance();
XSSFCellFill cellFill = new XSSFCellFill(ctFill); XSSFCellFill cellFill = new XSSFCellFill(ctFill);
@ -68,13 +77,14 @@ public class TestXSSFCellFill extends TestCase {
assertEquals(8, cellFill.getPatternType().intValue()); assertEquals(8, cellFill.getPatternType().intValue());
} }
public void testColorFromTheme() { @Test
public void testColorFromTheme() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("styles.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("styles.xlsx");
XSSFCell cellWithThemeColor = wb.getSheetAt(0).getRow(10).getCell(0); XSSFCell cellWithThemeColor = wb.getSheetAt(0).getRow(10).getCell(0);
//color RGB will be extracted from theme //color RGB will be extracted from theme
XSSFColor foregroundColor = cellWithThemeColor.getCellStyle().getFillForegroundXSSFColor(); XSSFColor foregroundColor = cellWithThemeColor.getCellStyle().getFillForegroundXSSFColor();
byte[] rgb = foregroundColor.getRgb(); byte[] rgb = foregroundColor.getRGB();
byte[] rgbWithTint = foregroundColor.getRgbWithTint(); byte[] rgbWithTint = foregroundColor.getRGBWithTint();
// Dk2 // Dk2
assertEquals(rgb[0],31); assertEquals(rgb[0],31);
assertEquals(rgb[1],73); assertEquals(rgb[1],73);
@ -86,5 +96,6 @@ public class TestXSSFCellFill extends TestCase {
assertEquals(rgbWithTint[0],120); assertEquals(rgbWithTint[0],120);
assertEquals(rgbWithTint[1],-111); assertEquals(rgbWithTint[1],-111);
assertEquals(rgbWithTint[2],-80); assertEquals(rgbWithTint[2],-80);
wb.close();
} }
} }

View File

@ -104,8 +104,8 @@ public final class Word6Extractor extends POIOLE2TextExtractor {
ret[i] = doc.getTextTable().getTextPieces().get(i).getStringBuilder().toString(); ret[i] = doc.getTextTable().getTextPieces().get(i).getStringBuilder().toString();
// Fix the line endings // Fix the line endings
ret[i].replaceAll("\r", "\ufffe"); ret[i] = ret[i].replaceAll("\r", "\ufffe");
ret[i].replaceAll("\ufffe","\r\n"); ret[i] = ret[i].replaceAll("\ufffe","\r\n");
} }
} }

View File

@ -17,11 +17,20 @@
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.awt.*; import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/** /**
* Tests the capabilities of the EscherGraphics class. * Tests the capabilities of the EscherGraphics class.
@ -29,55 +38,62 @@ import java.io.ByteArrayOutputStream;
* All tests have two escher groups available to them, * All tests have two escher groups available to them,
* one anchored at 0,0,1022,255 and another anchored * one anchored at 0,0,1022,255 and another anchored
* at 20,30,500,200 * at 20,30,500,200
*
* @author Glen Stampoultzis (glens at apache.org)
*/ */
public final class TestEscherGraphics extends TestCase { public final class TestEscherGraphics {
private HSSFWorkbook workbook; private HSSFWorkbook workbook;
private HSSFPatriarch patriarch; private HSSFPatriarch patriarch;
private HSSFShapeGroup escherGroupA; private HSSFShapeGroup escherGroupA;
private HSSFShapeGroup escherGroupB;
private EscherGraphics graphics; private EscherGraphics graphics;
protected void setUp() throws Exception @Before
{ public void setUp() throws IOException {
workbook = new HSSFWorkbook(); workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("test"); HSSFSheet sheet = workbook.createSheet("test");
patriarch = sheet.createDrawingPatriarch(); patriarch = sheet.createDrawingPatriarch();
escherGroupA = patriarch.createGroup(new HSSFClientAnchor(0,0,1022,255,(short)0,0,(short) 0,0)); escherGroupA = patriarch.createGroup(new HSSFClientAnchor(0,0,1022,255,(short)0,0,(short) 0,0));
escherGroupB = patriarch.createGroup(new HSSFClientAnchor(20,30,500,200,(short)0,0,(short) 0,0)); patriarch.createGroup(new HSSFClientAnchor(20,30,500,200,(short)0,0,(short) 0,0));
// escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); graphics = new EscherGraphics(escherGroupA, workbook, Color.black, 1.0f);
graphics = new EscherGraphics(this.escherGroupA, workbook, Color.black, 1.0f); }
super.setUp();
@After
public void closeResources() throws IOException {
workbook.close();
} }
@Test
public void testGetFont() { public void testGetFont() {
Font f = graphics.getFont(); Font f = graphics.getFont();
if (f.toString().indexOf("dialog") == -1 && f.toString().indexOf("Dialog") == -1) if (f.toString().indexOf("dialog") == -1 && f.toString().indexOf("Dialog") == -1) {
assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString());
}
} }
@Test
public void testGetFontMetrics() { public void testGetFontMetrics() {
Font f = graphics.getFont(); Font f = graphics.getFont();
if (f.toString().indexOf("dialog") != -1 || f.toString().indexOf("Dialog") != -1) if (f.toString().indexOf("dialog") != -1 || f.toString().indexOf("Dialog") != -1) {
return; return;
}
FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont());
assertEquals(7, fontMetrics.charWidth('X')); assertEquals(7, fontMetrics.charWidth('X'));
assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString());
} }
@Test
public void testSetFont() { public void testSetFont() {
Font f = new Font("Helvetica", 0, 12); Font f = new Font("Helvetica", 0, 12);
graphics.setFont(f); graphics.setFont(f);
assertEquals(f, graphics.getFont()); assertEquals(f, graphics.getFont());
} }
@Test
public void testSetColor() { public void testSetColor() {
graphics.setColor(Color.red); graphics.setColor(Color.red);
assertEquals(Color.red, graphics.getColor()); assertEquals(Color.red, graphics.getColor());
} }
@Test
public void testFillRect() { public void testFillRect() {
graphics.fillRect( 10, 10, 20, 20 ); graphics.fillRect( 10, 10, 20, 20 );
HSSFSimpleShape s = (HSSFSimpleShape) escherGroupA.getChildren().get(0); HSSFSimpleShape s = (HSSFSimpleShape) escherGroupA.getChildren().get(0);
@ -88,12 +104,14 @@ public final class TestEscherGraphics extends TestCase {
assertEquals(30, s.getAnchor().getDx2()); assertEquals(30, s.getAnchor().getDx2());
} }
@Test
public void testDrawString() { public void testDrawString() {
graphics.drawString("This is a test", 10, 10); graphics.drawString("This is a test", 10, 10);
HSSFTextbox t = (HSSFTextbox) escherGroupA.getChildren().get(0); HSSFTextbox t = (HSSFTextbox) escherGroupA.getChildren().get(0);
assertEquals("This is a test", t.getString().getString()); assertEquals("This is a test", t.getString().getString());
} }
@Test
public void testGetDataBackAgain() throws Exception { public void testGetDataBackAgain() throws Exception {
HSSFSheet s; HSSFSheet s;
HSSFShapeGroup s1; HSSFShapeGroup s1;
@ -284,6 +302,6 @@ public final class TestEscherGraphics extends TestCase {
assertEquals(200, s2.getAnchor().getDy2()); assertEquals(200, s2.getAnchor().getDy2());
// Not working just yet // Not working just yet
//assertEquals("I am text box 1", tbox1.getString().getString()); assertEquals("I am text box 1", tbox1.getString().getString());
} }
} }

View File

@ -17,30 +17,44 @@
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.awt.*; import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/** /**
* Tests the Graphics2d drawing capability. * Tests the Graphics2d drawing capability.
*
* @author Glen Stampoultzis (glens at apache.org)
*/ */
public final class TestEscherGraphics2d extends TestCase { public final class TestEscherGraphics2d {
private HSSFWorkbook workbook;
private HSSFShapeGroup escherGroup; private HSSFShapeGroup escherGroup;
private EscherGraphics2d graphics; private EscherGraphics2d graphics;
@Override @Before
protected void setUp() { public void setUp() {
HSSFWorkbook workbook = new HSSFWorkbook(); workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("test"); HSSFSheet sheet = workbook.createSheet("test");
escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0)); escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0));
escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor());
EscherGraphics g = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f); EscherGraphics g = new EscherGraphics(escherGroup, workbook, Color.black, 1.0f);
graphics = new EscherGraphics2d(g); graphics = new EscherGraphics2d(g);
} }
@After
public void closeResources() throws IOException {
workbook.close();
}
@Test
public void testDrawString() { public void testDrawString() {
graphics.drawString("This is a test", 10, 10); graphics.drawString("This is a test", 10, 10);
HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0); HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0);
@ -71,7 +85,8 @@ public final class TestEscherGraphics2d extends TestCase {
} }
} }
public void testFillRect() { @Test
public void testFillRect() {
graphics.fillRect( 10, 10, 20, 20 ); graphics.fillRect( 10, 10, 20, 20 );
HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0);
assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType()); assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType());
@ -81,29 +96,37 @@ public final class TestEscherGraphics2d extends TestCase {
assertEquals(30, s.getAnchor().getDx2()); assertEquals(30, s.getAnchor().getDx2());
} }
public void testGetFontMetrics() { @Test
public void testGetFontMetrics() {
FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont());
if (isDialogPresent()) // if dialog is returned we can't run the test properly. if (isDialogPresent()) {
// if dialog is returned we can't run the test properly.
return; return;
}
assertEquals(7, fontMetrics.charWidth('X')); assertEquals(7, fontMetrics.charWidth('X'));
assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString());
} }
public void testSetFont() { @Test
public void testSetFont() {
Font f = new Font("Helvetica", 0, 12); Font f = new Font("Helvetica", 0, 12);
graphics.setFont(f); graphics.setFont(f);
assertEquals(f, graphics.getFont()); assertEquals(f, graphics.getFont());
} }
public void testSetColor() { @Test
public void testSetColor() {
graphics.setColor(Color.red); graphics.setColor(Color.red);
assertEquals(Color.red, graphics.getColor()); assertEquals(Color.red, graphics.getColor());
} }
public void testGetFont() { @Test
public void testGetFont() {
Font f = graphics.getFont(); Font f = graphics.getFont();
if (isDialogPresent()) // if dialog is returned we can't run the test properly. if (isDialogPresent()) {
// if dialog is returned we can't run the test properly.
return; return;
}
assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString());
} }
@ -113,7 +136,8 @@ public final class TestEscherGraphics2d extends TestCase {
return fontDebugStr.indexOf("dialog") != -1 || fontDebugStr.indexOf("Dialog") != -1; return fontDebugStr.indexOf("dialog") != -1 || fontDebugStr.indexOf("Dialog") != -1;
} }
public void testDraw() { @Test
public void testDraw() {
graphics.draw(new Line2D.Double(10,10,20,20)); graphics.draw(new Line2D.Double(10,10,20,20));
HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0);
assertTrue(s.getShapeType() == HSSFSimpleShape.OBJECT_TYPE_LINE); assertTrue(s.getShapeType() == HSSFSimpleShape.OBJECT_TYPE_LINE);

View File

@ -68,7 +68,7 @@ public abstract class BaseTestBugzillaIssues {
* Also tests bug 15353 (problems with hyperlinks to Google) * Also tests bug 15353 (problems with hyperlinks to Google)
*/ */
@Test @Test
public final void bug23094() throws Exception { public final void bug23094() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
Sheet s = wb1.createSheet(); Sheet s = wb1.createSheet();
Row r = s.createRow(0); Row r = s.createRow(0);
@ -92,7 +92,7 @@ public abstract class BaseTestBugzillaIssues {
* open resulting file in Excel to check results! * open resulting file in Excel to check results!
* @param num the number of strings to generate * @param num the number of strings to generate
*/ */
public final void bug15375(int num) throws Exception { public final void bug15375(int num) throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
Sheet sheet = wb1.createSheet(); Sheet sheet = wb1.createSheet();
CreationHelper factory = wb1.getCreationHelper(); CreationHelper factory = wb1.getCreationHelper();
@ -137,7 +137,7 @@ public abstract class BaseTestBugzillaIssues {
* Merged regions were being removed from the parent in cloned sheets * Merged regions were being removed from the parent in cloned sheets
*/ */
@Test @Test
public void bug22720() throws Exception { public void bug22720() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet("TEST"); wb.createSheet("TEST");
Sheet template = wb.getSheetAt(0); Sheet template = wb.getSheetAt(0);
@ -165,7 +165,7 @@ public abstract class BaseTestBugzillaIssues {
} }
@Test @Test
public final void bug28031() throws Exception { public final void bug28031() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
Sheet sheet = wb1.createSheet(); Sheet sheet = wb1.createSheet();
wb1.setSheetName(0, "Sheet1"); wb1.setSheetName(0, "Sheet1");
@ -191,7 +191,7 @@ public abstract class BaseTestBugzillaIssues {
* {=SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""))>0,1))} * {=SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""))>0,1))}
*/ */
@Test @Test
public final void bug21334() throws Exception { public final void bug21334() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
Sheet sh = wb1.createSheet(); Sheet sh = wb1.createSheet();
Cell cell = sh.createRow(0).createCell(0); Cell cell = sh.createRow(0).createCell(0);
@ -208,7 +208,7 @@ public abstract class BaseTestBugzillaIssues {
/** another test for the number of unique strings issue /** another test for the number of unique strings issue
*test opening the resulting file in Excel*/ *test opening the resulting file in Excel*/
@Test @Test
public final void bug22568() throws Exception { public final void bug22568() throws IOException {
int r=2000;int c=3; int r=2000;int c=3;
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
@ -260,7 +260,7 @@ public abstract class BaseTestBugzillaIssues {
* Bug 42448: Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 * Bug 42448: Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69
*/ */
@Test @Test
public final void bug42448() throws Exception { public final void bug42448() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Cell cell = wb.createSheet().createRow(0).createCell(0); Cell cell = wb.createSheet().createRow(0).createCell(0);
cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69"); cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69");
@ -269,7 +269,7 @@ public abstract class BaseTestBugzillaIssues {
} }
@Test @Test
public void bug18800() throws Exception { public void bug18800() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
wb1.createSheet("TEST"); wb1.createSheet("TEST");
Sheet sheet = wb1.cloneSheet(0); Sheet sheet = wb1.cloneSheet(0);
@ -300,7 +300,7 @@ public abstract class BaseTestBugzillaIssues {
} }
@Test @Test
public void bug43093() throws Exception { public void bug43093() throws IOException {
Workbook xlw = _testDataProvider.createWorkbook(); Workbook xlw = _testDataProvider.createWorkbook();
addNewSheetWithCellsA1toD4(xlw, 1); addNewSheetWithCellsA1toD4(xlw, 1);
@ -322,7 +322,7 @@ public abstract class BaseTestBugzillaIssues {
} }
@Test @Test
public void bug46729_testMaxFunctionArguments() throws Exception { public void bug46729_testMaxFunctionArguments() throws IOException {
String[] func = {"COUNT", "AVERAGE", "MAX", "MIN", "OR", "SUBTOTAL", "SKEW"}; String[] func = {"COUNT", "AVERAGE", "MAX", "MIN", "OR", "SUBTOTAL", "SKEW"};
SpreadsheetVersion ssVersion = _testDataProvider.getSpreadsheetVersion(); SpreadsheetVersion ssVersion = _testDataProvider.getSpreadsheetVersion();
@ -362,7 +362,7 @@ public abstract class BaseTestBugzillaIssues {
} }
@Test @Test
public final void bug50681_testAutoSize() throws Exception { public final void bug50681_testAutoSize() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
BaseTestSheetAutosizeColumn.fixFonts(wb); BaseTestSheetAutosizeColumn.fixFonts(wb);
Sheet sheet = wb.createSheet("Sheet1"); Sheet sheet = wb.createSheet("Sheet1");
@ -456,7 +456,7 @@ public abstract class BaseTestBugzillaIssues {
* CreateFreezePane column/row order check * CreateFreezePane column/row order check
*/ */
@Test @Test
public void bug49381() throws Exception { public void bug49381() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
int colSplit = 1; int colSplit = 1;
int rowSplit = 2; int rowSplit = 2;
@ -510,7 +510,7 @@ public abstract class BaseTestBugzillaIssues {
* open resulting file in excel, and check that there is a link to Google * open resulting file in excel, and check that there is a link to Google
*/ */
@Test @Test
public void bug15353() throws Exception { public void bug15353() throws IOException {
String hyperlinkF = "HYPERLINK(\"http://google.com\",\"Google\")"; String hyperlinkF = "HYPERLINK(\"http://google.com\",\"Google\")";
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
@ -536,7 +536,7 @@ public abstract class BaseTestBugzillaIssues {
* HLookup and VLookup with optional arguments * HLookup and VLookup with optional arguments
*/ */
@Test @Test
public void bug51024() throws Exception { public void bug51024() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet(); Sheet s = wb.createSheet();
Row r1 = s.createRow(0); Row r1 = s.createRow(0);
@ -573,7 +573,7 @@ public abstract class BaseTestBugzillaIssues {
} }
@Test @Test
public void stackoverflow23114397() throws Exception { public void stackoverflow23114397() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
DataFormat format = wb.getCreationHelper().createDataFormat(); DataFormat format = wb.getCreationHelper().createDataFormat();
@ -642,7 +642,7 @@ public abstract class BaseTestBugzillaIssues {
* =ISNUMBER(SEARCH("AM",A1)) evaluation * =ISNUMBER(SEARCH("AM",A1)) evaluation
*/ */
@Test @Test
public void stackoverflow26437323() throws Exception { public void stackoverflow26437323() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet(); Sheet s = wb.createSheet();
Row r1 = s.createRow(0); Row r1 = s.createRow(0);
@ -799,7 +799,7 @@ public abstract class BaseTestBugzillaIssues {
*/ */
@Ignore("Fix this to evaluate for XSSF, Fix this to work at all for HSSF") @Ignore("Fix this to evaluate for XSSF, Fix this to work at all for HSSF")
@Test @Test
public void bug46670() throws Exception { public void bug46670() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
Sheet s = wb1.createSheet(); Sheet s = wb1.createSheet();
Row r1 = s.createRow(0); Row r1 = s.createRow(0);
@ -925,7 +925,7 @@ public abstract class BaseTestBugzillaIssues {
* that it now is again * that it now is again
*/ */
@Test @Test
public void bug48718() throws Exception { public void bug48718() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
int startingFonts = wb instanceof HSSFWorkbook ? 4 : 1; int startingFonts = wb instanceof HSSFWorkbook ? 4 : 1;
@ -947,7 +947,7 @@ public abstract class BaseTestBugzillaIssues {
} }
@Test @Test
public void bug57430() throws Exception { public void bug57430() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
wb.createSheet("Sheet1"); wb.createSheet("Sheet1");
@ -1050,7 +1050,7 @@ public abstract class BaseTestBugzillaIssues {
* kind of value from a Formula cell * kind of value from a Formula cell
*/ */
@Test @Test
public void bug47815() throws Exception { public void bug47815() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet(); Sheet s = wb.createSheet();
Row r = s.createRow(0); Row r = s.createRow(0);
@ -1109,7 +1109,7 @@ public abstract class BaseTestBugzillaIssues {
} }
@Test @Test
public void test58113() throws Exception { public void test58113() throws IOException {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet( "Test" ); Sheet sheet = wb.createSheet( "Test" );
@ -1155,7 +1155,7 @@ public abstract class BaseTestBugzillaIssues {
* Mid in it, can give #VALUE in Excel * Mid in it, can give #VALUE in Excel
*/ */
@Test @Test
public void bug55747() throws Exception { public void bug55747() throws IOException {
Workbook wb1 = _testDataProvider.createWorkbook(); Workbook wb1 = _testDataProvider.createWorkbook();
FormulaEvaluator ev = wb1.getCreationHelper().createFormulaEvaluator(); FormulaEvaluator ev = wb1.getCreationHelper().createFormulaEvaluator();
Sheet s = wb1.createSheet(); Sheet s = wb1.createSheet();