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

More patches ported from poi v3.16 #1371

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 10 additions & 10 deletions main/HSSF/Record/FormulaRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,25 +248,25 @@ public FormulaRecord()
* @param in the RecordInputstream to Read the record from
*/

public FormulaRecord(RecordInputStream in1):base(in1)
public FormulaRecord(RecordInputStream ris):base(ris)
{
long valueLongBits = in1.ReadLong();
field_5_options = in1.ReadShort();
long valueLongBits = ris.ReadLong();
field_5_options = ris.ReadShort();
specialCachedValue = SpecialCachedValue.Create(valueLongBits);
if (specialCachedValue == null) {
field_4_value = BitConverter.Int64BitsToDouble(valueLongBits);
}

field_6_zero = in1.ReadInt();
int field_7_expression_len = in1.ReadShort();
field_6_zero = ris.ReadInt();
int field_7_expression_len = ris.ReadShort();

field_8_parsed_expr = NPOI.SS.Formula.Formula.Read(field_7_expression_len, in1,in1.Available());
field_8_parsed_expr = NPOI.SS.Formula.Formula.Read(field_7_expression_len, ris, ris.Available());
}
/**
* @return <c>true</c> if this {@link FormulaRecord} is followed by a
* {@link StringRecord} representing the cached text result of the formula
* evaluation.
*/
* @return <c>true</c> if this {@link FormulaRecord} is followed by a
* {@link StringRecord} representing the cached text result of the formula
* evaluation.
*/
public bool HasCachedResultString
{
get
Expand Down
21 changes: 16 additions & 5 deletions main/POIFS/FileSystem/POIFSFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,22 @@ public static POIFSFileSystem Create(FileInfo file)
// TODO Make this nicer!
// Create a new empty POIFS in the file
POIFSFileSystem tmp = new POIFSFileSystem();
FileStream fout = file.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);
tmp.WriteFileSystem(fout);
fout.Close();
tmp.Close();

try
{
FileStream fout = file.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
tmp.WriteFileSystem(fout);
}
finally
{
fout.Close();
}
}
finally
{
tmp.Close();
}
// Open it up again backed by the file
return new POIFSFileSystem(file, false);
}
Expand Down
20 changes: 10 additions & 10 deletions main/SS/Formula/Atp/WorkdayCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public int PastDaysOfWeek(double start, double end, DayOfWeek dayOfWeek)
pastDaysOfWeek++;
}
}
return start < end ? pastDaysOfWeek : -pastDaysOfWeek;
return start <= end ? pastDaysOfWeek : -pastDaysOfWeek;
}

/**
Expand All @@ -199,22 +199,22 @@ public int PastDaysOfWeek(double start, double end, DayOfWeek dayOfWeek)
* @return number of holidays that occur in workdays, between start and end dates.
*/

private int CalculateNonWeekendHolidays(double start, double end, double[] holidays)
protected internal int CalculateNonWeekendHolidays(double start, double end, double[] holidays)
{
int nonWeekendHolidays = 0;
double startDay = start < end ? start : end;
double endDay = end > start ? end : start;
for (int i = 0; i < holidays.Length; i++)
foreach (double holiday in holidays)
{
if (IsInARange(startDay, endDay, holidays[i]))
if (IsInARange(startDay, endDay, holiday))
{
if (!IsWeekend(holidays[i]))
if (!IsWeekend(holiday))
{
nonWeekendHolidays++;
}
}
}
return start < end ? nonWeekendHolidays : -nonWeekendHolidays;
return start <= end ? nonWeekendHolidays : -nonWeekendHolidays;
}

