Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches ported from poi 3.16 #1322

Merged
merged 12 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions OpenXmlFormats/Spreadsheet/Sheet/CT_Worksheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ public bool IsSetSheetCalcPr()
{
return this.sheetCalcPrField != null;
}

public bool IsSetDimension()
{
return this.dimensionField != null;
}
public CT_SheetProtection AddNewSheetProtection()
{
this.sheetProtectionField = new CT_SheetProtection();
Expand Down
4 changes: 3 additions & 1 deletion main/HPSF/HPSFPropertiesOnlyDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ private void Write(NPOIFSFileSystem fs)
WriteProperties(fs, excepts);

// Copy over everything else unchanged
EntryUtils.CopyNodes(directory, fs.Root, excepts);
FilteringDirectoryNode src = new FilteringDirectoryNode(directory, excepts);
FilteringDirectoryNode dest = new FilteringDirectoryNode(fs.Root, excepts);
EntryUtils.CopyNodes(src, dest);

// Caller will save the resultant POIFSFileSystem to the stream/file
}
Expand Down
1 change: 1 addition & 0 deletions main/HSSF/UserModel/HSSFCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ internal void NotifyArrayFormulaChanging()
NotifyArrayFormulaChanging(msg);
}

[Obsolete("Will be removed at NPOI 2.8, Use CachedFormulaResultType instead.")]
public CellType GetCachedFormulaResultTypeEnum()
{
throw new NotImplementedException();
Expand Down
25 changes: 0 additions & 25 deletions main/POIFS/FileSystem/EntryUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,6 @@ public static void CopyNodes(FilteringDirectoryNode filteredSource,
CopyNodes((DirectoryEntry)filteredSource, (DirectoryEntry)filteredTarget);
}

/**
* Copies nodes from one Directory to the other minus the excepts
*
* @param sourceRoot
* is the source Directory to copy from
* @param targetRoot
* is the target Directory to copy to
* @param excepts
* is a list of Strings specifying what nodes NOT to copy
* @deprecated use {@link FilteringDirectoryNode} instead
*/
[Obsolete]
public static void CopyNodes(DirectoryEntry sourceRoot,
DirectoryEntry targetRoot, List<String> excepts)
{
IEnumerator entries = sourceRoot.Entries;
while (entries.MoveNext())
{
Entry entry = (Entry)entries.Current;
if (!excepts.Contains(entry.Name))
{
CopyNodeRecursively(entry, targetRoot);
}
}
}

/**
* Copies all nodes from one POIFS to the other
Expand Down
17 changes: 0 additions & 17 deletions main/SS/Formula/FormulaShifter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,6 @@ private FormulaShifter(int srcSheetIndex, int dstSheetIndex)
_mode = ShiftMode.SheetMove;
}

[Obsolete("deprecated As of 3.14 beta 1 (November 2015), replaced by CreateForRowShift(int, String, int, int, int, SpreadsheetVersion)")]
public static FormulaShifter CreateForRowShift(
int externSheetIndex,
string sheetName,
int firstMovedRowIndex,
int lastMovedRowIndex,
int numberOfRowsToMove)
{
return CreateForRowShift(
externSheetIndex,
sheetName,
firstMovedRowIndex,
lastMovedRowIndex,
numberOfRowsToMove,
SpreadsheetVersion.EXCEL97);
}

public static FormulaShifter CreateForRowShift(
int externSheetIndex,
string sheetName,
Expand Down
14 changes: 13 additions & 1 deletion main/SS/UserModel/Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,19 @@ CellType CellType
bool IsPartOfArrayFormulaGroup { get; }

bool IsMergedCell { get; }


/// <summary>
/// Only valid for formula cells
/// </summary>
/// <returns>one of (<see cref="CellType.Numeric" />, <see cref="CellType.String" />,
/// <see cref="CellType.Boolean" />, <see cref="CellType.Error" />) depending
/// on the cached value of the formula
/// </returns>
/// <remarks>
/// @since POI 3.15 beta 3
/// Will be renamed to <c>getCachedFormulaResultType()</c> when we make the CellType enum transition in POI 4.0. See bug 59791.
/// </remarks>
[Obsolete("Will be removed at NPOI 2.8, Use CachedFormulaResultType instead.")]
CellType GetCachedFormulaResultTypeEnum();
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/SS/UserModel/DataFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ public string FormatCellValue(ICell cell, IFormulaEvaluator evaluator)
{
try
{
cellType = cell.GetCachedFormulaResultTypeEnum();
cellType = cell.CachedFormulaResultType;
}
catch(Exception)
{
Expand Down
79 changes: 46 additions & 33 deletions ooxml/XSSF/Extractor/XSSFExportToXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private void mapCellOnNode(XSSFCell cell, XmlNode node)
case CellType.Boolean: value += cell.BooleanCellValue; break;
case CellType.Error: value = cell.ErrorCellString; break;
case CellType.Formula:
if(cell.GetCachedFormulaResultTypeEnum()== CellType.String)
if(cell.CachedFormulaResultType== CellType.String)
{
value = cell.StringCellValue;
}
Expand All @@ -295,7 +295,7 @@ private void mapCellOnNode(XSSFCell cell, XmlNode node)
{
value = GetFormattedDate(cell);
}
else if(cell.GetCachedFormulaResultTypeEnum()== CellType.Numeric)
else if(cell.CachedFormulaResultType== CellType.Numeric)
{
value=cell.GetRawValue();
}
Expand Down Expand Up @@ -455,12 +455,12 @@ public int Compare(String leftXpath, String rightXpath)
String[] leftTokens = leftXpath.Split(new char[]{'/'});
String[] rightTokens = rightXpath.Split(new char[] { '/' });

int minLenght = leftTokens.Length < rightTokens.Length ? leftTokens.Length : rightTokens.Length;
int minLength = leftTokens.Length < rightTokens.Length ? leftTokens.Length : rightTokens.Length;

XmlNode localComplexTypeRootNode = doc.DocumentElement;


for (int i = 1; i < minLenght; i++)
for (int i = 1; i < minLength; i++)
{

String leftElementName = leftTokens[i];
Expand Down Expand Up @@ -496,7 +496,10 @@ public int Compare(String leftXpath, String rightXpath)

private int IndexOfElementInComplexType(String elementName, XmlNode complexType)
{

if(complexType == null)
{
return -1;
}
XmlNodeList list = complexType.ChildNodes;
int indexOf = -1;

Expand All @@ -507,8 +510,8 @@ private int IndexOfElementInComplexType(String elementName, XmlNode complexType)
{
if (node.LocalName.Equals("element"))
{
XmlNode nameAttribute = node.Attributes.GetNamedItem("name");
if (nameAttribute.Value.Equals(RemoveNamespace(elementName)))
XmlNode element = GetNameOrRefElement(node);
if (element.Value.Equals(RemoveNamespace(elementName)))
{
indexOf = i;
break;
Expand All @@ -519,22 +522,32 @@ private int IndexOfElementInComplexType(String elementName, XmlNode complexType)
}
return indexOf;
}
private XmlNode GetNameOrRefElement(XmlNode node)
{
XmlNode returnNode = node.Attributes.GetNamedItem("name");
if(returnNode != null)
{
return returnNode;
}

return node.Attributes.GetNamedItem("ref");
}

private XmlNode GetComplexTypeForElement(String elementName, XmlNode xmlSchema, XmlNode localComplexTypeRootNode)
{
String elementNameWithoutNamespace = RemoveNamespace(elementName);

String complexTypeName = getComplexTypeNameFromChildren(localComplexTypeRootNode, elementNameWithoutNamespace);
String complexTypeName = GetComplexTypeNameFromChildren(localComplexTypeRootNode, elementNameWithoutNamespace);

XmlNode complexTypeNode = null;
// Note: we expect that all the complex types are defined at root level
if(!"".Equals(complexTypeName))
{
complexTypeNode = getComplexTypeNodeFromSchemaChildren(xmlSchema, null, complexTypeName);
complexTypeNode = GetComplexTypeNodeFromSchemaChildren(xmlSchema, null, complexTypeName);
}
return complexTypeNode;
}
private String getComplexTypeNameFromChildren(XmlNode localComplexTypeRootNode,
private String GetComplexTypeNameFromChildren(XmlNode localComplexTypeRootNode,
String elementNameWithoutNamespace)
{
if(localComplexTypeRootNode == null)
Expand Down Expand Up @@ -566,45 +579,45 @@ private String getComplexTypeNameFromChildren(XmlNode localComplexTypeRootNode,
}
return complexTypeName;
}
private XmlNode getComplexTypeNodeFromSchemaChildren(XmlNode xmlSchema, XmlNode complexTypeNode,
private XmlNode GetComplexTypeNodeFromSchemaChildren(XmlNode xmlSchema, XmlNode complexTypeNode,
String complexTypeName)
{

XmlNodeList complexTypeList = xmlSchema.ChildNodes;
for(int i = 0; i < complexTypeList.Count; i++)
XmlNodeList complexTypeList = xmlSchema.ChildNodes;
for(int i = 0; i < complexTypeList.Count; i++)
{
XmlNode node = complexTypeList[i];
if(node is XmlElement)
{
XmlNode node = complexTypeList[i];
if(node is XmlElement)
if(node.LocalName.Equals("complexType"))
{
if(node.LocalName.Equals("complexType"))
XmlNode nameAttribute = node.Attributes.GetNamedItem("name");
if(nameAttribute.Value.Equals(complexTypeName))
{
XmlNode nameAttribute = node.Attributes.GetNamedItem("name");
if(nameAttribute.Value.Equals(complexTypeName))

XmlNodeList complexTypeChildList = node.ChildNodes;
for(int j = 0; j < complexTypeChildList.Count; j++)
{
XmlNode sequence = complexTypeChildList[j];

XmlNodeList complexTypeChildList = node.ChildNodes;
for(int j = 0; j < complexTypeChildList.Count; j++)
if(sequence is XmlElement)
{
XmlNode sequence = complexTypeChildList[j];

if(sequence is XmlElement)
if(sequence.LocalName.Equals("sequence"))
{
if(sequence.LocalName.Equals("sequence"))
{
complexTypeNode = sequence;
break;
}
complexTypeNode = sequence;
break;
}
}
if(complexTypeNode != null)
{
break;
}

}
if(complexTypeNode != null)
{
break;
}

}
}
}
}
return complexTypeNode;
}
}
Expand Down
24 changes: 14 additions & 10 deletions ooxml/XSSF/Streaming/SXSSFCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,21 @@ public bool BooleanCellValue

public CellType CachedFormulaResultType
{
get { return GetCachedFormulaResultTypeEnum(); }
get
{
if(_value.GetType() != CellType.Formula)
{
throw new InvalidOperationException("Only formula cells have cached results");
}

return ((FormulaValue) _value).GetFormulaType();
}
}

[Obsolete("Will be removed at NPOI 2.8, Use CachedFormulaResultType instead.")]
public CellType GetCachedFormulaResultTypeEnum()
{
if (_value.GetType() != CellType.Formula)
{
throw new InvalidOperationException("Only formula cells have cached results");
}

return ((FormulaValue)_value).GetFormulaType();
return CachedFormulaResultType;
}

public IComment CellComment
Expand Down Expand Up @@ -755,7 +759,7 @@ private void SetType(CellType type)
if (_value != null)
{
// if a cell is not blank then convert the old value to string
bool val = convertCellValueToBoolean();
bool val = ConvertCellValueToBoolean();
bval.Value = val;
}
_value = bval;
Expand Down Expand Up @@ -824,13 +828,13 @@ private static InvalidOperationException typeMismatch(CellType expectedTypeCode,
+ " " + (isFormulaCell ? "formula " : "") + "cell";
return new InvalidOperationException(msg);
}
private bool convertCellValueToBoolean()
private bool ConvertCellValueToBoolean()
{
CellType cellType = _value.GetType();

if (cellType == CellType.Formula)
{
cellType = GetCachedFormulaResultTypeEnum();
cellType = CachedFormulaResultType;
}

switch (cellType)
Expand Down
7 changes: 1 addition & 6 deletions ooxml/XSSF/Streaming/SXSSFEvaluationCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,8 @@ public CellType CachedFormulaResultType
return _cell.CachedFormulaResultType;
}
}
/**
* @since POI 3.15 beta 3
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
//@Internal(since= "POI 3.15 beta 3")

[Obsolete("Will be removed at NPOI 2.8, Use CachedFormulaResultType instead.")]
public CellType GetCachedFormulaResultTypeEnum()
{
return _cell.GetCachedFormulaResultTypeEnum();
Expand Down
2 changes: 1 addition & 1 deletion ooxml/XSSF/Streaming/SheetDataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void WriteCell(int columnIndex, ICell cell)

WriteAsBytes("</f>");

switch (cell.GetCachedFormulaResultTypeEnum())
switch (cell.CachedFormulaResultType)
{
case CellType.Numeric:
double nval = cell.NumericCellValue;
Expand Down
3 changes: 1 addition & 2 deletions ooxml/XSSF/UserModel/XSSFCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ public ICell CopyCellTo(int targetIndex)
return CellUtil.CopyCell(this.Row, this.ColumnIndex, targetIndex);
}

[Obsolete("Will be removed at NPOI 2.8, Use CachedFormulaResultType instead.")]
public CellType GetCachedFormulaResultTypeEnum()
{
if(!IsFormulaCell)
Expand All @@ -1395,6 +1396,4 @@ public CellType GetCachedFormulaResultTypeEnum()
return GetBaseCellType(false);
}
}


}
2 changes: 1 addition & 1 deletion ooxml/XSSF/UserModel/XSSFRichTextString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace NPOI.XSSF.UserModel
*/
public class XSSFRichTextString : IRichTextString
{
private static Regex utfPtrn = new Regex("_x([0-9A-F]{4})_", RegexOptions.Compiled);
private static Regex utfPtrn = new Regex("_x([0-9A-Fa-f]{4})_", RegexOptions.Compiled);

private CT_Rst st;
private StylesTable styles;
Expand Down
Loading
Loading