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
7 changes: 7 additions & 0 deletions main/SS/UserModel/Charts/ChartAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public interface IChartAxis
* @return minor tick mark.
*/
AxisTickMark MinorTickMark { get; set; }


/// <summary>
/// Use this to check before retrieving a number format, as calling {@link #getNumberFormat()} may create a default one if none exists.
/// </summary>
/// <returns>return true if a number format element is defined, false if not</returns>
bool HasNumberFormat();
}


Expand Down
16 changes: 12 additions & 4 deletions main/SS/UserModel/Charts/ChartAxisFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@ namespace NPOI.SS.UserModel.Charts
/// </summary>
/// <remarks>@author Roman Kashitsyn</remarks>
public interface IChartAxisFactory
{
{
/// <summary>
/// returns new value axis
/// create new value axis at the end of the list at the specified chart position.
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
IValueAxis CreateValueAxis(AxisPosition pos);

/// <summary>
/// create new category axis at the end of the list at the specified chart position.
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
IChartAxis CreateCategoryAxis(AxisPosition pos);

/// <summary>
/// create new date category axis at the end of the list at the specified chart position.
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
IChartAxis CreateDateAxis(AxisPosition pos);
}

Expand Down
3 changes: 2 additions & 1 deletion ooxml/XSSF/Streaming/SXSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ private void InjectData(FileInfo zipfile, Stream outStream, bool leaveOpen)
zos.PutNextEntry(new ZipEntry(ze.Name));
var inputStream = zip.GetInputStream(ze);
XSSFSheet xSheet = GetSheetFromZipEntryName(ze.Name);
if (xSheet != null)
// See bug 56557, we should not inject data into the special ChartSheets
if (xSheet != null && !(xSheet is XSSFChartSheet))
{
SXSSFSheet sxSheet = GetSXSSFSheet(xSheet);
var xis = sxSheet.GetWorksheetXMLInputStream();
Expand Down
10 changes: 10 additions & 0 deletions ooxml/XSSF/UserModel/Charts/XSSFCategoryAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public void SetAuto(CT_Boolean au)
ctCatAx.auto = au;
}

public override CT_ChartLines GetMajorGridLines()
{
return ctCatAx.majorGridlines;
}

private void createAxis(long id, AxisPosition pos)
{
ctCatAx = chart.GetCTChart().plotArea.AddNewCatAx();
Expand All @@ -109,6 +114,11 @@ private void createAxis(long id, AxisPosition pos)
this.MajorTickMark=(AxisTickMark.Cross);
this.MinorTickMark=(AxisTickMark.None);
}

public override bool HasNumberFormat()
{
return ctCatAx.IsSetNumFmt();
}
}
}

43 changes: 23 additions & 20 deletions ooxml/XSSF/UserModel/Charts/XSSFChartAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public AxisPosition Position
{
get
{
return toAxisPosition(GetCTAxPos());
return ToAxisPosition(GetCTAxPos());
}
set
{
GetCTAxPos().val = fromAxisPosition(value);
GetCTAxPos().val = FromAxisPosition(value);
}
}

