Skip to content
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
10 changes: 8 additions & 2 deletions main/SS/Formula/FormulaShifter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,13 +1005,19 @@ private Ptg RowCopyRefPtg(RefPtgBase rptg)
int refRow = rptg.Row;
if (rptg.IsRowRelative)
{
// check new location where the ref is located
int destRowIndex = _firstMovedIndex + _amountToMove;
if (destRowIndex < 0 || _version.LastRowIndex < destRowIndex)
{
return CreateDeletedRef(rptg);
}

rptg.Row = refRow + _amountToMove;
// check new location where the ref points to
int newRowIndex = refRow + _amountToMove;
if(newRowIndex < 0 || _version.LastRowIndex < newRowIndex)
{
return CreateDeletedRef(rptg);
}
rptg.Row = newRowIndex;
return rptg;
}

Expand Down
2 changes: 1 addition & 1 deletion main/SS/UserModel/FractionFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public String Format(string num)
}

//if whole part has to go into the numerator
if ("".Equals(wholePartFormatString))
if (string.IsNullOrEmpty(wholePartFormatString))
{
int trueNum = (fract.Denominator * (int)wholePart) + fract.Numerator;
sb1.Append(trueNum).Append("/").Append(fract.Denominator);
Expand Down
37 changes: 4 additions & 33 deletions main/Util/IntList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class IntList
{
private int[] _array;
private int _limit;
private int fillval = 0;

private static int _default_size = 128;

/// <summary>
Expand All @@ -57,10 +57,10 @@ public IntList()
{
}

public IntList(int InitialCapacity)
: this(InitialCapacity, 0)
public IntList(int initialCapacity)
{

_array = new int[initialCapacity];
_limit = 0;
}

/// <summary>
Expand All @@ -74,30 +74,6 @@ public IntList(IntList list)
_limit = list._limit;
}

/// <summary>
/// create an IntList with a predefined Initial size
/// </summary>
/// <param name="initialCapacity">the size for the internal array</param>
/// <param name="fillvalue"></param>
public IntList(int initialCapacity, int fillvalue)
{
_array = new int[initialCapacity];
if (fillval != 0)
{
fillval = fillvalue;
FillArray(fillval, _array, 0);
}
_limit = 0;
}

private static void FillArray(int val, int[] array, int index)
{
for (int k = index; k < array.Length; k++)
{
array[k] = val;
}
}

/// <summary>
/// add the specfied value at the specified index
/// </summary>
Expand Down Expand Up @@ -580,11 +556,6 @@ private void growArray(int new_size)
: new_size;
int[] new_array = new int[size];

if (fillval != 0)
{
FillArray(fillval, new_array, _array.Length);
}

Array.Copy(_array, 0, new_array, 0, _limit);
_array = new_array;
}
Expand Down
71 changes: 33 additions & 38 deletions ooxml/XSSF/Extractor/XSSFExportToXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,38 +494,38 @@ private static int IndexOfElementInComplexType(String elementName, XmlNode compl
{
return -1;
}
XmlNodeList list = complexType.ChildNodes;

int indexOf = -1;
int i = 0;
XmlNode node = complexType.FirstChild;
String elementNameWithoutNamespace = RemoveNamespace(elementName);

for (int i = 0; i < list.Count; i++)
while(node != null)
{
XmlNode node = list[i];
if (node is XmlElement)
{
if (node.LocalName.Equals("element"))
if(node is XmlElement && "element".Equals(node.LocalName)) {
XmlNode element = GetNameOrRefElement(node);
if(element.Value.Equals(elementNameWithoutNamespace))
{
XmlNode element = GetNameOrRefElement(node);
if (element.Value.Equals(RemoveNamespace(elementName)))
{
indexOf = i;
break;
}

indexOf = i;
break;
}
}
i++;
node = node.NextSibling;
}

return indexOf;
}

private static XmlNode GetNameOrRefElement(XmlNode node)
{
XmlNode returnNode = node.Attributes.GetNamedItem("name");
XmlNode returnNode = node.Attributes.GetNamedItem("ref");
if(returnNode != null)
{
return returnNode;
}

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

private static XmlNode GetComplexTypeForElement(String elementName, XmlNode xmlSchema, XmlNode localComplexTypeRootNode)
Expand All @@ -549,67 +549,62 @@ private static String GetComplexTypeNameFromChildren(XmlNode localComplexTypeRoo
{
return "";
}
XmlNodeList list = localComplexTypeRootNode.ChildNodes;
XmlNode node = localComplexTypeRootNode.FirstChild;
String complexTypeName = "";

for(int i = 0; i < list.Count; i++)
while(node != null)
{
XmlNode node = list[i];
if(node is XmlElement)
if(node is XmlElement && "element".Equals(node.LocalName))
{
if(node.LocalName.Equals("element"))
XmlNode nameAttribute = node.Attributes.GetNamedItem("name");
if(nameAttribute.Value.Equals(elementNameWithoutNamespace))
{
XmlNode nameAttribute = node.Attributes.GetNamedItem("name");
if(nameAttribute.Value.Equals(elementNameWithoutNamespace))
XmlNode complexTypeAttribute = node.Attributes.GetNamedItem("type");
if(complexTypeAttribute != null)
{
XmlNode complexTypeAttribute = node.Attributes.GetNamedItem("type");
if(complexTypeAttribute != null)
{
complexTypeName = complexTypeAttribute.Value;
break;
}
complexTypeName = complexTypeAttribute.Value;
break;
}
}
}
node = node.NextSibling;
}
return complexTypeName;
}
private static XmlNode GetComplexTypeNodeFromSchemaChildren(XmlNode xmlSchema, XmlNode complexTypeNode, String complexTypeName)
{
XmlNodeList complexTypeList = xmlSchema.ChildNodes;
for(int i = 0; i < complexTypeList.Count; i++)
XmlNode node = xmlSchema.FirstChild;
while(node != null)
{
XmlNode node = complexTypeList[i];
if(node is XmlElement)
{
if(node.LocalName.Equals("complexType"))
{
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 = node.FirstChild;
while(sequence != null)
{
XmlNode sequence = complexTypeChildList[j];

if(sequence is XmlElement)
{
if(sequence.LocalName.Equals("sequence"))
String localName = sequence.LocalName;
if("sequence".Equals(localName) || "all".Equals(localName))
{
complexTypeNode = sequence;
break;
}
}
sequence = sequence.NextSibling;
}
if(complexTypeNode != null)
{
break;
}

}
}
}
node = node.NextSibling;
}
return complexTypeNode;
}
Expand Down
26 changes: 25 additions & 1 deletion ooxml/XSSF/Model/StylesTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,8 @@ public XSSFCellStyle CreateCellStyle()
/**
* Finds a font that matches the one with the supplied attributes
*/
public XSSFFont FindFont(bool bold, short color, short fontHeight, String name, bool italic, bool strikeout, FontSuperScript typeOffset, FontUnderlineType underline)
public XSSFFont FindFont(bool bold, short color, short fontHeight, String name, bool italic, bool strikeout,
FontSuperScript typeOffset, FontUnderlineType underline)
{
foreach (XSSFFont font in fonts)
{
Expand All @@ -945,6 +946,29 @@ public XSSFFont FindFont(bool bold, short color, short fontHeight, String name,
return null;
}

/// <summary>
/// Finds a font that matches the one with the supplied attributes,
/// where color is the actual Color-value, not the indexed color
/// </summary>
public XSSFFont FindFont(bool bold, IColor color, short fontHeight, string name, bool italic, bool strikeout,
FontSuperScript typeOffset, FontUnderlineType underline)
{
foreach(XSSFFont font in fonts)
{
if((font.IsBold == bold)
&& font.GetXSSFColor().Equals(color)
&& font.FontHeight == fontHeight
&& font.FontName.Equals(name)
&& font.IsItalic == italic
&& font.IsStrikeout == strikeout
&& font.TypeOffset == typeOffset
&& font.Underline == underline)
{
return font;
}
}
return null;
}
/// <summary>
/// default or custom indexed color to RGB mapping
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion ooxml/XSSF/UserModel/XSSFBorderFormatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public short TopBorderColor
{
get
{
return GetIndexedColor(RightBorderColorColor as XSSFColor);
return GetIndexedColor(TopBorderColorColor as XSSFColor);
}
set
{
Expand Down
8 changes: 8 additions & 0 deletions ooxml/XSSF/UserModel/XSSFFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,21 @@ public void SetFamily(FontFamily family)
* @return unique index number of the underlying record this Font represents (probably you don't care
* unless you're comparing which one is which)
*/
[Obsolete]
public short Index
{
get
{
return _index;
}
}
public int IndexAsInt
{
get
{
return _index;
}
}

public override int GetHashCode()
{
Expand Down
8 changes: 2 additions & 6 deletions openxml4Net/OPC/PackagingUriHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,9 @@ public static Uri Combine(Uri prefix, Uri suffix)
*/
public static String Combine(String prefix, String suffix)
{
if (!prefix.EndsWith("" + FORWARD_SLASH_CHAR)
&& !suffix.StartsWith("" + FORWARD_SLASH_CHAR))
if (!prefix.EndsWith(FORWARD_SLASH_STRING) && !suffix.StartsWith(FORWARD_SLASH_STRING))
return prefix + FORWARD_SLASH_CHAR + suffix;
else if ((!prefix.EndsWith("" + FORWARD_SLASH_CHAR)
&& suffix.StartsWith("" + FORWARD_SLASH_CHAR) || (prefix
.EndsWith("" + FORWARD_SLASH_CHAR) && !suffix.StartsWith(""
+ FORWARD_SLASH_CHAR))))
else if (prefix.EndsWith(FORWARD_SLASH_STRING) ^ suffix.StartsWith(FORWARD_SLASH_STRING))
return prefix + suffix;
else
return "";
Expand Down
28 changes: 28 additions & 0 deletions testcases/main/HSSF/UserModel/TestBugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3520,6 +3520,34 @@ public void Test61300()
});
}

[Test]
public void Test51262()
{
HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("51262.xls");
ISheet sheet = wb.GetSheetAt(0);
IRow row = sheet.GetRow(2);

ICell cell = row.GetCell(1);
ICellStyle style = cell.CellStyle;
ClassicAssert.AreEqual(26, style.FontIndex);

row = sheet.GetRow(3);
cell = row.GetCell(1);
style = cell.CellStyle;
ClassicAssert.AreEqual(28, style.FontIndex);

// check the two fonts
HSSFFont font = wb.GetFontAt((short) 26) as HSSFFont;
ClassicAssert.IsTrue(font.IsBold);
ClassicAssert.AreEqual(10, font.FontHeightInPoints);
ClassicAssert.AreEqual("\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF", font.FontName);

font = wb.GetFontAt((short) 28) as HSSFFont;
ClassicAssert.IsTrue(font.IsBold);
ClassicAssert.AreEqual(10, font.FontHeightInPoints);
ClassicAssert.AreEqual("\uFF2D\uFF33 \uFF30\u30B4\u30B7\u30C3\u30AF", font.FontName);
}

// follow https://svn.apache.org/viewvc?view=revision&revision=1896552 to write a unit test for this fix.
[Test]
public void Test52447()
Expand Down
Loading
Loading