Skip to content

Commit

Permalink
Merge pull request #48 from jake-codes-at-5-am/xssfcolumn
Browse files Browse the repository at this point in the history
Xssfcolumn
  • Loading branch information
artem-iron authored Jul 3, 2023
2 parents 6d1986c + 4d020f4 commit 60ae6d9
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 13 deletions.
14 changes: 4 additions & 10 deletions ooxml/XSSF/UserModel/XSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5077,23 +5077,17 @@ private void RemoveOverwrittenColumns(int startColumn, int endColumn, int n)
throw new RuntimeException("There is no columns in XML part");
}

for (int i = startColumn + n; i <= endColumn + n; i++)
{
_ = GetColumn(i) ?? CreateColumn(i);
}

List<IColumn> columnsToRemove = new List<IColumn>();

// first remove all columns which will be overwritten
foreach (KeyValuePair<int, XSSFColumn> columnDict in _columns)
for (int i = startColumn + n; i <= endColumn + n; i++)
{
XSSFColumn column = columnDict.Value;
int columnNum = column.ColumnNum;

// check if we should remove this column as it will be overwritten
// by the data later
if (ShouldRemoveAtIndex(startColumn, endColumn, n, columnNum))
if (ShouldRemoveAtIndex(startColumn, endColumn, n, i))
{
IColumn column = GetColumn(i, true);

columnsToRemove.Add(column);
}
}
Expand Down
6 changes: 6 additions & 0 deletions testcases/main/HSSF/Extractor/TestOldExcelExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace TestCases.HSSF.Extractor
using NPOI.POIFS.FileSystem;
using NPOI.Util;
using System.Text;
using System.Threading;

