Skip to content

Commit

Permalink
Templater v4.3.0
Browse files Browse the repository at this point in the history
Example of Excel row/column/sheet hiding
  • Loading branch information
zapov committed Feb 4, 2020
1 parent 71d1c08 commit 6c5d035
Show file tree
Hide file tree
Showing 157 changed files with 309 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/CsvStreaming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.4.3.0\lib\Net40\NGS.Templater.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.13.0" targetFramework="net40-Client" />
<package id="Templater" version="4.2.0" targetFramework="net40-Client" />
<package id="Templater" version="4.3.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>csv-streaming-example</artifactId>
<packaging>jar</packaging>
<version>4.2.0</version>
<version>4.3.0</version>
<name>CSV streaming</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/DepartmentReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.4.3.0\lib\Net40\NGS.Templater.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.2.0" targetFramework="net40-Client" />
<package id="Templater" version="4.3.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>department-report-example</artifactId>
<packaging>jar</packaging>
<version>4.2.0</version>
<version>4.3.0</version>
<name>DepartmentReportExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/DoubleProcessing/DoubleProcessing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.4.3.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
7 changes: 7 additions & 0 deletions Advanced/DoubleProcessing/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Horizontal resize will duplicate content to the right, as opposed to the bottom.

Often after horizontal resize document needs to be reanalyzed to help Templater copy with changes.

If 0 is used during horizontal resize and affected region include whole column, Templater will perform pull to the left by hiding the relevant columns.
Whole column can be defined in multiple ways:

* by using named range which spans the whole column
* via builtin **whole-column** metadata
* when tags which are getting resized are located on both starting and ending row

### Formula rewriting

Templater will analyze and rewrite formula definitions. This allows for creating very generic templates which when expanded fit into place.
Expand Down
2 changes: 1 addition & 1 deletion Advanced/DoubleProcessing/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.2.0" targetFramework="net40-Client" />
<package id="Templater" version="4.3.0" targetFramework="net40-Client" />
</packages>
7 changes: 6 additions & 1 deletion Advanced/DoubleProcessing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>double-processing-example</artifactId>
<packaging>jar</packaging>
<version>4.2.0</version>
<version>4.3.0</version>
<name>DoubleProcessingExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand All @@ -18,6 +18,11 @@
<artifactId>templater</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.mockrunner</groupId>
<artifactId>mockrunner-jdbc</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>

<build>
Expand Down
Binary file modified Advanced/DoubleProcessing/result.xlsx
Binary file not shown.
45 changes: 45 additions & 0 deletions Advanced/DoubleProcessing/src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -22,12 +23,32 @@ public static void Main(string[] args)
for (int i = 0; i < person.Length; i++)
person[i] = new Person(rnd, i);

var units = PrepareStarcraftUnits();

//let's do a horizontal resize so document is prepared for second pass
using (var doc = Configuration.Factory.Open(ms, "xlsx"))
{
//[[equals]] at the beginning of the cell causes conversion to formula
//this is processed at the end of processing, but since this tag is newly introduced, it's processed at the second pass
doc.Process(new { Person = person, formula = "[[equals]]" });
//remove columns which do not exist in the data table
var columns = new HashSet<string>(units.Columns.Cast<DataColumn>().Select(it => it.ColumnName));
var tags = doc.Templater.Tags.ToList();
foreach (var t in tags)
{
if (!t.StartsWith("starcraft.")) continue;
var metadata = doc.Templater.GetMetadata(t, false).ToList();
if (!metadata.Contains("horizontal-resize")) continue;//we are interested only in specific columns
var colName = t.Substring("starcraft.".Length);
if (columns.Contains(colName))
{
metadata.Remove("horizontal-resize");//keep all metadata except horizontal resize
var appendMetadata = metadata.Count == 0 ? string.Empty : ":" + string.Join(":", metadata);
doc.Templater.Replace(t, "[[" + t + "]" + appendMetadata + "]");//strip horizontal resize attribute
}
else
doc.Templater.Resize(new string[] { t }, 0);//hide column from output
}
}
File.WriteAllBytes("DoubleProcessing.xlsx", ms.ToArray());
ms.Position = 0;
Expand All @@ -37,7 +58,10 @@ public static void Main(string[] args)

//let's do a second pass with our prepared object
using (var doc = Configuration.Factory.Open(ms, "xlsx"))
{
doc.Process(complex);
doc.Process(new { starcraft = units });
}

File.WriteAllBytes("DoubleProcessing.xlsx", ms.ToArray());

Expand Down Expand Up @@ -126,5 +150,26 @@ static Dictionary<string, object> BuildComplexObject(int people)
}
return result;
}

