Skip to content

Commit 68dbba1

Browse files
author
JanKallman
committed
Some changes to the sample project. New sample 12 & 13. Some Changes and fixes on pivot tables. GetValue<T> method added to Range and worksheet for easier type conversion (handles DateTime, TimeSpan, Nullable and decimal).
Next version is close, so please report any bugs found in this code. --HG-- extra : convert_revision : svn%3Ac031521d-7fdb-604e-9ef1-0138de3cd895/trunk%4083
1 parent ab81d45 commit 68dbba1

35 files changed

+1226
-248
lines changed

ExcelPackage/Drawing/Chart/ExcelChart.cs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,24 @@ public enum eTrendLine
292292
/// </summary>
293293
Power
294294
}
295+
/// <summary>
296+
/// Specifies the possible ways to display blanks
297+
/// </summary>
298+
public enum eDisplayBlanksAs
299+
{
300+
/// <summary>
301+
/// Blank values shall be left as a gap
302+
/// </summary>
303+
Gap,
304+
/// <summary>
305+
/// Blank values shall be spanned with a line (Line charts)
306+
/// </summary>
307+
Span,
308+
/// <summary>
309+
/// Blank values shall be treated as zero
310+
/// </summary>
311+
Zero
312+
}
295313
#endregion
296314

297315

