Skip to content

Commit

Permalink
fix hashtable comparison in HSSFCellUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyqus committed Nov 26, 2013
1 parent a2e8927 commit 1a2a76e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion main/HSSF/Util/HSSFCellUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,27 @@ public static void SetFont(ICell cell, HSSFWorkbook workbook, HSSFFont font)
{
SetCellStyleProperty(cell, workbook, FONT, font);
}
private static bool CompareHashTableKeyValueIsEqual(Hashtable a, Hashtable b)
{
foreach (DictionaryEntry a_entry in a)
{
foreach (DictionaryEntry b_entry in b)
{
if (a_entry.Key.ToString() == b_entry.Key.ToString())
{
if ((a_entry.Value is short && b_entry.Value is short
&& (short)a_entry.Value != (short)b_entry.Value) ||
(a_entry.Value is bool && b_entry.Value is bool
&& (bool)a_entry.Value != (bool)b_entry.Value))
{
return false;
}
}
}
}

return true;
}
/**
* This method attempt to find an already existing HSSFCellStyle that matches
* what you want the style to be. If it does not find the style, then it
Expand Down Expand Up @@ -218,7 +238,8 @@ public static void SetCellStyleProperty(NPOI.SS.UserModel.ICell cell, HSSFWorkbo
NPOI.SS.UserModel.ICellStyle wbStyle = workbook.GetCellStyleAt(i);
Hashtable wbStyleMap = GetFormatProperties(wbStyle);

if (wbStyleMap.Equals(values))
// if (wbStyleMap.Equals(values))
if (CompareHashTableKeyValueIsEqual(wbStyleMap, values))
{
newStyle = wbStyle;
break;
Expand Down

0 comments on commit 1a2a76e

Please sign in to comment.