/**
* Unit tests for the Excel 5/95 and Excel 4 (and older) text
Expand All @@ -42,6 +43,11 @@ private static OldExcelExtractor CreateExtractor(String sampleFileName)
return new OldExcelExtractor(file);
}

public TestOldExcelExtractor()
{
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
}

[Test]
public void TestSimpleExcel3()
{
Expand Down
6 changes: 6 additions & 0 deletions testcases/main/SS/Formula/Atp/TestNetworkdaysFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public class TestNetworkdaysFunction
private static String THIRD_HOLIDAY = formatter.Format(new DateTime(2009, JANUARY, 21), CultureInfo.CurrentCulture);

private static OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 1, 1, 1, null);

public TestNetworkdaysFunction()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
}

[Test]
public void TestFailWhenNoArguments()
{
Expand Down
2 changes: 2 additions & 0 deletions testcases/main/SS/Formula/Functions/TestBesselJ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ public void TestInvalid()
[Test]
public void TestNumError()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmNumError("22.5", "-40");
}

//https://support.microsoft.com/en-us/office/besselj-function-839cb181-48de-408b-9d80-bd02982d94f7
[Test]
public void TestMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
ISheet sheet = wb.CreateSheet();
IRow row = sheet.CreateRow(0);
Expand Down
1 change: 1 addition & 0 deletions testcases/main/SS/Formula/Functions/TestComplex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private static void ConfirmValueError(String msg, String real_num, String i_num,
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
ConfirmValue("Complex number with 3 and 4 as the real and imaginary coefficients (3 + 4i)", "3", "4", "", "3+4i");
ConfirmValue("Complex number with 3 and 4 as the real and imaginary coefficients, and j as the suffix (3 + 4j)", "3", "4", "j", "3+4j");

Expand Down
4 changes: 4 additions & 0 deletions testcases/main/SS/Formula/Functions/TestDec2Bin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace TestCases.SS.Formula.Functions
[TestFixture]
public class TestDec2Bin
{
public TestDec2Bin()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
}

private static ValueEval invokeValue(String number1)
{
Expand Down
4 changes: 4 additions & 0 deletions testcases/main/SS/Formula/Functions/TestDec2Hex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace TestCases.SS.Formula.Functions
[TestFixture]
public class TestDec2Hex
{
public TestDec2Hex()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
}

private static ValueEval invokeValue(String number1, String number2)
{
Expand Down
1 change: 1 addition & 0 deletions testcases/main/SS/Formula/Functions/TestDelta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private static void ConfirmValueError(String number1, String number2)
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
ConfirmValue("5", "4", 0); // Checks whether 5 Equals 4 (0)
ConfirmValue("5", "5", 1); // Checks whether 5 Equals 5 (1)

Expand Down
3 changes: 3 additions & 0 deletions testcases/main/SS/Formula/Functions/TestDollarDe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public void TestInvalid()
[Test]
public void TestNumError()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmNumError("22.5", "-40");
}

[Test]
public void TestDiv0()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmDiv0("22.5", "0");
confirmDiv0("22.5", "0.9");
confirmDiv0("22.5", "-0.9");
Expand All @@ -38,6 +40,7 @@ public void TestDiv0()
[Test]
public void TestMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
var sheet = wb.CreateSheet();
var row = sheet.CreateRow(0);
Expand Down
3 changes: 3 additions & 0 deletions testcases/main/SS/Formula/Functions/TestDollarFr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public void TestInvalid()
[Test]
public void TestNumError()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmNumError("22.5", "-40");
}

[Test]
public void TestDiv0()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmDiv0("22.5", "0");
confirmDiv0("22.5", "0.9");
confirmDiv0("22.5", "-0.9");
Expand All @@ -38,6 +40,7 @@ public void TestDiv0()
[Test]
public void TestMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
var sheet = wb.CreateSheet();
var row = sheet.CreateRow(0);
Expand Down
2 changes: 2 additions & 0 deletions testcases/main/SS/Formula/Functions/TestFixed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void SetUp()
[Test]
public void TestValid()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
// thousands separator
Confirm("FIXED(1234.56789,2,TRUE)", "1234.57");
Confirm("FIXED(1234.56789,2,FALSE)", "1,234.57");
Expand Down Expand Up @@ -88,6 +89,7 @@ public void TestValid()
[Test]
public void TestOptionalParams()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
Fixed fixedFunc = new Fixed();
ValueEval Evaluate = fixedFunc.Evaluate(0, 0, new NumberEval(1234.56789));
Assert.IsTrue(Evaluate is StringEval);
Expand Down
3 changes: 3 additions & 0 deletions testcases/main/SS/Formula/Functions/TestNormDist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TestNormDist
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmValue("42", "40", "1.5", true, 0.908788780274132);
confirmValue("42", "40", "1.5", false, 0.109340049783996);
}
Expand All @@ -29,6 +30,7 @@ public void TestInvalid()
[Test]
public void TestNumError()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmNumError("42", "40", "0", false);
confirmNumError("42", "40", "0", true);
confirmNumError("42", "40", "-0.1", false);
Expand All @@ -40,6 +42,7 @@ public void TestNumError()
[Test]
public void TestMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
ISheet sheet = wb.CreateSheet();
SS.Util.Utils.AddRow(sheet, 0, "Data", "Description");
Expand Down
3 changes: 3 additions & 0 deletions testcases/main/SS/Formula/Functions/TestNormInv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TestNormInv
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmValue("0.908789", "40", "1.5", 42.000002);
}

Expand All @@ -30,6 +31,7 @@ public void TestInvalid()
[Test]
public void TestNumError()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmNumError("0.5", "40", "0");
confirmNumError("0.5", "40", "-0.1");
confirmNumError("-0.5", "40", "0.1");
Expand All @@ -42,6 +44,7 @@ public void TestNumError()
[Test]
public void TestMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
ISheet sheet = wb.CreateSheet();
SS.Util.Utils.AddRow(sheet, 0, "Data", "Description");
Expand Down
2 changes: 2 additions & 0 deletions testcases/main/SS/Formula/Functions/TestNormSDist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TestNormSDist
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmValue("1.333333", 0.908788726);
}

Expand All @@ -28,6 +29,7 @@ public void TestInvalid()
[Test]
public void TestMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
ISheet sheet = wb.CreateSheet();
IRow row = sheet.CreateRow(0);
Expand Down
1 change: 1 addition & 0 deletions testcases/main/SS/Formula/Functions/TestNormSInv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TestNormSInv
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmValue("0.9088", 1.3334);
}

Expand Down
2 changes: 2 additions & 0 deletions testcases/main/SS/Formula/Functions/TestNumberValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class TestNumberValue
[Test]
public void TestMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
var sheet = wb.CreateSheet();
var row = sheet.CreateRow(0);
Expand All @@ -23,6 +24,7 @@ public void TestMicrosoftExample1()
[Test]
public void TestMicrosoftExample2()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
var sheet = wb.CreateSheet();
var row = sheet.CreateRow(0);
Expand Down
1 change: 1 addition & 0 deletions testcases/main/SS/Formula/Functions/TestNumericFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void TestSIGN()
[Test]
public void TestDOLLAR()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
ICell cell = wb.CreateSheet().CreateRow(0).CreateCell(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
Expand Down
2 changes: 2 additions & 0 deletions testcases/main/SS/Formula/Functions/TestQuotient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private static void ConfirmValueError(String msg, String numerator, String denom
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
ConfirmValue("int portion of 5/2 (2)", "5", "2", "2");
ConfirmValue("int portion of 4.5/3.1 (1)", "4.5", "3.1", "1");

Expand All @@ -65,6 +66,7 @@ public void TestBasic()
[Test]
public void TestErrors()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
ConfirmValueError("numerator is nonnumeric", "ABCD", "", ErrorEval.VALUE_INVALID);
ConfirmValueError("denominator is nonnumeric", "", "ABCD", ErrorEval.VALUE_INVALID);

Expand Down
3 changes: 3 additions & 0 deletions testcases/main/SS/Formula/Functions/TestStandardize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TestStandardize
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmValue("42", "40", "1.5", 1.33333333);
}

Expand All @@ -29,13 +30,15 @@ public void TestInvalid()
[Test]
public void TestNumError()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmNumError("42", "40", "0");
confirmNumError("42", "40", "-0.1");
}
//https://support.microsoft.com/en-us/office/standardize-function-81d66554-2d54-40ec-ba83-6437108ee775
[Test]
public void TestMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
ISheet sheet = wb.CreateSheet();
SS.Util.Utils.AddRow(sheet, 0, "Data", "Description");
Expand Down
3 changes: 3 additions & 0 deletions testcases/main/SS/Formula/Functions/TestTDist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TestTDist
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmValue("5.968191467", "8", "1", 0.00016754180265310392);
confirmValue("5.968191467", "8", "2", 0.00033508360530620784);
confirmValue("5.968191467", "8.2", "2.2", 0.00033508360530620784);
Expand All @@ -34,6 +35,7 @@ public void TestInvalid()
[Test]
public void TestNumError()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
confirmNumError("5.968191467", "8", "0");
confirmNumError("-5.968191467", "8", "2");
}
Expand All @@ -42,6 +44,7 @@ public void TestNumError()
[Test]
public void testMicrosoftExample1()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
HSSFWorkbook wb = new HSSFWorkbook();
ISheet sheet = wb.CreateSheet();
SS.Util.Utils.AddRow(sheet, 0, "Data", "Description");
Expand Down
3 changes: 2 additions & 1 deletion testcases/main/SS/Formula/Functions/TestText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void TestTextWithStringFirstArg()
[Test]
public void TestTextWithDeciamlFormatSecondArg()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
ValueEval numArg = new NumberEval(321321.321);
ValueEval formatArg = new StringEval("#,###.00000");
ValueEval[] args = { numArg, formatArg };
Expand Down Expand Up @@ -77,7 +78,7 @@ public void TestTextWithDeciamlFormatSecondArg()
[Test]
public void TestTextWithFractionFormatSecondArg()
{

System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
ValueEval numArg = new NumberEval(321.321);
ValueEval formatArg = new StringEval("# #/#");
ValueEval[] args = { numArg, formatArg };
Expand Down
3 changes: 3 additions & 0 deletions testcases/main/SS/UserModel/TestFractionFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ limitations under the License.
using NUnit.Framework;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;

namespace TestCases.SS.UserModel
{

Expand All @@ -34,6 +36,7 @@ public class TestFractionFormat
[Test]
public void TestSingle()
{
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
FractionFormat f = new FractionFormat("", "##");
string val = "321.321";
String ret = f.Format(val);
Expand Down
3 changes: 2 additions & 1 deletion testcases/main/Util/TestStringUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace TestCases.Util
{
using System;
using System.Text;

using System.Threading;
using NPOI.Util;
using NUnit.Framework;
/**
Expand Down Expand Up @@ -248,6 +248,7 @@ public void TestPutUncompressedUnicode()
[Test]
public void Join()
{
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
Assert.AreEqual("", StringUtil.Join(",")); // degenerate case: nothing to join
Assert.AreEqual("abc", StringUtil.Join(",", "abc")); // degenerate case: one thing to join, no trailing comma
Assert.AreEqual("abc|def|ghi", StringUtil.Join("|", "abc", "def", "ghi"));
Expand Down
Loading

0 comments on commit 60ae6d9

Please sign in to comment.