@@ -377,7 +395,7 @@ private void Init(ExcelDrawings drawings, XmlNode chartNode)
377395
{
378396
//_chartXmlHelper = new XmlHelper(drawings.NameSpaceManager, chartNode);
379397
_chartXmlHelper = XmlHelperFactory.Create(drawings.NameSpaceManager, chartNode);
380-
_chartXmlHelper.SchemaNodeOrder = new string[] { "title", "pivotFmt", "view3D", "plotArea", "barDir", "grouping", "varyColors", "ser", "dLbls", "dropLines", "upDownBars", "marker", "smooth", "shape", "legend", "overlap", "axId", "spPr", "printSettings" };
398+
_chartXmlHelper.SchemaNodeOrder = new string[] { "title", "pivotFmt", "view3D", "plotArea", "barDir", "grouping", "varyColors", "ser", "dLbls", "dropLines", "upDownBars", "marker", "smooth", "shape", "legend", "plotVisOnly","dispBlanksAs", "overlap", "axId", "spPr", "printSettings" };
381399
WorkSheet = drawings.Worksheet;
382400
}
383401
#endregion
@@ -1235,6 +1253,53 @@ public eChartStyle Style
12351253
}
12361254
}
12371255
}
1256+
const string _plotVisibleOnlyPath="../../c:plotVisOnly/@val";
1257+
/// <summary>
1258+
/// Show data in hidden rows and columns
1259+
/// </summary>
1260+
public bool ShowHiddenData
1261+
{
1262+
get
1263+
{
1264+
//!!Inverted value!!
1265+
return !_chartXmlHelper.GetXmlNodeBool(_plotVisibleOnlyPath);
1266+
}
1267+
set
1268+
{
1269+
//!!Inverted value!!
1270+
_chartXmlHelper.SetXmlNodeBool(_plotVisibleOnlyPath, !value);
1271+
}
1272+
}
1273+
const string _displayBlanksAsPath = "../../c:dispBlanksAs/@val";
1274+
/// <summary>
1275+
/// Specifies the possible ways to display blanks
1276+
/// </summary>
1277+
public eDisplayBlanksAs DisplayBlanksAs
1278+
{
1279+
get
1280+
{
1281+
string v=_chartXmlHelper.GetXmlNodeString(_displayBlanksAsPath);
1282+
if (string.IsNullOrEmpty(v))
1283+
{
1284+
return eDisplayBlanksAs.Gap;
1285+
}
1286+
else
1287+
{
1288+
return (eDisplayBlanksAs)Enum.Parse(typeof(eDisplayBlanksAs), v, true);
1289+
}
1290+
}
1291+
set
1292+
{
1293+
if (value == eDisplayBlanksAs.Gap)
1294+
{
1295+
_chartSeries.DeleteNode(_displayBlanksAsPath);
1296+
}
1297+
else
1298+
{
1299+
_chartSeries.SetXmlNodeString(_displayBlanksAsPath, value.ToString().ToLower());
1300+
}
1301+
}
1302+
}
12381303
private bool HasPrimaryAxis()
12391304
{
12401305
if (_plotArea.ChartTypes.Count == 1)

ExcelPackage/EPPlus.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<Compile Include="ExcelWorksheetView.cs" />
144144
<Compile Include="EncryptedPackageHandler.cs" />
145145
<Compile Include="Table\PivotTable\ExcelPivotTableFieldGroup.cs" />
146+
<Compile Include="Table\PivotTable\ExcelPivotTableFieldItem.cs" />
146147
<Compile Include="Table\PivotTable\ExcelPivotTablePageFieldSettings.cs" />
147148
<Compile Include="Table\PivotTable\ExcelPivotTableDataField.cs" />
148149
<Compile Include="Table\PivotTable\ExcelPivotTableFieldCollection.cs" />

ExcelPackage/ExcelCell.cs

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private enum flags
4343

4444
}
4545
#region Cell Private Properties
46-
private ExcelWorksheet _xlWorksheet;
46+
private ExcelWorksheet _worksheet;
4747
private int _row;
4848
private int _col;
4949
internal string _formula="";
@@ -53,59 +53,59 @@ private enum flags
5353
#endregion
5454
#region ExcelCell Constructor
5555
/// <summary>
56-
/// Creates a new instance of ExcelCell class. For internal use only!
56+
/// A cell in the worksheet.
5757
/// </summary>
58-
/// <param name="xlWorksheet">A reference to the parent worksheet</param>
59-
/// <param name="row">The row number in the parent worksheet</param>
60-
/// <param name="col">The column number in the parent worksheet</param>
61-
protected internal ExcelCell(ExcelWorksheet xlWorksheet, int row, int col)
58+
/// <param name="worksheet">A reference to the worksheet</param>
59+
/// <param name="row">Row number</param>
60+
/// <param name="col">Column number</param>
61+
internal ExcelCell(ExcelWorksheet worksheet, int row, int col)
6262
{
6363
if (row < 1 || col < 1)
64-
throw new Exception("ExcelCell Constructor: Negative row and column numbers are not allowed");
64+
throw new ArgumentException("Negative row and column numbers are not allowed");
6565
if (row > ExcelPackage.MaxRows || col > ExcelPackage.MaxColumns)
66-
throw new Exception("ExcelCell Constructor: row or column numbers are out of range");
67-
if (xlWorksheet == null)
68-
throw new Exception("ExcelCell Constructor: xlWorksheet must be set to a valid reference");
66+
throw new ArgumentException("Row or column numbers are out of range");
67+
if (worksheet == null)
68+
throw new ArgumentException("Worksheet must be set to a valid reference");
6969

7070
_row = row;
7171
_col = col;
72-
_xlWorksheet = xlWorksheet;
73-
if (col < xlWorksheet._minCol) xlWorksheet._minCol = col;
74-
if (col > xlWorksheet._maxCol) xlWorksheet._maxCol = col;
72+
_worksheet = worksheet;
73+
if (col < worksheet._minCol) worksheet._minCol = col;
74+
if (col > worksheet._maxCol) worksheet._maxCol = col;
7575
_sharedFormulaID = int.MinValue;
7676
IsRichText = false;
7777
}
78-
protected internal ExcelCell(ExcelWorksheet xlWorksheet, string cellAddress)
78+
internal ExcelCell(ExcelWorksheet worksheet, string cellAddress)
7979
{
80-
_xlWorksheet = xlWorksheet;
80+
_worksheet = worksheet;
8181
GetRowColFromAddress(cellAddress, out _row, out _col);
82-
if (_col < xlWorksheet._minCol) xlWorksheet._minCol = _col;
83-
if (_col > xlWorksheet._maxCol) xlWorksheet._maxCol = _col;
82+
if (_col < worksheet._minCol) worksheet._minCol = _col;
83+
if (_col > worksheet._maxCol) worksheet._maxCol = _col;
8484
_sharedFormulaID = int.MinValue;
8585
IsRichText = false;
8686
}
87-
#endregion // END Cell Constructors
87+
#endregion
8888
internal ulong CellID
8989
{
9090
get
9191
{
92-
return GetCellID(_xlWorksheet.SheetID, Row, Column);
92+
return GetCellID(_worksheet.SheetID, Row, Column);
9393
}
9494
}
9595
#region ExcelCell Public Properties
9696

