Skip to content

Commit

Permalink
Merge pull request #1316 from antony-liu/poi/v3.16-patch3
Browse files Browse the repository at this point in the history
Some patches ported from poi
  • Loading branch information
tonyqus committed Apr 26, 2024
2 parents efb45c5 + ff7fa87 commit 815eb29
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 75 deletions.
4 changes: 4 additions & 0 deletions main/HSSF/Extractor/OldExcelExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace NPOI.HSSF.Extractor
*/
public class OldExcelExtractor
{
private const int FILE_PASS_RECORD_SID = 0x2f;
private RecordInputStream ris;

// sometimes we hold the stream here and thus need to ensure it is closed at some point
Expand Down Expand Up @@ -247,6 +248,9 @@ public String Text

switch (sid)
{
case FILE_PASS_RECORD_SID:
throw new EncryptedDocumentException("Encryption not supported for Old Excel files");

// Biff 5+ only, no sheet names in older formats
case OldSheetRecord.sid:
OldSheetRecord shr = new OldSheetRecord(ris);
Expand Down
23 changes: 23 additions & 0 deletions main/Util/StringUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -854,5 +854,28 @@ public static String Join(String separator, params object[] array)
{
return Join(array, separator);
}

/**
* Count number of occurrences of needle in haystack
* Has same signature as org.apache.commons.lang3.StringUtils#countMatches
*
* @param haystack the CharSequence to check, may be null
* @param needle the character to count the quantity of
* @return the number of occurrences, 0 if the CharSequence is null
*/
public static int CountMatches(string haystack, char needle)
{
if (haystack == null) return 0;
int count = 0;
int length = haystack.Length;
for (int i = 0; i < length; i++)
{
if (haystack[i] == needle)
{
count++;
}
}
return count;
}
}
}
Loading

0 comments on commit 815eb29

Please sign in to comment.