Skip to content

Commit 16b9489

Browse files
author
JanKallman
committed
New Sample 9-csv files, charts-multiple chart types, secondary axis. Sample 10-Encryption. Added ExcelWorkbookView.
Please Report any bugs, strange behavior or miss spellings found in this code, next version is close. --HG-- rename : SampleApp/LinqSample.cs => SampleApp/Sample8.cs extra : convert_revision : svn%3Ac031521d-7fdb-604e-9ef1-0138de3cd895/trunk%4053
1 parent 8da8bda commit 16b9489

38 files changed

+1045
-163
lines changed

ExcelPackage/Drawing/Chart/ExcelChart.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private void CreateNewChart(ExcelDrawings drawings, eChartType type, ExcelChart
387387
XmlElement graphFrame = TopNode.OwnerDocument.CreateElement("graphicFrame", ExcelPackage.schemaSheetDrawings);
388388
graphFrame.SetAttribute("macro", "");
389389
TopNode.AppendChild(graphFrame);
390-
graphFrame.InnerXml = "<xdr:nvGraphicFramePr><xdr:cNvPr id=\"2\" name=\"Chart 1\" /><xdr:cNvGraphicFramePr /></xdr:nvGraphicFramePr><xdr:xfrm><a:off x=\"0\" y=\"0\" /> <a:ext cx=\"0\" cy=\"0\" /></xdr:xfrm><a:graphic><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/chart\"><c:chart xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:id=\"rId1\" /> </a:graphicData> </a:graphic>";
390+
graphFrame.InnerXml = string.Format("<xdr:nvGraphicFramePr><xdr:cNvPr id=\"{0}\" name=\"Chart 1\" /><xdr:cNvGraphicFramePr /></xdr:nvGraphicFramePr><xdr:xfrm><a:off x=\"0\" y=\"0\" /> <a:ext cx=\"0\" cy=\"0\" /></xdr:xfrm><a:graphic><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/chart\"><c:chart xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:id=\"rId1\" /> </a:graphicData> </a:graphic>",_id);
391391
TopNode.AppendChild(TopNode.OwnerDocument.CreateElement("clientData", ExcelPackage.schemaSheetDrawings));
392392

393393
Package package = drawings.Worksheet.xlPackage.Package;
@@ -565,6 +565,10 @@ private string GetChartSerieStartXml(eChartType type, int axID, int xAxID)
565565
xml.Append(AddShape(type));
566566
xml.Append(AddFirstSliceAng(type));
567567
xml.Append(AddHoleSize(type));
568+
if (IsTypeStacked() || IsTypePercentStacked())
569+
{
570+
xml.Append("<c:overlap val=\"100\"/>");
571+
}
568572
xml.Append(AddAxisId(axID, xAxID));
569573

570574
return xml.ToString();
@@ -795,6 +799,9 @@ protected bool IsTypePercentStacked()
795799
{
796800
return ChartType == eChartType.AreaStacked100 ||
797801
ChartType == eChartType.BarStacked100 ||
802+
ChartType == eChartType.BarStacked1003D ||
803+
ChartType == eChartType.ColumnStacked100 ||
804+
ChartType == eChartType.ColumnStacked1003D ||
798805
ChartType == eChartType.ConeBarStacked100 ||
799806
ChartType == eChartType.ConeColStacked100 ||
800807
ChartType == eChartType.CylinderBarStacked100 ||
@@ -807,8 +814,11 @@ protected bool IsTypePercentStacked()
807814
protected bool IsTypeStacked()
808815
{
809816
return ChartType == eChartType.AreaStacked ||
817+
ChartType == eChartType.AreaStacked3D ||
810818
ChartType == eChartType.BarStacked ||
819+
ChartType == eChartType.BarStacked3D ||
811820
ChartType == eChartType.ColumnStacked3D ||
821+
ChartType == eChartType.ColumnStacked ||
812822
ChartType == eChartType.ConeBarStacked ||
813823
ChartType == eChartType.ConeColStacked ||
814824
ChartType == eChartType.CylinderBarStacked ||

ExcelPackage/Drawing/Chart/ExcelChartSerie.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,38 @@ public string Header
9494
}
9595
set
9696
{
97-
//Where need this one
97+
//We need this one
9898
CreateNode(headerPath);
9999
SetXmlNodeString(headerPath, value);
100100
}
101101
}
102+
const string headerAddressPath = "c:tx/c:strRef/c:f";
103+
/// <summary>
104+
/// Header address for the serie.
105+
/// </summary>
106+
public ExcelAddressBase HeaderAddress
107+
{
108+
get
109+
{
110+
string address = GetXmlNodeString(headerAddressPath);
111+
if (address == "")
112+
{
113+
return null;
114+
}
115+
else
116+
{
117+
return new ExcelAddressBase(address);
118+
}
119+
}
120+
set
121+
{
122+
if (value._fromCol != value._toCol || value._fromRow != value._toRow || value.Addresses != null)
123+
{
124+
throw (new Exception("Address must be a single cell"));
125+
}
126+
SetXmlNodeString(headerAddressPath, ExcelCell.GetFullAddress(value.WorkSheet, value.Address));
127+
}
128+
}
102129
string _seriesTopPath;
103130
string _seriesPath = "{0}/c:numRef/c:f";
104131
/// <summary>

ExcelPackage/Drawing/Chart/ExcelChartSeries.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public ExcelChart Chart
9898
}
9999
#region "Add Series"
100100