9797
/// <summary>
98-
/// Read-only reference to the cell's row number
98+
/// Row number
9999
/// </summary>
100-
public int Row { get { return _row; } internal set { _row = value; } }
100+
internal int Row { get { return _row; } set { _row = value; } }
101101
/// <summary>
102-
/// Read-only reference to the cell's column number
102+
/// Column number
103103
/// </summary>
104-
public int Column { get { return _col; } internal set { _col = value; } }
104+
internal int Column { get { return _col; } set { _col = value; } }
105105
/// <summary>
106-
/// Returns the current cell address in the standard Excel format (e.g. 'E5')
106+
/// The address
107107
/// </summary>
108-
public string CellAddress { get { return GetAddress(_row, _col); } }
108+
internal string CellAddress { get { return GetAddress(_row, _col); } }
109109
/// <summary>
110110
/// Returns true if the cell's contents are numeric.
111111
/// </summary>
@@ -175,7 +175,7 @@ public string StyleName
175175
}
176176
set
177177
{
178-
_styleID = _xlWorksheet.Workbook.Styles.GetStyleIdFromName(value);
178+
_styleID = _worksheet.Workbook.Styles.GetStyleIdFromName(value);
179179
_styleName = value;
180180
}
181181
}
@@ -191,9 +191,9 @@ public int StyleID
191191
{
192192
if(_styleID>0)
193193
return _styleID;
194-
else if (_xlWorksheet._rows != null && _xlWorksheet._rows.ContainsKey(ExcelRow.GetRowID(_xlWorksheet.SheetID, Row)))
194+
else if (_worksheet._rows != null && _worksheet._rows.ContainsKey(ExcelRow.GetRowID(_worksheet.SheetID, Row)))
195195
{
196-
return _xlWorksheet.Row(Row).StyleID;
196+
return _worksheet.Row(Row).StyleID;
197197
}
198198
else
199199
{
@@ -216,7 +216,7 @@ public int StyleID
216216

217217
private ExcelColumn GetColumn(int col)
218218
{
219-
foreach (ExcelColumn column in _xlWorksheet._columns)
219+
foreach (ExcelColumn column in _worksheet._columns)
220220
{
221221
if (col >= column.ColumnMin && col <= column.ColumnMax)
222222
{
@@ -233,7 +233,7 @@ public ExcelStyle Style
233233
{
234234
get
235235
{
236-
return _xlWorksheet.Workbook.Styles.GetStyleObject(StyleID, _xlWorksheet.PositionID, CellAddress);
236+
return _worksheet.Workbook.Styles.GetStyleObject(StyleID, _worksheet.PositionID, CellAddress);
237237
}
238238
}
239239
internal void SetNewStyleName(string Name, int Id)
@@ -298,9 +298,9 @@ public string Formula
298298
}
299299
else
300300
{
301-
if (_xlWorksheet._sharedFormulas.ContainsKey(SharedFormulaID))
301+
if (_worksheet._sharedFormulas.ContainsKey(SharedFormulaID))
302302
{
303-
var f = _xlWorksheet._sharedFormulas[SharedFormulaID];
303+
var f = _worksheet._sharedFormulas[SharedFormulaID];
304304
if (f.StartRow == Row && f.StartCol == Column)
305305
{
306306
return f.Formula;
@@ -322,9 +322,9 @@ public string Formula
322322
_formula = value;
323323
_formulaR1C1 = "";
324324
_sharedFormulaID = int.MinValue;
325-
if (_formula!="" && !_xlWorksheet._formulaCells.ContainsKey(CellID))
325+
if (_formula!="" && !_worksheet._formulaCells.ContainsKey(CellID))
326326
{
327-
_xlWorksheet._formulaCells.Add(this);
327+
_worksheet._formulaCells.Add(this);
328328
}
329329
}
330330
}
@@ -348,9 +348,9 @@ public string FormulaR1C1
348348
}
349349
else
350350
{
351-
if (_xlWorksheet._sharedFormulas.ContainsKey(SharedFormulaID))
351+
if (_worksheet._sharedFormulas.ContainsKey(SharedFormulaID))
352352
{
353-
return TranslateToR1C1(_xlWorksheet._sharedFormulas[SharedFormulaID].Formula, Row, Column);
353+
return TranslateToR1C1(_worksheet._sharedFormulas[SharedFormulaID].Formula, Row, Column);
354354
}
355355
else
356356
{
@@ -367,9 +367,9 @@ public string FormulaR1C1
367367
_formulaR1C1 = value;
368368
_formula = "";
369369
SharedFormulaID = int.MinValue;
370-
if (!_xlWorksheet._formulaCells.ContainsKey(CellID))
370+
if (!_worksheet._formulaCells.ContainsKey(CellID))
371371
{
372-
_xlWorksheet._formulaCells.Add(this);
372+
_worksheet._formulaCells.Add(this);
373373
}
374374
}
375375
}
@@ -385,7 +385,7 @@ public int SharedFormulaID {
385385
set
386386
{
387387
_sharedFormulaID = value;
388-
if(_xlWorksheet._formulaCells.ContainsKey(CellID)) _xlWorksheet._formulaCells.Delete(CellID);
388+
if(_worksheet._formulaCells.ContainsKey(CellID)) _worksheet._formulaCells.Delete(CellID);
389389
}
390390
}
391391
public bool IsArrayFormula { get; internal set; }
@@ -442,11 +442,10 @@ ulong IRangeID.RangeID
442442
{
443443
get
444444
{
445-
return GetCellID(_xlWorksheet.SheetID, Row, Column);
445+
return GetCellID(_worksheet.SheetID, Row, Column);
446446
}
447447
set
448448
{
449-
//_sheet = (int)(cellID % 0x8000);
450449
_col = ((int)(value >> 15) & 0x3FF);
451450
_row = ((int)(value >> 29));
452451
}

0 commit comments

Comments
 (0)