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
40 changes: 36 additions & 4 deletions OpenXmlFormats/Spreadsheet/Styles/CT_Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,20 @@ public bool IsSetDiagonal()
{
return this.diagonalField != null;
}
public void unsetDiagonal()
public void UnsetDiagonal()
{
this.diagonalField = null;
}

public void unsetRight()
public void UnsetRight()
{
this.rightField = null;
}
public void unsetLeft()
public void UnsetLeft()
{
this.leftField = null;
}
public void unsetTop()
public void UnsetTop()
{
this.topField = null;
}
Expand Down Expand Up @@ -230,6 +230,38 @@ public CT_BorderPr AddNewBottom()
return this.bottomField;
}

public bool IsSetVertical()
{
return verticalField != null;
}

public CT_BorderPr AddNewVertical()
{
verticalField = new CT_BorderPr();
return verticalField;
}

public void UnsetVertical()
{
verticalField = null;
}

public bool IsSetHorizontal()
{
return horizontalField != null;
}

public CT_BorderPr AddNewHorizontal()
{
horizontalField = new CT_BorderPr();
return horizontalField;
}

public void UnsetHorizontal()
{
horizontalField = null;
}

[XmlElement(Namespace = "http://schemas.openxmlformats.org/spreadsheetml/2006/main")]
public CT_BorderPr left
{
Expand Down
18 changes: 17 additions & 1 deletion OpenXmlFormats/Spreadsheet/Styles/CT_BorderPr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public class CT_BorderPr
private CT_Color colorField;

private ST_BorderStyle styleField;
private bool styleFieldSpecified;
public static CT_BorderPr Parse(XmlNode node, XmlNamespaceManager namespaceManager)
{
if (node == null)
return null;
CT_BorderPr ctObj = new CT_BorderPr();
ctObj.styleFieldSpecified = node.Attributes["style"] != null;
if (node.Attributes["style"] != null)
ctObj.style = (ST_BorderStyle)Enum.Parse(typeof(ST_BorderStyle), node.Attributes["style"].Value);
foreach (XmlNode childNode in node.ChildNodes)
Expand Down Expand Up @@ -71,7 +73,7 @@ public void UnsetColor()
}
public bool IsSetStyle()
{
return styleField != ST_BorderStyle.none;
return styleFieldSpecified;
}

[XmlElement]
Expand All @@ -97,15 +99,29 @@ public ST_BorderStyle style
}
set
{
this.styleFieldSpecified = value != ST_BorderStyle.none;
this.styleField = value;
}
}

public bool styleSpecified
{
get
{
return this.styleFieldSpecified;
}
set
{
this.styleFieldSpecified = value;
}
}

public CT_BorderPr Copy()
{
var res = new CT_BorderPr();
res.colorField = this.colorField == null ? null : this.colorField.Copy();
res.style = this.style;
res.styleSpecified = this.styleSpecified;
return res;
}
}
Expand Down
13 changes: 13 additions & 0 deletions OpenXmlFormats/Spreadsheet/Styles/CT_Colors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ internal void Write(StreamWriter sw, string nodeName)
sw.Write(string.Format("</{0}>", nodeName));
}

public bool IsSetIndexedColors()
{
return this.indexedColors != null;
}

[XmlArray(Order = 0)]
[XmlArrayItem("rgbColor", IsNullable = false)]
public List<CT_RgbColor> indexedColors
Expand Down Expand Up @@ -112,6 +117,8 @@ public static CT_RgbColor Parse(XmlNode node, XmlNamespaceManager namespaceManag
if (node == null)
return null;
CT_RgbColor ctObj = new CT_RgbColor();
if(node.Attributes["rgb"] != null)
ctObj.rgbHex = node.Attributes["rgb"].Value;
ctObj.rgb = XmlHelper.ReadBytes(node.Attributes["rgb"]);
return ctObj;
}
Expand Down Expand Up @@ -140,6 +147,12 @@ public byte[] rgb
this.rgbField = value;
}
}
[XmlIgnore]
public string rgbHex
{
get;
set;
}
}


Expand Down
75 changes: 75 additions & 0 deletions main/HSSF/UserModel/HSSFBorderFormatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,80 @@ public bool IsForwardDiagonalOn
}
}

/// <summary>
/// HSSF doesn't support table borders, so always <see cref="BorderStyle.NONE" />
/// </summary>
/// <see cref="IBorderFormatting.BorderVertical" />
public BorderStyle BorderVertical { get => BorderStyle.None; set { /*nothing, Not available for HSSF.*/ ; } }

/// <summary>
/// HSSF doesn't support table borders, so always <see cref="BorderStyle.NONE" />
/// </summary>
/// <see cref="IBorderFormatting.BorderHorizontal" />
public BorderStyle BorderHorizontal { get => BorderStyle.None; set { /*nothing, Not available for HSSF.*/ ; } }

/// <summary>
/// HSSF Doesn't support table borders, so always <see cref="HSSFColorPredefined.AUTOMATIC" />
/// </summary>
/// <see cref="IBorderFormatting.VerticalBorderColor" />
public short VerticalBorderColor
{
get
{
return HSSFColor.Automatic.Index;
}
set
{
//nothing, Not available for HSSF.
}
}

/// <summary>
/// HSSF Doesn't support table borders, so always <see cref="HSSFColorPredefined.AUTOMATIC" />
/// </summary>
/// <see cref="IBorderFormatting.VerticalBorderColorColor" />
public IColor VerticalBorderColorColor
{
get
{
return HSSFColor.Automatic.GetInstance();
}
set
{
//nothing, Not available for HSSF.
}
}

