aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-06-03 23:57:31 +0000
committerJosh Micich <josh@apache.org>2009-06-03 23:57:31 +0000
commit8d91fa9c11741ef561af064ba13b9647486db5a9 (patch)
tree2a374e2318e5f8a683d3d2ff536c0279c5832269
parent5fbf7c235004a2d3978a98aaa06b468bf482cbe6 (diff)
downloadpoi-8d91fa9c11741ef561af064ba13b9647486db5a9.tar.gz
poi-8d91fa9c11741ef561af064ba13b9647486db5a9.zip
submitted in error
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@781622 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/poi/hssf/dev/BiffViewer.java2
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFName.java30
-rw-r--r--src/java/org/apache/poi/ss/formula/FormulaParser.java2
-rw-r--r--src/java/org/apache/poi/ss/usermodel/Cell.java18
-rw-r--r--src/java/org/apache/poi/ss/usermodel/Sheet.java27
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java8
6 files changed, 75 insertions, 12 deletions
diff --git a/src/java/org/apache/poi/hssf/dev/BiffViewer.java b/src/java/org/apache/poi/hssf/dev/BiffViewer.java
index 264aa6d7f8..484dd58143 100644
--- a/src/java/org/apache/poi/hssf/dev/BiffViewer.java
+++ b/src/java/org/apache/poi/hssf/dev/BiffViewer.java
@@ -155,6 +155,7 @@ public final class BiffViewer {
case EndRecord.sid: return new EndRecord(in);
case ExtSSTRecord.sid: return new ExtSSTRecord(in);
case ExtendedFormatRecord.sid: return new ExtendedFormatRecord(in);
+ case ExternalNameRecord.sid: return new ExternalNameRecord(in);
case ExternSheetRecord.sid: return new ExternSheetRecord(in);
case FilePassRecord.sid: return new FilePassRecord(in);
case FileSharingRecord.sid: return new FileSharingRecord(in);
@@ -358,6 +359,7 @@ public final class BiffViewer {
*
*/
public static void main(String[] args) {
+ args = new String[] { "--out", "c:/josh/temp/ex47199-23710-twoPSBs-x.xls", };
CommandArgs cmdArgs;
try {
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFName.java b/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
index bceaf340ad..1c21c0f5b1 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
@@ -21,8 +21,10 @@ import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.usermodel.Name;
+import org.apache.poi.ss.util.CellReference;
/**
* High Level Representation of a 'defined name' which could be a 'built-in' name,
@@ -133,13 +135,37 @@ public final class HSSFName implements Name {
}
}
- private static void validateName(String name){
- if(name.length() == 0) throw new IllegalArgumentException("Name cannot be blank");
+ static void validateName(String name){
+ if(name.length() == 0) {
+ throw new IllegalArgumentException("Name cannot be blank");
+ }
char c = name.charAt(0);
if(!(c == '_' || Character.isLetter(c)) || name.indexOf(' ') != -1) {
throw new IllegalArgumentException("Invalid name: '"+name+"'; Names must begin with a letter or underscore and not contain spaces");
}
+ if (true) {
+ return;
+ }
+ int looksLikeType = CellReference.classifyCellReference(name, SpreadsheetVersion.EXCEL97);
+ String looksLikeStr;
+ switch (looksLikeType) {
+ case CellReference.NameType.NAMED_RANGE:
+ // all OK
+ return;
+ case CellReference.NameType.CELL:
+ looksLikeStr = "cell reference";
+ break;
+ case CellReference.NameType.COLUMN:
+ looksLikeStr = "column reference";
+ break;
+ default:
+ looksLikeStr = null;
+ }
+ if (looksLikeType != CellReference.NameType.NAMED_RANGE) {
+ throw new IllegalArgumentException("Specified name '" + name + "' is invalid"
+ + (looksLikeStr == null ? "" : " because it looks like a " + looksLikeStr));
+ }
}
/**
diff --git a/src/java/org/apache/poi/ss/formula/FormulaParser.java b/src/java/org/apache/poi/ss/formula/FormulaParser.java
index ec2252d5e0..5366b6028d 100644
--- a/src/java/org/apache/poi/ss/formula/FormulaParser.java
+++ b/src/java/org/apache/poi/ss/formula/FormulaParser.java
@@ -557,7 +557,7 @@ public final class FormulaParser {
// which will either be named ranges or functions
StringBuilder sb = new StringBuilder();
- if (!Character.isLetter(look)) {
+ if (!isValidDefinedNameChar(look)) {
throw expected("number, string, or defined name");
}
while (isValidDefinedNameChar(look)) {
diff --git a/src/java/org/apache/poi/ss/usermodel/Cell.java b/src/java/org/apache/poi/ss/usermodel/Cell.java
index aa1e8c3955..0a76061e45 100644
--- a/src/java/org/apache/poi/ss/usermodel/Cell.java
+++ b/src/java/org/apache/poi/ss/usermodel/Cell.java
@@ -149,11 +149,19 @@ public interface Cell {
void setCellValue(double value);
/**
- * Set a boolean value for the cell
- *
- * @param value the boolean value to set this cell to. For formulas we'll set the
- * precalculated value, for booleans we'll set its value. For other types we
- * will change the cell to a boolean cell and set its value.
+ * Converts the supplied date to its equivalent Excel numeric value and sets
+ * that into the cell.
+ * <p/>
+ * <b>Note</b> - There is actually no 'DATE' cell type in Excel. In many
+ * cases (when entering date values), Excel automatically adjusts the
+ * <i>cell style</i> to some date format, creating the illusion that the cell
+ * data type is now something besides {@link Cell#CELL_TYPE_NUMERIC}. POI
+ * does not attempt to replicate this behaviour. To make a numeric cell
+ * display as a date, use {@link #setCellStyle(CellStyle)} etc.
+ *
+ * @param value the numeric value to set this cell to. For formulas we'll set the
+ * precalculated value, for numerics we'll set its value. For other types we
+ * will change the cell to a numerics cell and set its value.
*/
void setCellValue(Date value);
diff --git a/src/java/org/apache/poi/ss/usermodel/Sheet.java b/src/java/org/apache/poi/ss/usermodel/Sheet.java
index ffeb96abda..9ee99a4f2a 100644
--- a/src/java/org/apache/poi/ss/usermodel/Sheet.java
+++ b/src/java/org/apache/poi/ss/usermodel/Sheet.java
@@ -406,8 +406,8 @@ public interface Sheet extends Iterable<Row> {
PrintSetup getPrintSetup();
/**
- * Gets the user model for the default document header.
- * <p>
+ * Gets the user model for the default document header. If it does not exist, the footer will
+ * be created. See {@link #hasHeader()} and {@link #removeHeader()}. <br/>
* Note that XSSF offers more kinds of document headers than HSSF does
* </p>
* @return the document header.
@@ -415,12 +415,33 @@ public interface Sheet extends Iterable<Row> {
Header getHeader();
/**
- * Gets the user model for the default document footer.
+ * @return <code>true</code> if this sheet has a header
+ */
+// boolean hasHeader();
+
+ /**
+ * Removes the header if it exists. If it does not exist, this method does nothing.
+ */
+// void removeHeader();
+
+ /**
+ * Gets the user model for the default document footer. If it does not exist, the footer will
+ * be created. See {@link #hasFooter()} and {@link #removeFooter()}. <br/>
* Note that XSSF offers more kinds of document footers than HSSF does.
*
* @return the document footer.
*/
Footer getFooter();
+
+ /**
+ * @return <code>true</code> if this sheet has a footer
+ */
+// boolean hasFooter();
+
+ /**
+ * Removes the footer if it exists. If it does not exist, this method does nothing.
+ */
+// void removeFooter();
/**
* Sets a flag indicating whether this sheet is selected.
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
index 88a2c0cf16..ee97c35d46 100755
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFName.java
@@ -29,6 +29,7 @@ import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
+import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.util.AreaReference;
/**
@@ -250,6 +251,11 @@ public final class TestHSSFName extends BaseTestNamedRange {
for (int i = 0; i < ptgs.length; i++) {
assertEquals('R', ptgs[i].getRVAType());
}
-
}
+
+ public void testValidNames() {
+ Name n = getTestDataProvider().createWorkbook().createName();
+ n.setNameName("B00000001");
+
+ }
} \ No newline at end of file