+ * Returns a ValueEval that may be one or more values, such as the allowed values for a data validation constraint.
+ *
+ * @param formula
+ * @param target cell context for the operation
+ * @param region containing the cell
+ * @return ValueEval for one or more values
+ * @throws IllegalArgumentException if target does not define a sheet name to evaluate the formula on.
+ */
+ public ValueEval EvaluateList(String formula, CellReference target, CellRangeAddressBase region) {
+ return Evaluate(formula, target, region, FormulaType.DataValidationList);
+ }
+
private ValueEval Evaluate(String formula, CellReference target, CellRangeAddressBase region, FormulaType formulaType)
{
String sheetName = target == null ? null : target.SheetName;
@@ -461,6 +481,8 @@ private ValueEval EvaluateAny(IEvaluationCell srcCell, int sheetIndex,
//return cce.GetValue();
return result;
}
+
+
/**
* Adds the current cell reference to the exception for easier debugging.
* Would be nice to get the formula text as well, but that seems to require
@@ -709,6 +731,7 @@ public ValueEval EvaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs)
{
throw new InvalidOperationException("evaluation stack not empty");
}
+ // "unwrap" result to just the value relevant for the source cell if needed
ValueEval result;
if (ec.IsSingleValue)
{
@@ -784,14 +807,14 @@ public static ValueEval DereferenceResult(ValueEval evaluationResult, int srcRow
return value;
}
/**
- * Dereferences a single value from any AreaEval or RefEval evaluation
- * result. If the supplied evaluationResult is just a plain value, it is
- * returned as-is.
- *
- * @return a {@link NumberEval}, {@link StringEval}, {@link BoolEval}, or
- * {@link ErrorEval}. Never null. {@link BlankEval} is
- * converted to {@link NumberEval#ZERO}
- */
+ * Dereferences a single value from any AreaEval or RefEval evaluation
+ * result. If the supplied evaluationResult is just a plain value, it is
+ * returned as-is.
+ *
+ * @return a {@link NumberEval}, {@link StringEval}, {@link BoolEval}, or
+ * {@link ErrorEval}. Never null. {@link BlankEval} is
+ * converted to {@link NumberEval#ZERO}
+ */
public static ValueEval DereferenceResult(ValueEval evaluationResult, OperationEvaluationContext ec)
{
ValueEval value;
diff --git a/main/Util/DocumentFormatException.cs b/main/Util/DocumentFormatException.cs
new file mode 100644
index 000000000..442abc15d
--- /dev/null
+++ b/main/Util/DocumentFormatException.cs
@@ -0,0 +1,69 @@
+
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+namespace NPOI.Util
+{
+ /// false, this will throw this
+ * exception with the message.
+ *
+ * @param assertTrue
+ * @param message
+ */
+ public static void Check(bool assertTrue, String message)
+ {
+ if (! assertTrue)
+ {
+ throw new RecordFormatException(message);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/ooxml/Util/PackageHelper.cs b/ooxml/Util/PackageHelper.cs
index df29d079a..e0c339721 100644
--- a/ooxml/Util/PackageHelper.cs
+++ b/ooxml/Util/PackageHelper.cs
@@ -134,7 +134,7 @@ private static void Copy(OPCPackage pkg, PackagePart part, OPCPackage tgt, Packa
* @param src source properties
* @param tgt target properties
*/
- private static void CopyProperties(PackageProperties src, PackageProperties tgt)
+ private static void CopyProperties(IPackageProperties src, IPackageProperties tgt)
{
tgt.SetCategoryProperty(src.GetCategoryProperty());
tgt.SetContentStatusProperty(src.GetContentStatusProperty());
diff --git a/ooxml/XSSF/Util/EvilUnclosedBRFixingInputStream.cs b/ooxml/XSSF/Util/EvilUnclosedBRFixingInputStream.cs
index 80dbb41ab..4f58ce4e1 100644
--- a/ooxml/XSSF/Util/EvilUnclosedBRFixingInputStream.cs
+++ b/ooxml/XSSF/Util/EvilUnclosedBRFixingInputStream.cs
@@ -20,11 +20,6 @@ limitations under the License.
using NPOI.Util;
namespace NPOI.XSSF.Util
{
-
-
-
-
-
/**
* This is a seriously sick fix for the fact that some .xlsx
* files contain raw bits of HTML, without being escaped
@@ -46,272 +41,6 @@ public EvilUnclosedBRFixingInputStream(InputStream source)
}
}
- //public class EvilUnclosedBRFixingInputStream : Stream
- //{
- // private Stream source;
- // private byte[] spare;
-
- // private static byte[] detect = new byte[] {
- // (byte)'<', (byte)'b', (byte)'r', (byte)'>'
- // };
-
- // public EvilUnclosedBRFixingInputStream(Stream source)
- // {
- // this.source = source;
- // }
-
- // /**
- // * Warning - doesn't fix!
- // */
-
- // public int Read()
- // {
- // return source.ReadByte();
- // }
-
-
- // public override int Read(byte[] b, int off, int len)
- // {
- // // Grab any data left from last time
- // int readA = ReadFromSpare(b, off, len);
-
- // // Now read from the stream
- // int readB = source.Read(b, off + readA, len - readA);
-
- // // Figure out how much we've done
- // int read;
- // if (readB == -1 || readB == 0)
- // {
- // if (readA == 0)
- // {
- // return readB;
- // }
- // read = readA;
- // }
- // else
- // {
- // read = readA + readB;
- // }
-
- // // Fix up our data
- // if (read > 0)
- // {
- // read = fixUp(b, off, read);
- // }
-
- // // All done
- // return read;
- // }
-
-
- // public int Read(byte[] b)
- // {
- // return this.Read(b, 0, b.Length);
- // }
-
- // /**
- // * Reads into the buffer from the spare bytes
- // */
- // private int ReadFromSpare(byte[] b, int offset, int len)
- // {
- // if (spare == null) return 0;
- // if (len == 0) throw new ArgumentException("Asked to read 0 bytes");
-
- // if (spare.Length <= len)
- // {
- // // All fits, good
- // Array.Copy(spare, 0, b, offset, spare.Length);
- // int read = spare.Length;
- // spare = null;
- // return read;
- // }
- // else
- // {
- // // We have more spare than they can copy with...
- // byte[] newspare = new byte[spare.Length - len];
- // Array.Copy(spare, 0, b, offset, len);
- // Array.Copy(spare, len, newspare, 0, newspare.Length);
- // spare = newspare;
- // return len;
- // }
- // }
- // private void AddToSpare(byte[] b, int offset, int len, bool atTheEnd)
- // {
- // if (spare == null)
- // {
- // spare = new byte[len];
- // Array.Copy(b, offset, spare, 0, len);
- // }
- // else
- // {
- // byte[] newspare = new byte[spare.Length + len];
- // if (atTheEnd)
- // {
- // Array.Copy(spare, 0, newspare, 0, spare.Length);
- // Array.Copy(b, offset, newspare, spare.Length, len);
- // }
- // else
- // {
- // Array.Copy(b, offset, newspare, 0, len);
- // Array.Copy(spare, 0, newspare, len, spare.Length);
- // }
- // spare = newspare;
- // }
- // }
-
- // private int fixUp(byte[] b, int offset, int read)
- // {
- // // Do we have any potential overhanging ones?
- // for (int i = 0; i < detect.Length - 1; i++)
- // {
- // int base1 = offset + read - 1 - i;
- // if (base1 < 0) continue;
-
- // bool going = true;
- // for (int j = 0; j <= i && going; j++)
- // {
- // if (b[base1 + j] == detect[j])
- // {
- // // Matches
- // }
- // else
- // {
- // going = false;
- // }
- // }
- // if (going)
- // {
- // // There could be a
handing over the end, eg
fixAt = new List
!
- // int fixes = 0;
- // foreach (int at in fixAt)
- // {
- // if (at > offset + read - detect.Length - overshoot - fixes)
- // {
- // overshoot = needed - at - 1 - fixes;
- // break;
- // }
- // fixes++;
- // }
-
- // AddToSpare(b, offset + read - overshoot, overshoot, false);
- // read -= overshoot;
- // }
-
- // // Fix them, in reverse order so the
- // // positions are valid
- // for (int j = fixAt.Count - 1; j >= 0; j--)
- // {
- // int i = fixAt[j];
- // if (i >= read + offset)
- // {
- // // This one has Moved into the overshoot
- // continue;
- // }
- // if (i > read - 3)
- // {
- // // This one has Moved into the overshoot
- // continue;
- // }
-
- // byte[] tmp = new byte[read - i - 3];
- // Array.Copy(b, i + 3, tmp, 0, tmp.Length);
- // b[i + 3] = (byte)'/';
- // Array.Copy(tmp, 0, b, i + 4, tmp.Length);
- // // It got one longer
- // read++;
- // }
- // return read;
- // }
-
- // public override bool CanRead
- // {
- // get { return true; }
- // }
-
- // public override bool CanSeek
- // {
- // get { return true; }
- // }
-
- // public override bool CanWrite
- // {
- // get { return false; }
- // }
-
- // public override void Flush()
- // {
-
- // }
-
- // public override long Length
- // {
- // get { return source.Length; }
- // }
-
- // public override long Position
- // {
- // get
- // {
- // return source.Position;
- // }
- // set
- // {
- // source.Position = value;
- // }
- // }
-
- // public override long Seek(long offset, SeekOrigin origin)
- // {
- // return source.Seek(offset, origin);
- // }
-
- // public override void SetLength(long value)
- // {
- // throw new InvalidOperationException();
- // }
-
- // public override void Write(byte[] buffer, int offset, int count)
- // {
- // throw new InvalidOperationException();
- // }
- //}
}
diff --git a/ooxml/XWPF/Usermodel/XWPFRelation.cs b/ooxml/XWPF/Usermodel/XWPFRelation.cs
index da00ab65e..e621ffb6f 100644
--- a/ooxml/XWPF/Usermodel/XWPFRelation.cs
+++ b/ooxml/XWPF/Usermodel/XWPFRelation.cs
@@ -17,6 +17,7 @@ limitations under the License.
namespace NPOI.XWPF.UserModel
{
+ using NPOI.OpenXml4Net.OPC;
using System;
using System.Collections.Generic;
/**
@@ -32,26 +33,26 @@ public class XWPFRelation : POIXMLRelation
public static XWPFRelation DOCUMENT = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
+ PackageRelationshipTypes.CORE_DOCUMENT,
"/word/document.xml",
- null
+ null
);
public static XWPFRelation TEMPLATE = new XWPFRelation(
- "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
- "/word/document.xml",
- null
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
+ PackageRelationshipTypes.CORE_DOCUMENT,
+ "/word/document.xml",
+ null
);
public static XWPFRelation MACRO_DOCUMENT = new XWPFRelation(
- "application/vnd.ms-word.document.macroEnabled.main+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
+ "application/vnd.ms-word.document.macroEnabled.main+xml",
+ PackageRelationshipTypes.CORE_DOCUMENT,
"/word/document.xml",
- null
+ null
);
public static XWPFRelation MACRO_TEMPLATE_DOCUMENT = new XWPFRelation(
- "application/vnd.ms-word.template.macroEnabledTemplate.main+xml",
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
+ "application/vnd.ms-word.template.macroEnabledTemplate.main+xml",
+ PackageRelationshipTypes.CORE_DOCUMENT,
"/word/document.xml",
null
);
diff --git a/openxml4Net/OPC/Internal/PackagePropertiesPart.cs b/openxml4Net/OPC/Internal/PackagePropertiesPart.cs
index 405004b5f..5aeff6098 100644
--- a/openxml4Net/OPC/Internal/PackagePropertiesPart.cs
+++ b/openxml4Net/OPC/Internal/PackagePropertiesPart.cs
@@ -17,15 +17,13 @@ namespace NPOI.OpenXml4Net.OPC.Internal
* @author Julien Chable
* @version 1.0
*/
- public class PackagePropertiesPart : PackagePart, PackageProperties
+ public class PackagePropertiesPart : PackagePart, IPackageProperties
{
- public static String NAMESPACE_DC = "http://purl.org/dc/elements/1.1/";
+ public static String NAMESPACE_DC_URI = PackageProperties.NAMESPACE_DC;
- public static String NAMESPACE_DC_URI = "http://purl.org/dc/elements/1.1/";
+ public static String NAMESPACE_CP_URI = PackageNamespaces.CORE_PROPERTIES;
- public static String NAMESPACE_CP_URI = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
-
- public static String NAMESPACE_DCTERMS_URI = "http://purl.org/dc/terms/";
+ public static String NAMESPACE_DCTERMS_URI = PackageProperties.NAMESPACE_DCTERMS;
public static String NAMESPACE_XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
private static String DEFAULT_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
diff --git a/openxml4Net/OPC/OPCPackage.cs b/openxml4Net/OPC/OPCPackage.cs
index d1afa4938..d53b3ea0d 100644
--- a/openxml4Net/OPC/OPCPackage.cs
+++ b/openxml4Net/OPC/OPCPackage.cs
@@ -604,7 +604,7 @@ internal void ThrowExceptionIfWriteOnly()
*
* @return The PackageProperties part of this package.
*/
- public PackageProperties GetPackageProperties()
+ public IPackageProperties GetPackageProperties()
{
this.ThrowExceptionIfWriteOnly();
// If no properties part has been found then we Create one
diff --git a/openxml4Net/OPC/PackageProperties.cs b/openxml4Net/OPC/PackageProperties.cs
index 31ad2ed39..3d6d5c3a5 100644
--- a/openxml4Net/OPC/PackageProperties.cs
+++ b/openxml4Net/OPC/PackageProperties.cs
@@ -11,7 +11,7 @@ namespace NPOI.OpenXml4Net.OPC
* @version 1.0
* @see org.apache.poi.OpenXml4Net.opc.OPCPackage
*/
- public interface PackageProperties
+ public interface IPackageProperties
{
/* Getters and Setters */
@@ -198,4 +198,17 @@ public interface PackageProperties
*/
void SetVersionProperty(String version);
}
+
+ public class PackageProperties
+ {
+ /**
+ * Dublin Core Terms URI.
+ */
+ public static String NAMESPACE_DCTERMS = "http://purl.org/dc/terms/";
+
+ /**
+ * Dublin Core namespace URI.
+ */
+ public static String NAMESPACE_DC = "http://purl.org/dc/elements/1.1/";
+ }
}
diff --git a/testcases/main/HSSF/UserModel/TestBugs.cs b/testcases/main/HSSF/UserModel/TestBugs.cs
index af2fa4eec..8d3386719 100644
--- a/testcases/main/HSSF/UserModel/TestBugs.cs
+++ b/testcases/main/HSSF/UserModel/TestBugs.cs
@@ -46,6 +46,7 @@ namespace TestCases.HSSF.UserModel
using NPOI.HSSF;
using System.Net;
using SixLabors.ImageSharp;
+ using NPOI.HPSF;
/**
* Testcases for bugs entered in bugzilla
@@ -2369,8 +2370,8 @@ public void Test47847()
ClassicAssert.AreEqual(3, wb.NumberOfSheets);
// Find the SST record
- UnicodeString withExt = wb.Workbook.GetSSTString(0);
- UnicodeString withoutExt = wb.Workbook.GetSSTString(31);
+ NPOI.HSSF.Record.UnicodeString withExt = wb.Workbook.GetSSTString(0);
+ NPOI.HSSF.Record.UnicodeString withoutExt = wb.Workbook.GetSSTString(31);
ClassicAssert.AreEqual("O:Alloc:Qty", withExt.String);
ClassicAssert.IsTrue((withExt.OptionFlags & 0x0004) == 0x0004);
@@ -3500,6 +3501,29 @@ public void Test45353b()
wb.Close();
}
+ [Test]
+ public void Test61287()
+ {
+ IWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("61287.xls");
+ ExcelExtractor ex = new ExcelExtractor((HSSFWorkbook)wb);
+ String text = ex.Text;
+ POITestCase.AssertContains(text, "\u8D44\u4EA7\u8D1F\u503A\u8868");
+ wb.Close();
+ }
+
+ [Test]
+ public void Test61300()
+ {
+ ClassicAssert.Throws