static DataTable PrepareStarcraftUnits()
{
var dt = new DataTable();
dt.Columns.Add("unit", typeof(string));
dt.Columns.Add("size", typeof(string));
//version not included so it's removed from the output
dt.Columns.Add("minerals", typeof(int));
dt.Columns.Add("gas", typeof(int));
dt.Columns.Add("ground attack", typeof(int));
dt.Columns.Add("air attack", typeof(int));
//range not included so it's removed from the output
dt.Columns.Add("build time", typeof(int));
dt.Rows.Add("Battlecruiser", "L", 400, 300, 25, 25, 160);
dt.Rows.Add("Dropship", "L", 100, 100, 0, 0, 50);
dt.Rows.Add("Firebat", "S", 50, 25, 16, 0, 24);
dt.Rows.Add("Ghost", "S", 25, 75, 10, 10, 50);
dt.Rows.Add("Marine", "S", 50, 0, 6, 6, 24);
dt.Rows.Add("Vulture", "M", 75, 0, 20, 0, 30);
return dt;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package hr.ngs.templater.example;

import com.mockrunner.mock.jdbc.MockResultSet;
import hr.ngs.templater.Configuration;
import hr.ngs.templater.IDocumentFactory;
import hr.ngs.templater.ITemplateDocument;

import java.awt.Desktop;
import java.io.*;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.DateFormat;
import java.util.*;

Expand All @@ -22,13 +25,34 @@ public static void main(final String[] args) throws Exception {
for (int i = 0; i < person.length; i++)
person[i] = new Person(rnd, i);

ResultSet units = prepareStarcraftUnits();

IDocumentFactory factory = Configuration.factory();
ByteArrayOutputStream os = new ByteArrayOutputStream();
//let's do a horizontal resize so document is prepared for second pass
ITemplateDocument doc1 = factory.open(templateStream, "xlsx", os);
//[[equals]] at the beginning of the cell causes conversion to formula
//this is processed at the end of processing, but since this tag is newly introduced, it's processed at the second pass
doc1.process(new HashMap<String, Object>() {{ put("Person", person); put("formula", "[[equals]]"); }});
Set<String> columns = new HashSet<>();
ResultSetMetaData rsMD = units.getMetaData();
for (int i = 1; i <= rsMD.getColumnCount(); i++) {
columns.add(rsMD.getColumnName(i));
}
String[] tags = doc1.templater().tags();
for (String t : tags) {
if (!t.startsWith("starcraft.")) continue;
List<String> metadata = new ArrayList<>(Arrays.asList(doc1.templater().getMetadata(t, false)));
if (!metadata.contains("horizontal-resize")) continue;//we are interested only in specific columns
String colName = t.substring("starcraft.".length());
if (columns.contains(colName)) {
metadata.remove("horizontal-resize");
String appendMetadata = metadata.size() == 0 ? "" : ":" + String.join(":", metadata);
doc1.templater().replace(t, "[[" + t + "]" + appendMetadata + "]");//strip horizontal resize attribute
} else {
doc1.templater().resize(new String[] { t }, 0);//hide column from output
}
}
doc1.flush();

//now let's prepare our complex object for standard processing
Expand All @@ -39,6 +63,7 @@ public static void main(final String[] args) throws Exception {
//let's do a second pass with our prepared object
ITemplateDocument doc2 = factory.open(is, "xlsx", fos);
doc2.process(complex);
doc2.process(new HashMap<String, Object>() {{ put("starcraft", units); }});
doc2.flush();
fos.close();

Expand Down Expand Up @@ -128,4 +153,24 @@ static Map<String, Object> buildComplexObject(int people) {
}
return result;
}

static ResultSet prepareStarcraftUnits() {
MockResultSet dt = new MockResultSet("Starcraft");
dt.addColumn("unit");
dt.addColumn("size");
//version not included so it's removed from the output
dt.addColumn("minerals");
dt.addColumn("gas");
dt.addColumn("ground attack");
dt.addColumn("air attack");
//range not included so it's removed from the output
dt.addColumn("build time");
dt.addRow(Arrays.asList("Battlecruiser", "L", 400, 300, 25, 25, 160));
dt.addRow(Arrays.asList("Dropship", "L", 100, 100, 0, 0, 50));
dt.addRow(Arrays.asList("Firebat", "S", 50, 25, 16, 0, 24));
dt.addRow(Arrays.asList("Ghost", "S", 25, 75, 10, 10, 50));
dt.addRow(Arrays.asList("Marine", "S", 50, 0, 6, 6, 24));
dt.addRow(Arrays.asList("Vulture", "M", 75, 0, 20, 0, 30));
return dt;
}
}
Binary file modified Advanced/DoubleProcessing/template/ResizeWithNesting.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/PowerQuery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.4.3.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.2.0" targetFramework="net40-Client" />
<package id="Templater" version="4.3.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>power-query-example</artifactId>
<packaging>jar</packaging>
<version>4.2.0</version>
<version>4.3.0</version>
<name>PowerQueryExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/SalesOrderMVP (.NET)/SalesOrderMVP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.4.3.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/SalesOrderMVP (.NET)/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Fluent.Ribbon" version="3.6.1.236" targetFramework="net40-Client" />
<package id="Templater" version="4.2.0" targetFramework="net40-Client" />
<package id="Templater" version="4.3.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/SheetReport/SheetReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.2.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.4.3.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/SheetReport/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SharpZipLib" version="0.86.0" targetFramework="net40-Client" />
<package id="Templater" version="4.2.0" targetFramework="net40-Client" />
<package id="Templater" version="4.3.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/SheetReport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>sheet-report-example</artifactId>
<packaging>jar</packaging>
<version>4.2.0</version>
<version>4.3.0</version>
<name>SheetReportExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/TemplaterServer/TemplaterServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Templater" Version="4.2.0" />
<PackageReference Include="Templater" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 7 additions & 2 deletions Advanced/TemplaterServer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>templater-server</artifactId>
<packaging>jar</packaging>
<version>4.2.0</version>
<version>4.3.0</version>
<name>TemplaterServer</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>com.dslplatform</groupId>
<artifactId>dsl-json</artifactId>
<version>1.9.3</version>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>e-iceblue</groupId>
Expand All @@ -45,6 +45,11 @@
<version>19.12</version>
<classifier>jdk17</classifier>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"objectGroup": "Range test scorecard",
"description": "Test description",
"groups": [
{
"name": "Group 0",
"clauses": []
},
{
"name": "Group 1",
"clauses": [
Expand Down
Loading

0 comments on commit 6c5d035

Please sign in to comment.