Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/JanKallman/EPPlus
Browse files Browse the repository at this point in the history
  • Loading branch information
EPPlus committed Aug 19, 2018
2 parents 842ccb4 + 642e73b commit daf907d
Show file tree
Hide file tree
Showing 29 changed files with 583 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ obj/
Ankh.NoLoad
*.[Pp]ublish.xml
.vs/
.nuget/nuget.exe

#Tooling
_ReSharper*/
Expand Down
6 changes: 6 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
151 changes: 151 additions & 0 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>

<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>
</PropertyGroup>

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
<PackagesConfig>packages.config</PackagesConfig>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>

<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT" />
</Target>

<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />

<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>

<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<EnvKey ParameterType="System.String" Required="true" />
<EnvValue ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
}
catch {
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
5 changes: 2 additions & 3 deletions EPPlus/Drawing/ExcelDrawings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ private void AddDrawings()
ExcelDrawing dr;
switch(node.LocalName)
{
case "oneCellAnchor":
//dr = new ExcelDrawing(this, node, "xdr:sp/xdr:nvSpPr/xdr:cNvPr/@name");
dr = ExcelDrawing.GetDrawing(this, node); //Issue 15373
case "oneCellAnchor":
dr = ExcelDrawing.GetDrawing(this, node);
break;
case "twoCellAnchor":
dr = ExcelDrawing.GetDrawing(this, node);
Expand Down
1 change: 1 addition & 0 deletions EPPlus/EPPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@
<Compile Include="FormulaParsing\Excel\Functions\ErrorHandlingFunction.cs" />
<Compile Include="FormulaParsing\Excel\Functions\ExcelDoubleCellValue.cs" />
<Compile Include="FormulaParsing\Excel\Functions\ExcelFunction.cs" />
<Compile Include="FormulaParsing\Excel\Functions\Finance\Pmt.cs" />
<Compile Include="FormulaParsing\Excel\Functions\FunctionArgument.cs" />
<Compile Include="FormulaParsing\Excel\Functions\FunctionRepository.cs" />
<Compile Include="FormulaParsing\Excel\Functions\FunctionsModule.cs" />
Expand Down
57 changes: 29 additions & 28 deletions EPPlus/ExcelCellBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,34 +758,35 @@ public static string GetFullAddress(string worksheetName, string address)
}
internal static string GetFullAddress(string worksheetName, string address, bool fullRowCol)
{
if (address.IndexOf("!") == -1 || address=="#REF!")
{
if (fullRowCol)
{
string[] cells = address.Split(':');
if (cells.Length > 0)
{
address = string.Format("'{0}'!{1}", worksheetName, cells[0]);
if (cells.Length > 1)
{
address += string.Format(":{0}", cells[1]);
}
}
}
else
{
var a = new ExcelAddressBase(address);
if ((a._fromRow == 1 && a._toRow == ExcelPackage.MaxRows) || (a._fromCol == 1 && a._toCol == ExcelPackage.MaxColumns))
{
address = string.Format("'{0}'!{1}{2}:{3}{4}", worksheetName, ExcelAddress.GetColumnLetter(a._fromCol), a._fromRow, ExcelAddress.GetColumnLetter(a._toCol), a._toRow);
}
else
{
address=GetFullAddress(worksheetName, address, true);
}
}
}
return address;
if(!string.IsNullOrEmpty(worksheetName)) worksheetName = worksheetName.Replace("'", "''"); //Makesure addresses handle single qoutes
if (address.IndexOf("!") == -1 || address=="#REF!")
{
if (fullRowCol)
{
string[] cells = address.Split(':');
if (cells.Length > 0)
{
address = string.Format("'{0}'!{1}", worksheetName, cells[0]);
if (cells.Length > 1)
{
address += string.Format(":{0}", cells[1]);
}
}
}
else
{
var a = new ExcelAddressBase(address);
if ((a._fromRow == 1 && a._toRow == ExcelPackage.MaxRows) || (a._fromCol == 1 && a._toCol == ExcelPackage.MaxColumns))
{
address = string.Format("'{0}'!{1}{2}:{3}{4}", worksheetName, ExcelAddress.GetColumnLetter(a._fromCol), a._fromRow, ExcelAddress.GetColumnLetter(a._toCol), a._toRow);
}
else
{
address=GetFullAddress(worksheetName, address, true);
}
}
}
return address;
}
#endregion
#region IsValidCellAddress
Expand Down
1 change: 0 additions & 1 deletion EPPlus/ExcelNamedRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,5 @@ public override string ToString()
{
return Name;
}

}
}
5 changes: 5 additions & 0 deletions EPPlus/ExcelNamedRangeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using System.Text;
using System.Collections;
using System.Linq;
using OfficeOpenXml.FormulaParsing.ExcelUtilities;