101-
public ExcelChartSerie Add(ExcelRange Serie, ExcelRange XSerie)
101+
public ExcelChartSerie Add(ExcelRangeBase Serie, ExcelRangeBase XSerie)
102102
{
103-
return AddSeries(Serie.Address, XSerie.Address);
103+
return AddSeries(Serie.FullAddressAbsolute, XSerie.FullAddressAbsolute);
104104
}
105105
public ExcelChartSerie Add(string SerieAddress, string XSerieAddress)
106106
{

ExcelPackage/Drawing/Chart/ExcelDoughnutChart.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using System.Collections.Generic;
3333
using System.Text;
3434
using System.Xml;
35+
using System.Globalization;
3536

3637
namespace OfficeOpenXml.Drawing.Chart
3738
{
@@ -83,7 +84,7 @@ public decimal FirstSliceAngle
8384
}
8485
internal set
8586
{
86-
_chartXmlHelper.SetXmlNodeString(_firstSliceAngPath, value.ToString());
87+
_chartXmlHelper.SetXmlNodeString(_firstSliceAngPath, value.ToString(CultureInfo.InvariantCulture));
8788
}
8889
}
8990
//string _holeSizePath = "c:chartSpace/c:chart/c:plotArea/{0}/c:holeSize/@val";
@@ -99,7 +100,7 @@ public decimal HoleSize
99100
}
100101
internal set
101102
{
102-
_chartXmlHelper.SetXmlNodeString(_holeSizePath, value.ToString());
103+
_chartXmlHelper.SetXmlNodeString(_holeSizePath, value.ToString(CultureInfo.InvariantCulture));
103104
}
104105
}
105106
}

ExcelPackage/Drawing/ExcelDrawingBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public int RowOff
141141
protected ExcelDrawings _drawings;
142142
protected XmlNode _topNode;
143143
string _nameXPath;
144-
int _id;
144+
protected internal int _id;
145145
const float STANDARD_DPI = 96;
146146
public const int EMU_PER_PIXEL = 9525;
147147