/**
Expand All @@ -236,9 +236,9 @@ private bool IsWeekend(double aDate)

private bool IsHoliday(double aDate, double[] holidays)
{
for (int i = 0; i < holidays.Length; i++)
foreach (double holiday in holidays)
{
if (Math.Round(holidays[i]) == Math.Round(aDate))
if (Math.Round(holiday) == Math.Round(aDate))
{
return true;
}
Expand All @@ -251,8 +251,8 @@ private bool IsHoliday(double aDate, double[] holidays)
* @param holidays an array of holidays.
* @return <code>1</code> is not a workday, <code>0</code> otherwise.
*/

private int IsNonWorkday(double aDate, double[] holidays)
[Obsolete("will be removed, not used in POI itself")]
protected internal int IsNonWorkday(double aDate, double[] holidays)
{
return IsWeekend(aDate) || IsHoliday(aDate, holidays) ? 1 : 0;
}
Expand Down
37 changes: 23 additions & 14 deletions main/SS/Formula/FormulaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class FormulaParser
* Tracks whether the run of whitespace preceeding "look" could be an
* intersection operator. See GetChar.
*/
private bool _inIntersection = false;
private bool _inIntersection;

private IFormulaParsingWorkbook _book;
private static SpreadsheetVersion _ssVersion;
Expand Down Expand Up @@ -759,7 +759,7 @@ private ParseNode ParseStructuredReference(String tableName)
GetChar();
}
// parse column quantifier
String startColumnName = null;
String startColumnName;
String endColumnName = null;
int nColQuantifiers = 0;
savePtr1 = _pointer;
Expand Down Expand Up @@ -1393,6 +1393,19 @@ public override String ToString()
return sb.ToString();
}
}

private String GetBookName()
{
StringBuilder sb = new StringBuilder();
GetChar();
while (look != ']')
{
sb.Append(look);
GetChar();
}
GetChar();
return sb.ToString();
}
/**
* Note - caller should reset {@link #_pointer} upon <code>null</code> result
* @return The sheet name as an identifier <code>null</code> if '!' is not found in the right place
Expand All @@ -1403,15 +1416,7 @@ private SheetIdentifier ParseSheetName()
String bookName;
if (look == '[')
{
StringBuilder sb = new StringBuilder();
GetChar();
while (look != ']')
{
sb.Append(look);
GetChar();
}
GetChar();
bookName = sb.ToString();
bookName = GetBookName();
}
else
{
Expand All @@ -1420,9 +1425,13 @@ private SheetIdentifier ParseSheetName()

if (look == '\'')
{
StringBuilder sb = new StringBuilder();

Match('\'');
if (look == '[')
{
bookName = GetBookName();
}

StringBuilder sb = new StringBuilder();
bool done = look == '\'';
while (!done)
{
Expand Down Expand Up @@ -1655,7 +1664,7 @@ private void AddName(String functionName)
* Generates the variable Function ptg for the formula.
*
* For IF Formulas, Additional PTGs are Added To the Tokens
* @param name a {@link NamePtg} or {@link NameXPtg} or <code>null</code>
* @param name a {@link NamePtg} or {@link NameXPtg} or <code>null</code>
* @return Ptg a null is returned if we're in an IF formula, it needs extreme manipulation and is handled in this Function
*/
private ParseNode GetFunction(String name, Ptg namePtg, ParseNode[] args)
Expand Down
36 changes: 19 additions & 17 deletions main/SS/UserModel/ExcelStyleDateFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static ExcelStyleDateFormatter()
//DataFormatter.SetExcelStyleRoundingMode(format4digits);
}

private double dateToBeFormatted = 0.0;
private double dateToBeFormatted;

public ExcelStyleDateFormatter()
: base()
Expand All @@ -73,16 +73,18 @@ public ExcelStyleDateFormatter(String pattern)
}


//public ExcelStyleDateFormatter(String pattern,
// DateFormatSymbols formatSymbols)
//{
// super(processFormatPattern(pattern), formatSymbols);
//}
public ExcelStyleDateFormatter(String pattern,
DateTimeFormatInfo formatSymbols)
: base(ProcessFormatPattern(pattern), formatSymbols)
{

}