Expand Down Expand Up @@ -180,12 +180,12 @@ public AxisOrientation Orientation
{
get
{
return toAxisOrientation(GetCTScaling().orientation);
return ToAxisOrientation(GetCTScaling().orientation);
}
set
{
CT_Scaling scaling = GetCTScaling();
ST_Orientation stOrientation = fromAxisOrientation(value);
ST_Orientation stOrientation = FromAxisOrientation(value);
if (scaling.IsSetOrientation())
{
scaling.orientation.val = stOrientation;
Expand All @@ -201,11 +201,11 @@ public AxisCrosses Crosses
{
get
{
return toAxisCrosses(GetCTCrosses());
return ToAxisCrosses(GetCTCrosses());
}
set
{
GetCTCrosses().val = fromAxisCrosses(value);
GetCTCrosses().val = FromAxisCrosses(value);
}
}
public bool IsVisible
Expand All @@ -220,27 +220,27 @@ public bool IsVisible
}
}

public AxisTickMark MajorTickMark
public virtual AxisTickMark MajorTickMark
{
get
{
return toAxisTickMark(GetMajorCTTickMark());
return ToAxisTickMark(GetMajorCTTickMark());
}
set
{
GetMajorCTTickMark().val = fromAxisTickMark(value);
GetMajorCTTickMark().val = FromAxisTickMark(value);
}
}

public AxisTickMark MinorTickMark
public virtual AxisTickMark MinorTickMark
{
get
{
return toAxisTickMark(GetMinorCTTickMark());
return ToAxisTickMark(GetMinorCTTickMark());
}
set
{
GetMinorCTTickMark().val = fromAxisTickMark(value);
GetMinorCTTickMark().val = FromAxisTickMark(value);
}
}

Expand All @@ -251,8 +251,11 @@ public AxisTickMark MinorTickMark
protected abstract CT_Boolean GetDelete();
protected abstract CT_TickMark GetMajorCTTickMark();
protected abstract CT_TickMark GetMinorCTTickMark();
public abstract CT_ChartLines GetMajorGridLines();

private static ST_Orientation fromAxisOrientation(AxisOrientation orientation)
public abstract bool HasNumberFormat();

private static ST_Orientation FromAxisOrientation(AxisOrientation orientation)
{
switch (orientation)
{
Expand All @@ -263,7 +266,7 @@ private static ST_Orientation fromAxisOrientation(AxisOrientation orientation)
}
}

private static AxisOrientation toAxisOrientation(CT_Orientation ctOrientation)
private static AxisOrientation ToAxisOrientation(CT_Orientation ctOrientation)
{
switch (ctOrientation.val)
{
Expand All @@ -274,7 +277,7 @@ private static AxisOrientation toAxisOrientation(CT_Orientation ctOrientation)
}
}

private static ST_Crosses fromAxisCrosses(AxisCrosses crosses)
private static ST_Crosses FromAxisCrosses(AxisCrosses crosses)
{
switch (crosses)
{
Expand All @@ -286,7 +289,7 @@ private static ST_Crosses fromAxisCrosses(AxisCrosses crosses)
}
}

private static AxisCrosses toAxisCrosses(CT_Crosses ctCrosses)
private static AxisCrosses ToAxisCrosses(CT_Crosses ctCrosses)
{
switch (ctCrosses.val)
{
Expand All @@ -298,7 +301,7 @@ private static AxisCrosses toAxisCrosses(CT_Crosses ctCrosses)
}
}

private static ST_AxPos fromAxisPosition(AxisPosition position)
private static ST_AxPos FromAxisPosition(AxisPosition position)
{
switch (position)
{
Expand All @@ -311,7 +314,7 @@ private static ST_AxPos fromAxisPosition(AxisPosition position)
}
}

private static AxisPosition toAxisPosition(CT_AxPos ctAxPos)
private static AxisPosition ToAxisPosition(CT_AxPos ctAxPos)
{
switch (ctAxPos.val)
{
Expand All @@ -322,7 +325,7 @@ private static AxisPosition toAxisPosition(CT_AxPos ctAxPos)
default: return AxisPosition.Bottom;
}
}
private static ST_TickMark fromAxisTickMark(AxisTickMark tickMark)
private static ST_TickMark FromAxisTickMark(AxisTickMark tickMark)
{
switch (tickMark)
{
Expand All @@ -335,7 +338,7 @@ private static ST_TickMark fromAxisTickMark(AxisTickMark tickMark)
}
}

private static AxisTickMark toAxisTickMark(CT_TickMark ctTickMark)
private static AxisTickMark ToAxisTickMark(CT_TickMark ctTickMark)
{
switch (ctTickMark.val)
{
Expand Down
40 changes: 29 additions & 11 deletions ooxml/XSSF/UserModel/Charts/XSSFDateAxis.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
using NPOI.OpenXmlFormats.Dml.Chart;
/* ====================================================================
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 NPOI.OpenXmlFormats.Dml.Chart;
using NPOI.SS.UserModel.Charts;
using System;
using System.Collections.Generic;
Expand All @@ -14,7 +31,7 @@ public XSSFDateAxis(XSSFChart chart, long id, AxisPosition pos)
: base(chart)
{

createAxis(id, pos);
CreateAxis(id, pos);
}

public XSSFDateAxis(XSSFChart chart, CT_DateAx ctDateAx)
Expand Down Expand Up @@ -84,7 +101,7 @@ protected override CT_TickMark GetMinorCTTickMark()
return ctDateAx.minorTickMark;
}

protected CT_ChartLines GetMajorGridLines()
public override CT_ChartLines GetMajorGridLines()
{
return ctDateAx.majorGridlines;
}
Expand All @@ -94,22 +111,18 @@ public override void CrossAxis(IChartAxis axis)
ctDateAx.crossAx.val = (uint)axis.Id;
}

public CT_TimeUnit GetBaseTimeUnit()
public CT_TimeUnit BaseTimeUnit
{
return ctDateAx.baseTimeUnit;
}

public void SetBaseTimeUnit(CT_TimeUnit unit)
{
ctDateAx.baseTimeUnit = unit;
get { return ctDateAx.baseTimeUnit; }
set { ctDateAx.baseTimeUnit = value;}
}

public void SetAuto(CT_Boolean au)
{
ctDateAx.auto = au;
}

private void createAxis(long id, AxisPosition pos)
private void CreateAxis(long id, AxisPosition pos)
{
ctDateAx = chart.GetCTChart().plotArea.AddNewDateAx();
ctDateAx.AddNewAxId().val = (uint)id;
Expand All @@ -130,5 +143,10 @@ private void createAxis(long id, AxisPosition pos)
this.MajorTickMark = (AxisTickMark.Cross);
this.MinorTickMark = (AxisTickMark.None);
}

public override bool HasNumberFormat()
{
return ctDateAx.IsSetNumFmt();
}
}
}
13 changes: 11 additions & 2 deletions ooxml/XSSF/UserModel/Charts/XSSFValueAxis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override long Id

public void SetCrossBetween(AxisCrossBetween crossBetween)
{
ctValAx.crossBetween.val= fromCrossBetween(crossBetween);
ctValAx.crossBetween.val= FromCrossBetween(crossBetween);
}

public AxisCrossBetween GetCrossBetween()
Expand Down Expand Up @@ -106,6 +106,10 @@ protected override CT_Crosses GetCTCrosses()
{
return ctValAx.crosses;
}
public override CT_ChartLines GetMajorGridLines()
{
return ctValAx.majorGridlines;
}

public override void CrossAxis(IChartAxis axis)
{
Expand Down Expand Up @@ -135,7 +139,7 @@ private void CreateAxis(long id, AxisPosition pos)
MinorTickMark=(AxisTickMark.None);
}

private static ST_CrossBetween fromCrossBetween(AxisCrossBetween crossBetween)
private static ST_CrossBetween FromCrossBetween(AxisCrossBetween crossBetween)
{
switch (crossBetween)
{
Expand All @@ -156,5 +160,10 @@ private static AxisCrossBetween ToCrossBetween(ST_CrossBetween ctCrossBetween)
throw new ArgumentException();
}
}

public override bool HasNumberFormat()
{
return ctValAx.IsSetNumFmt();
}
}
}
12 changes: 12 additions & 0 deletions ooxml/XSSF/UserModel/XSSFChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ private bool HasAxis()
private void ParseAxis()
{
ParseCategoryAxis();
ParseDateAxis();
ParseValueAxis();
}
private void ParseCategoryAxis()
Expand All @@ -394,6 +395,17 @@ private void ParseCategoryAxis()
axis.Add(new XSSFCategoryAxis(this, catAx));
}
}

private void ParseDateAxis()
{
if (chart.plotArea.dateAx == null)
return;
foreach (CT_DateAx dateAx in chart.plotArea.dateAx)
{
axis.Add(new XSSFDateAxis(this, dateAx));
}
}

private void ParseValueAxis()
{
if (chart.plotArea.valAx == null)
Expand Down
16 changes: 15 additions & 1 deletion testcases/ooxml/XSSF/Streaming/TestSXSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,20 @@ public void CreateFromReadOnlyWorkbook()
ClassicAssert.AreEqual("Test Row 9", s.GetRow(9).GetCell(2).StringCellValue);
}

[Test]
public void Test56557()
{
IWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("56557.xlsx");

// Using streaming XSSFWorkbook makes the output file invalid
wb = new SXSSFWorkbook((XSSFWorkbook)wb);

// Should not throw POIXMLException: java.io.IOException: Unable to parse xml bean when reading back
IWorkbook wbBack = XSSFTestDataSamples.WriteOutAndReadBack(wb);
ClassicAssert.IsNotNull(wbBack);
wbBack.Close();

wb.Close();
}
}

}
Loading
Loading