/// <summary>
/// HSSF Doesn't support table borders, so always <see cref="HSSFColorPredefined.AUTOMATIC" />
/// </summary>
/// <see cref="NPOI.SS.UserModel.BorderFormatting.HorizontalBorderColor" />
public short HorizontalBorderColor
{
get
{
return HSSFColor.Automatic.Index;
}
set
{
//nothing, Not available for HSSF.
}
}

/// <summary>
/// HSSF Doesn't support table borders, so always <see cref="HSSFColorPredefined.AUTOMATIC" />
/// </summary>
/// <see cref="NPOI.SS.UserModel.BorderFormatting.HorizontalBorderColorColor" />
public IColor HorizontalBorderColorColor
{
get
{
return HSSFColor.Automatic.GetInstance();
}
set
{
//nothing, Not available for HSSF.
}
}
}
}
20 changes: 20 additions & 0 deletions main/HSSF/UserModel/HSSFExtendedColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
namespace NPOI.HSSF.UserModel
{
using System;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using RecordExtendedColor = NPOI.HSSF.Record.Common.ExtendedColor;

Expand Down Expand Up @@ -177,6 +178,25 @@ public override double Tint
color.Tint = (/*setter*/value);
}
}

protected override byte[] IndexedRGB
{
get
{
if (IsIndexed && Index > 0) {
int indexNum = Index;
HSSFColor indexed = HSSFColor.GetIndexHash()[indexNum];
if (indexed != null) {
byte[] rgb = new byte[3];
rgb[0] = (byte) indexed.GetTriplet()[0];
rgb[1] = (byte) indexed.GetTriplet()[1];
rgb[2] = (byte) indexed.GetTriplet()[2];
return rgb;
}
} // else
return null;
}
}
}

}
21 changes: 20 additions & 1 deletion main/SS/Formula/Eval/RefListEval.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
using System;
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

using System.Collections.Generic;
using System.Text;

namespace NPOI.SS.Formula.Eval
{
/// <summary>
/// Handling of a list of values, e.g. the 2nd argument in RANK(A1,(B1,B2,B3),1)
/// </summary>
public class RefListEval:ValueEval
{
private List<ValueEval> list = new List<ValueEval>();
Expand Down
29 changes: 9 additions & 20 deletions main/SS/Formula/Functions/Rank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ public class Rank : Var2or3ArgFunction

public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1)
{

AreaEval aeRange;
double result;
try
{
ValueEval ve = OperandResolver.GetSingleValue(arg0, srcRowIndex, srcColumnIndex);
result = OperandResolver.CoerceValueToDouble(ve);
double result = OperandResolver.CoerceValueToDouble(ve);
if (Double.IsNaN(result) || Double.IsInfinity(result))
{
throw new EvaluationException(ErrorEval.NUM_ERROR);
Expand All @@ -57,7 +54,7 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva
{
return eval(result, listEval, true);
}
aeRange = ConvertRangeArg(arg1);
AreaEval aeRange = ConvertRangeArg(arg1);
return eval(result, aeRange, true);
}
catch (EvaluationException e)
Expand All @@ -68,12 +65,10 @@ public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEva

public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2)
{
double result;

try
{
ValueEval ve = OperandResolver.GetSingleValue(arg0, srcRowIndex, srcColumnIndex);
result = OperandResolver.CoerceValueToDouble(ve);
double result = OperandResolver.CoerceValueToDouble(ve);
if (Double.IsNaN(result) || Double.IsInfinity(result))
{
throw new EvaluationException(ErrorEval.NUM_ERROR);
Expand Down Expand Up @@ -128,22 +123,16 @@ private static NumberEval eval(double arg0, RefListEval aeRange, bool descending
{
int rank = 1;

List<int> replaceList = new List<int>();
for (int i = 0; i < aeRange.GetList().Count; i++)
var list = aeRange.GetList();
for (int i = 0; i < list.Count; i++)
{
ValueEval ve = aeRange.GetList()[i];
if (ve is RefEval)
{
{
replaceList.Add(i);
}
}
foreach (var index in replaceList)
ValueEval ve = list[i];
if(ve is RefEval)
{
ValueEval targetVe = aeRange.GetList()[i];
aeRange.GetList()[index] = ((RefEval)targetVe).GetInnerValueEval(((RefEval)ve).FirstSheetIndex);
list[i] = ((RefEval)ve).GetInnerValueEval(((RefEval)ve).FirstSheetIndex);
}
Double value;
ve = list[i];
if (ve is NumberEval numberEval)
{
value = numberEval.NumberValue;
Expand Down
2 changes: 1 addition & 1 deletion main/SS/Formula/PTG/NamePtg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public NamePtg(int nameIndex)

public NamePtg(ILittleEndianInput in1)
{
field_1_label_index = in1.ReadShort();
field_1_label_index = in1.ReadUShort();
field_2_zero = in1.ReadShort();
}

Expand Down
2 changes: 0 additions & 2 deletions main/SS/Formula/WorkbookEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,6 @@ public ValueEval EvaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs)
ValueEval opResult;
if (ptg is OperationPtg optg)
{
if (optg is UnionPtg) { continue; }

int numops = optg.NumberOfOperands;
ValueEval[] ops = new ValueEval[numops];

Expand Down
Loading
Loading