//public ExcelStyleDateFormatter(String pattern, Locale locale)
//{
// super(processFormatPattern(pattern), locale);
//}
public ExcelStyleDateFormatter(String pattern, CultureInfo locale)
: base(ProcessFormatPattern(pattern), locale)
{

}
private static string DateTimeMatchEvaluator(Match match)
{
return match.Groups[1].Value;
Expand All @@ -94,12 +96,12 @@ private static string DateTimeMatchEvaluator(Match match)
private static String ProcessFormatPattern(String f)
{
String t = f.Replace("MMMMM", MMMMM_START_SYMBOL + "MMM" + MMMMM_TRUNCATE_SYMBOL);
t = Regex.Replace(t, "\\[H\\]", (H_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[HH\\]", (HH_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[m\\]", (M_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[mm\\]", (MM_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[s\\]", (S_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[ss\\]", (SS_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[H]", (H_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[HH]", (HH_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[m]", (M_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[mm]", (MM_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[s]", (S_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = Regex.Replace(t, "\\[ss]", (SS_BRACKET_SYMBOL).ToString(), RegexOptions.IgnoreCase);
t = t.Replace("s.000", "s.fff");
t = t.Replace("s.00", "s." + LL_BRACKET_SYMBOL);
t = t.Replace("s.0", "s." + L_BRACKET_SYMBOL);
Expand Down Expand Up @@ -142,7 +144,7 @@ public StringBuilder Format(DateTime date, StringBuilder paramStringBuilder, Cul
// Now handle our special cases
if (s.IndexOf(MMMMM_START_SYMBOL) != -1)
{
Regex reg = new Regex(MMMMM_START_SYMBOL + "(\\w)\\w+" + MMMMM_TRUNCATE_SYMBOL, RegexOptions.IgnoreCase);
Regex reg = new Regex(MMMMM_START_SYMBOL + "(\\p{L}|\\p{P}|\\p{N})[\\p{L}|\\p{P}|\\p{N}]+" + MMMMM_TRUNCATE_SYMBOL, RegexOptions.IgnoreCase);
Match m = reg.Match(s);
if (m.Success)
{
Expand Down
7 changes: 7 additions & 0 deletions ooxml/XSSF/UserModel/XSSFRelation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ public class XSSFRelation : POIXMLRelation
null
);

public static XSSFRelation CUSTOM_PROPERTIES = new XSSFRelation(
"application/vnd.openxmlformats-officedocument.spreadsheetml.customProperty",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty",
"/xl/customProperty#.bin",
null
);

public static String NS_SPREADSHEETML = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
public static String NS_DRAWINGML = "http://schemas.openxmlformats.org/drawingml/2006/main";
public static String NS_CHART = "http://schemas.openxmlformats.org/drawingml/2006/chart";
Expand Down
7 changes: 3 additions & 4 deletions testcases/main/HSSF/Model/TestFormulaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,8 +1483,7 @@ public void TestBackSlashInNames()
}

/**
* TODO - delete equiv Test:
* {@link BaseTestBugzillaIssues#test42448()}
* See the related/similar test: {@link BaseTestBugzillaIssues#test42448()}
*/
[Test]
public void TestParseAbnormalSheetNamesAndRanges_bug42448()
Expand Down Expand Up @@ -1537,11 +1536,11 @@ public void TestRangeFuncOperand_bug46951()
[Test]
public void TestUnionOfFullCollFullRowRef()
{
ParseFormula("3:4");
Ptg[] ptgs;
ptgs = ParseFormula("3:4");
ptgs = ParseFormula("$Z:$AC");
ConfirmTokenClasses(ptgs, typeof(AreaPtg));
ptgs = ParseFormula("B:B");
ParseFormula("B:B");

ptgs = ParseFormula("$11:$13");
ConfirmTokenClasses(ptgs, typeof(AreaPtg));
Expand Down
Loading
Loading