@@ -274,7 +274,7 @@ private decimal GetColumnWidth(int col)
274274
ExcelWorksheet ws = _drawings.Worksheet;
275275
if (ws._columns.ContainsKey(ExcelColumn.GetColumnID(ws.SheetID, col))) //Check that the column exists
276276
{
277-
return (decimal)ws.Column(col).Width;
277+
return (decimal)ws.Column(col).VisualWidth;
278278
}
279279
else
280280
{
@@ -323,13 +323,13 @@ internal void SetPixelLeft(int pixels)
323323
ExcelWorksheet ws = _drawings.Worksheet;
324324
decimal mdw = ws.Workbook.MaxFontWidth;
325325
int prevPix = 0;
326-
int pix = (int)decimal.Truncate(((256 * (decimal)ws.Column(1).Width + decimal.Truncate(128 / (decimal)mdw)) / 256) * mdw);
326+
int pix = (int)decimal.Truncate(((256 * (decimal)ws.Column(1).VisualWidth + decimal.Truncate(128 / (decimal)mdw)) / 256) * mdw);
327327
int col = 2;
328328

329329
while (pix < pixels)
330330
{
331331
prevPix = pix;
332-
pix += (int)decimal.Truncate(((256 * (decimal)ws.Column(col++).Width + decimal.Truncate(128 / (decimal)mdw)) / 256) * mdw);
332+
pix += (int)decimal.Truncate(((256 * (decimal)ws.Column(col++).VisualWidth + decimal.Truncate(128 / (decimal)mdw)) / 256) * mdw);
333333
}
334334
if (pix == pixels)
335335
{

ExcelPackage/Drawing/ExcelPicture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private void SetPosDefaults(Image image)
224224
private string PicStartXml()
225225
{
226226
StringBuilder xml = new StringBuilder();
227-
xml.AppendFormat("<xdr:nvPicPr><xdr:cNvPr id=\"2\" descr=\"\" />");
227+
xml.AppendFormat("<xdr:nvPicPr><xdr:cNvPr id=\"{0}\" descr=\"\" />", _id);
228228
xml.Append("<xdr:cNvPicPr><a:picLocks noChangeAspect=\"1\" /></xdr:cNvPicPr></xdr:nvPicPr><xdr:blipFill><a:blip xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:embed=\"\" cstate=\"print\" /><a:stretch><a:fillRect /> </a:stretch> </xdr:blipFill> <xdr:spPr> <a:xfrm> <a:off x=\"0\" y=\"0\" /> <a:ext cx=\"0\" cy=\"0\" /> </a:xfrm> <a:prstGeom prst=\"rect\"> <a:avLst /> </a:prstGeom> </xdr:spPr>");
229229
return xml.ToString();
230230
}

ExcelPackage/Drawing/ExcelShape.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public eTextVerticalType TextVertical
431431
private string ShapeStartXml()
432432
{
433433
StringBuilder xml = new StringBuilder();
434-
xml.AppendFormat("<xdr:nvSpPr><xdr:cNvPr id=\"{0}\" name=\"{1}\" /><xdr:cNvSpPr /></xdr:nvSpPr><xdr:spPr><a:prstGeom prst=\"rect\"><a:avLst /></a:prstGeom></xdr:spPr><xdr:style><a:lnRef idx=\"2\"><a:schemeClr val=\"accent1\"><a:shade val=\"50000\" /></a:schemeClr></a:lnRef><a:fillRef idx=\"1\"><a:schemeClr val=\"accent1\" /></a:fillRef><a:effectRef idx=\"0\"><a:schemeClr val=\"accent1\" /></a:effectRef><a:fontRef idx=\"minor\"><a:schemeClr val=\"lt1\" /></a:fontRef></xdr:style><xdr:txBody><a:bodyPr vertOverflow=\"clip\" rtlCol=\"0\" anchor=\"ctr\" /><a:lstStyle /><a:p></a:p></xdr:txBody>", _drawings.Count, Name);
434+
xml.AppendFormat("<xdr:nvSpPr><xdr:cNvPr id=\"{0}\" name=\"{1}\" /><xdr:cNvSpPr /></xdr:nvSpPr><xdr:spPr><a:prstGeom prst=\"rect\"><a:avLst /></a:prstGeom></xdr:spPr><xdr:style><a:lnRef idx=\"2\"><a:schemeClr val=\"accent1\"><a:shade val=\"50000\" /></a:schemeClr></a:lnRef><a:fillRef idx=\"1\"><a:schemeClr val=\"accent1\" /></a:fillRef><a:effectRef idx=\"0\"><a:schemeClr val=\"accent1\" /></a:effectRef><a:fontRef idx=\"minor\"><a:schemeClr val=\"lt1\" /></a:fontRef></xdr:style><xdr:txBody><a:bodyPr vertOverflow=\"clip\" rtlCol=\"0\" anchor=\"ctr\" /><a:lstStyle /><a:p></a:p></xdr:txBody>", _id, Name);
435435
return xml.ToString();
436436
}
437437
private string GetTextAchoringText(eTextAnchoringType value)

ExcelPackage/Drawing/ExcelView3D.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using System.Collections.Generic;
3333
using System.Text;
3434
using System.Xml;
35+
using System.Globalization;
3536

3637
namespace OfficeOpenXml.Drawing
3738
{
@@ -53,7 +54,7 @@ public decimal Perspective
5354
}
5455
set
5556
{
56-
SetXmlNodeString(perspectivePath, value.ToString());
57+
SetXmlNodeString(perspectivePath, value.ToString(CultureInfo.InvariantCulture));
5758
}
5859
}
5960
const string rotXPath = "c:rotX/@val";
@@ -66,7 +67,7 @@ public decimal RotX
6667
set
6768
{
6869
CreateNode(rotXPath);
69-
SetXmlNodeString(rotXPath, value.ToString());
70+
SetXmlNodeString(rotXPath, value.ToString(CultureInfo.InvariantCulture));
7071
}
7172
}
7273
}