namespace OfficeOpenXml
{
Expand Down Expand Up @@ -65,6 +66,10 @@ internal ExcelNamedRangeCollection(ExcelWorkbook wb, ExcelWorksheet ws)
public ExcelNamedRange Add(string Name, ExcelRangeBase Range)
{
ExcelNamedRange item;
if(!ExcelAddressUtil.IsValidName(Name))
{
throw (new ArgumentException("Name contains invalid characters"));
}
if (Range.IsName)
{

Expand Down
66 changes: 27 additions & 39 deletions EPPlus/ExcelRangeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2084,49 +2084,37 @@ public ExcelRangeBase LoadFromCollection<T>(IEnumerable<T> Collection, bool Prin
return null;
}

//if (Members.Length == 0)
//{
// foreach (var item in Collection)
// {
// //_worksheet.Cells[row++, col].Value = item;
// values[row, col++] = item;
// }
//}
//else
//{
foreach (var item in Collection)
{
col = 0;
if (item is string || item is decimal || item is DateTime || TypeCompat.IsPrimitive(item))
{
//_worksheet.Cells[row, col++].Value = item;
values[row, col++] = item;
}
else
foreach (var item in Collection)
{
col = 0;
if (item is string || item is decimal || item is DateTime || TypeCompat.IsPrimitive(item))
{
values[row, col++] = item;
}
else
{
foreach (var t in Members)
{
foreach (var t in Members)
if (isSameType == false && item.GetType().GetMember(t.Name, memberFlags).Length == 0)
{
if (isSameType == false && item.GetType().GetMember(t.Name, memberFlags).Length == 0)
{
col++;
continue; //Check if the property exists if and inherited class is used
}
else if (t is PropertyInfo)
{
values[row, col++] = ((PropertyInfo)t).GetValue(item, null);
}
else if (t is FieldInfo)
{
values[row, col++] = ((FieldInfo)t).GetValue(item);
}
else if (t is MethodInfo)
{
values[row, col++] = ((MethodInfo)t).Invoke(item, null);
}
col++;
continue; //Check if the property exists if and inherited class is used
}
else if (t is PropertyInfo)
{
values[row, col++] = ((PropertyInfo)t).GetValue(item, null);
}
else if (t is FieldInfo)
{
values[row, col++] = ((FieldInfo)t).GetValue(item);
}
else if (t is MethodInfo)
{
values[row, col++] = ((MethodInfo)t).Invoke(item, null);
}
}
row++;
//}
}
row++;
}

_worksheet.SetRangeValueInner(_fromRow, _fromCol, _fromRow + row - 1, _fromCol + col - 1, values);
Expand Down
10 changes: 6 additions & 4 deletions EPPlus/ExcelWorksheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public struct ExcelCoreValue
public class ExcelChartsheet : ExcelWorksheet
{
//ExcelDrawings draws;
public ExcelChartsheet(XmlNamespaceManager ns, ExcelPackage pck, string relID, Uri uriWorksheet, string sheetName, int sheetID, int positionID, eWorkSheetHidden hidden, eChartType chartType) :
public ExcelChartsheet(XmlNamespaceManager ns, ExcelPackage pck, string relID, Uri uriWorksheet, string sheetName, int sheetID, int positionID, eWorkSheetHidden hidden, eChartType chartType, ExcelPivotTable pivotTableSource ) :
base(ns, pck, relID, uriWorksheet, sheetName, sheetID, positionID, hidden)
{
this.Drawings.AddChart("Chart 1", chartType);
this.Drawings.AddChart("Chart 1", chartType, pivotTableSource);
}
public ExcelChartsheet(XmlNamespaceManager ns, ExcelPackage pck, string relID, Uri uriWorksheet, string sheetName, int sheetID, int positionID, eWorkSheetHidden hidden) :
base(ns, pck, relID, uriWorksheet, sheetName, sheetID, positionID, hidden)
Expand Down Expand Up @@ -3104,7 +3104,8 @@ private void SaveComments()
{
if (_comments.Uri == null)
{
_comments.Uri=new Uri(string.Format(@"/xl/comments{0}.xml", SheetID), UriKind.Relative);
var id = SheetID;
_comments.Uri = XmlHelper.GetNewUri(_package.Package, @"/xl/comments{0}.xml", ref id); //Issue 236-Part already exists fix
}
if(_comments.Part==null)
{
Expand All @@ -3129,7 +3130,8 @@ private void SaveComments()
{
if (_vmlDrawings.Uri == null)
{
_vmlDrawings.Uri = XmlHelper.GetNewUri(_package.Package, @"/xl/drawings/vmlDrawing{0}.vml");
var id = SheetID;
_vmlDrawings.Uri = XmlHelper.GetNewUri(_package.Package, @"/xl/drawings/vmlDrawing{0}.vml", ref id);
}
if (_vmlDrawings.Part == null)
{
Expand Down
Loading

0 comments on commit daf907d

Please sign in to comment.