Skip to content

Commit 3baeade

Browse files
committed
Updated to version 20.10
1 parent a76624b commit 3baeade

File tree

10 files changed

+379
-336
lines changed

10 files changed

+379
-336
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Collections;
6-
7-
namespace Aspose.Cells.Examples.CSharp.Articles.WorkingWithCalculationEngine
8-
{
9-
// ExStart:CustomFunctionStaticValue
10-
public class CustomFunctionStaticValue : ICustomFunction
11-
{
12-
public object CalculateCustomFunction(string functionName, ArrayList paramsList, ArrayList contextObjects)
13-
{
14-
return new object[][] {
15-
new object[]{new DateTime(2015, 6, 12, 10, 6, 30), 2},
16-
new object[]{3.0, "Test"}
17-
};
18-
}
19-
}
20-
// ExEnd:CustomFunctionStaticValue
21-
22-
public class ReturnRangeOfValuesUsingICustomFunction
23-
{
24-
public static void Run()
25-
{
26-
// ExStart:1
27-
// The path to the documents directory.
28-
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
29-
30-
// Create workbook
31-
Workbook wb = new Workbook();
32-
Cells cells = wb.Worksheets[0].Cells;
33-
34-
// Set formula
35-
Cell cell = cells[0, 0];
36-
cell.SetArrayFormula("=MYFUNC()", 2, 2);
37-
38-
Style style = cell.GetStyle();
39-
style.Number = 14;
40-
cell.SetStyle(style);
41-
42-
// Set calculation options for formula
43-
CalculationOptions copt = new CalculationOptions();
44-
copt.CustomFunction = new CustomFunctionStaticValue();
45-
wb.CalculateFormula(copt);
46-
47-
// Save to xlsx by setting the calc mode to manual
48-
wb.Settings.CalcMode = CalcModeType.Manual;
49-
wb.Save(dataDir + "output_out.xlsx");
50-
51-
// Save to pdf
52-
wb.Save(dataDir + "output_out.pdf");
53-
// ExEnd:1
54-
}
55-
}
56-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Collections;
6+
7+
namespace Aspose.Cells.Examples.CSharp.Articles.WorkingWithCalculationEngine
8+
{
9+
// ExStart:CustomFunctionStaticValue
10+
public class CustomFunctionStaticValue : AbstractCalculationEngine
11+
{
12+
public override void Calculate(CalculationData data)
13+
{
14+
data.CalculatedValue = new object[][] {
15+
new object[]{new DateTime(2015, 6, 12, 10, 6, 30), 2},
16+
new object[]{3.0, "Test"}
17+
};
18+
}
19+
}
20+
// ExEnd:CustomFunctionStaticValue
21+
22+
public class ReturnRangeOfValuesUsingAbstractCalculationEngine
23+
{
24+
public static void Run()
25+
{
26+
// ExStart:1
27+
// The path to the documents directory.
28+
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
29+
30+
// Create workbook
31+
Workbook workbook = new Workbook();
32+
Cells cells = workbook.Worksheets[0].Cells;
33+
34+
// Set formula
35+
Cell cell = cells[0, 0];
36+
cell.SetArrayFormula("=MYFUNC()", 2, 2);
37+
38+
Style style = cell.GetStyle();
39+
style.Number = 14;
40+
cell.SetStyle(style);
41+
42+
// Set calculation options for formula
43+
CalculationOptions calculationOptions = new CalculationOptions();
44+
calculationOptions.CustomEngine = new CustomFunctionStaticValue();
45+
workbook.CalculateFormula(calculationOptions);
46+
47+
// Save to xlsx by setting the calc mode to manual
48+
workbook.Settings.CalcMode = CalcModeType.Manual;
49+
workbook.Save(dataDir + "output_out.xlsx");
50+
51+
// Save to pdf
52+
workbook.Save(dataDir + "output_out.pdf");
53+
// ExEnd:1
54+
}
55+
}
56+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System.IO;
2+
3+
using Aspose.Cells;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
using System.Collections;
8+
9+
namespace Aspose.Cells.Examples.CSharp.Articles.WorkingWithCalculationEngine
10+
{
11+
// ExStart:AbstractCalculationEngine
12+
public class CustomFunction : AbstractCalculationEngine
13+
{
14+
public override void Calculate(CalculationData data)
15+
{
16+
decimal total = 0M;
17+
try
18+
{
19+
// Get value of first parameter
20+
object firstParameter = data.GetParamValue(0);
21+
Console.WriteLine(data.GetParamValue(0).GetType());
22+
23+
decimal firstParamB1 = 0;
24+
25+
if (firstParameter is ReferredArea)
26+
{
27+
ReferredArea ra = (ReferredArea)firstParameter;
28+
firstParamB1 = System.Convert.ToDecimal(ra.GetValue(0, 0));
29+
}
30+
31+
// Get value of second parameter
32+
object secondParameter = data.GetParamValue(1);
33+
Console.WriteLine(data.GetParamValue(1).GetType());
34+
35+
if (secondParameter is ReferredArea)
36+
{
37+
ReferredArea ra = (ReferredArea)secondParameter;
38+
39+
// get every item value of second parameter
40+
foreach (object[] value in (Array)ra.GetValues())
41+
{
42+
total += System.Convert.ToDecimal(value[0]);
43+
}
44+
}
45+
46+
total = total / firstParamB1;
47+
}
48+
catch
49+
{
50+
51+
}
52+
53+
// Result of the function
54+
data.CalculatedValue = total;
55+
}
56+
}
57+
// ExEnd:AbstractCalculationEngine
58+
59+
public class UsingAbstractCalculationEnginefeature
60+
{
61+
public static void Run()
62+
{
63+
// ExStart:UsingAbstractCalculationEnginefeature
64+
// The path to the documents directory.
65+
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
66+
67+
// Open the workbook
68+
Workbook workbook = new Workbook();
69+
70+
// Obtaining the reference of the first worksheet
71+
Worksheet worksheet = workbook.Worksheets[0];
72+
73+
// Adding sample values to cells
74+
worksheet.Cells["B1"].PutValue(5);
75+
worksheet.Cells["C1"].PutValue(100);
76+
worksheet.Cells["C2"].PutValue(150);
77+
worksheet.Cells["C3"].PutValue(60);
78+
worksheet.Cells["C4"].PutValue(32);
79+
worksheet.Cells["C5"].PutValue(62);
80+
81+
// Adding custom formula to Cell A1
82+
workbook.Worksheets[0].Cells["A1"].Formula = "=MyFunc(B1,C1:C5)";
83+
84+
// Set calculation options
85+
CalculationOptions calculationOptions = new CalculationOptions();
86+
calculationOptions.CustomEngine = new CustomFunction();
87+
88+
// Calcualting Formulas
89+
workbook.CalculateFormula(calculationOptions);
90+
91+
// Assign resultant value to Cell A1
92+
workbook.Worksheets[0].Cells["A1"].PutValue(workbook.Worksheets[0].Cells["A1"].Value);
93+
94+
// Save the file
95+
workbook.Save(dataDir + "UsingAbstractCalculationEnginefeature_out.xls");
96+
// ExEnd:UsingAbstractCalculationEnginefeature
97+
}
98+
}
99+
}

Examples/CSharp/Articles/WorkingWithCalculationEngine/UsingICustomFunctionfeature.cs

Lines changed: 0 additions & 80 deletions
This file was deleted.

Examples/CSharp/CSharp.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
</PropertyGroup>
3838
<PropertyGroup />
3939
<ItemGroup>
40-
<Reference Include="Aspose.Cells, Version=20.9.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Aspose.Cells.20.9.0\lib\net40\Aspose.Cells.dll</HintPath>
40+
<Reference Include="Aspose.Cells, Version=20.10.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
41+
<HintPath>..\packages\Aspose.Cells.20.10.0\lib\net40\Aspose.Cells.dll</HintPath>
4242
</Reference>
4343
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
4444
<Reference Include="Microsoft.VisualStudio.Tools.Applications.Runtime, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
@@ -300,7 +300,7 @@
300300
<Compile Include="Articles\StylingAndDataFormatting\ExtractThemeData.cs" />
301301
<Compile Include="Articles\WorkingWithCalculationEngine\CalculateIFNAFunction.cs" />
302302
<Compile Include="Articles\WorkingWithCalculationEngine\CalculationOfArrayFormula.cs" />
303-
<Compile Include="Articles\WorkingWithCalculationEngine\ReturnRangeOfValuesUsingICustomFunction.cs" />
303+
<Compile Include="Articles\WorkingWithCalculationEngine\ReturnRangeOfValuesUsingAbstractCalculationEngine.cs" />
304304
<Compile Include="Articles\WorkingWithCalculationEngine\SetExternalLinksInFormulas.cs" />
305305
<Compile Include="Articles\ManageChartsAndShapes\SetPictureBackGroundFillChart.cs" />
306306
<Compile Include="Articles\SetPixelFormatRenderedImage.cs" />
@@ -323,7 +323,7 @@
323323
<Compile Include="Articles\UsePresentationPreferenceOption.cs" />
324324
<Compile Include="Articles\UsingCustomXmlParts.cs" />
325325
<Compile Include="Articles\WorkingWithCalculationEngine\UsingFormulaTextFunction.cs" />
326-
<Compile Include="Articles\WorkingWithCalculationEngine\UsingICustomFunctionfeature.cs" />
326+
<Compile Include="Articles\WorkingWithCalculationEngine\UsingAbstractCalculationEnginefeature.cs" />
327327
<Compile Include="Articles\UsingImageMarkersWhileGroupingDataInSmartMarkers.cs" />
328328
<Compile Include="Articles\UsingLightCellsAPI.cs" />
329329
<Compile Include="Articles\UsingBuiltinStyles.cs" />
@@ -507,6 +507,7 @@
507507
<Compile Include="Files\Handling\OpeningTSVFiles.cs" />
508508
<Compile Include="Files\Handling\OpeningFODSFiles.cs" />
509509
<Compile Include="Files\Handling\OpeningSXCFiles.cs" />
510+
<Compile Include="Files\Utility\VerifyPassword.cs" />
510511
<Compile Include="HTML\PrintHeadings.cs" />
511512
<Compile Include="LoadingSavingConvertingAndManaging\ConvertExcelFileToHtmlWithTooltip.cs" />
512513
<Compile Include="LoadingSavingConvertingAndManaging\ConvertCsvToJson.cs" />

0 commit comments

Comments
 (0)