ExcelPackage/EPPlus.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<Compile Include="ExcelStyles.cs" />
9494
<Compile Include="ExcelProtection.cs" />
9595
<Compile Include="ExcelTextFormat.cs" />
96+
<Compile Include="ExcelWorkbookView.cs" />
9697
<Compile Include="ExcelWorksheetView.cs" />
9798
<Compile Include="EncryptedPackageHandler.cs" />
9899
<Compile Include="Style\IStyle.cs" />

ExcelPackage/EncryptedPackageHandler.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ internal byte[] WriteBinary()
116116
internal class EncryptionHeader
117117
{
118118
internal Flags Flags;
119-
internal int SizeExtra; //MUST be 0x00000000.
120-
internal AlgorithmID AlgID; //MUST be 0x0000660E (AES-128), 0x0000660F (AES-192), or 0x00006610 (AES-256).
121-
internal AlgorithmHashID AlgIDHash; //MUST be 0x00008004 (SHA-1).
122-
internal int KeySize; //MUST be 0x00000080 (AES-128), 0x000000C0 (AES-192), or 0x00000100 (AES-256).
123-
internal ProviderType ProviderType; //SHOULD<10> be 0x00000018 (AES).
124-
internal int Reserved1; //Undefined and MUST be ignored.
125-
internal int Reserved2; //MUST be 0x00000000 and MUST be ignored.
126-
internal string CSPName; //SHOULD<11> be set to either "Microsoft Enhanced RSA and AES Cryptographic Provider" or "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)" as a null-terminated Unicode string.
119+
internal int SizeExtra; //MUST be 0x00000000.
120+
internal AlgorithmID AlgID; //MUST be 0x0000660E (AES-128), 0x0000660F (AES-192), or 0x00006610 (AES-256).
121+
internal AlgorithmHashID AlgIDHash; //MUST be 0x00008004 (SHA-1).
122+
internal int KeySize; //MUST be 0x00000080 (AES-128), 0x000000C0 (AES-192), or 0x00000100 (AES-256).
123+
internal ProviderType ProviderType; //SHOULD<10> be 0x00000018 (AES).
124+
internal int Reserved1; //Undefined and MUST be ignored.
125+
internal int Reserved2; //MUST be 0x00000000 and MUST be ignored.
126+
internal string CSPName; //SHOULD<11> be set to either "Microsoft Enhanced RSA and AES Cryptographic Provider" or "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)" as a null-terminated Unicode string.
127127

128128

129129
internal byte[] WriteBinary()
@@ -509,6 +509,7 @@ private byte[] CreateTransformInfoPrimary()
509509
/// </summary>
510510
/// <param name="password">The password</param>
511511
/// <param name="algID"></param>
512+
/// <param name="key">The Encryption key</param>
512513
/// <returns></returns>
513514
private EncryptionInfo CreateEncryptionInfo(string password, AlgorithmID algID, out byte[] key)
514515
{

0 commit comments

Comments
 (0)