Giter Site home page Giter Site logo

pkokki / documentcreator Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 5.45 MB

An opinionated solution for creating documents from JSON objects (API payloads) based on Word templates and Excel formula configuration.

Home Page: https://doc-creator.azurewebsites.net/

License: MIT License

C# 70.02% JavaScript 0.79% TypeScript 14.13% CSS 0.70% HTML 3.90% VBA 10.37% Batchfile 0.10%
expression-evaluator document-generation math-expression-evaluator excel-formula

documentcreator's Introduction

Document Creator

An opinionated solution for creating documents from JSON objects (API payloads) based on Word templates and Excel formula configuration.

.NET Core GitHub tag (latest by date) GitHub commits since latest release (by date including pre-releases) GitHub code size in bytes GitHub issues

Getting Started

Create Word documents and HTML pages by combining Word templates (documents with content controls) and JSON data via transformations defined as Excel formulas.

Transformation examples

Nuget

Given the data

{
    "x1": 10,
    "x2": 2,
    "x3": { "firstname": "john", "surname": "smith" },
    "x4": [100, 200, 300, 400],
    "x5": {
        "y1": "A quick brown fox jumps over the lazy dog",
        "y2": "brown",
        "y3": "#red#",
        "y4": [ 1, 2, 3]
    }
}

we can evaluate the following expressions

expression result (in el-GR culture)
8 / 2 * (2 + 2) 16
x1 * x2 - x1 / x2 15
CONCATENATE(x3.firstname, " ", x3.surname) john smith
SUM(x4) * 24% 240,00
x4 ['100','200','300','400']
PROPER(REPLACE(x5.y1, SEARCH(x5.y2, x5.y1), LEN(x5.y2), x5.y3)) A Quick #Red# Fox Jumps Over The Lazy Dog
IF(x1 + IFNA(missing.path, x2) > 10, ">10", "<=10") >10
DATE(2020, 4, 28) + x5.y4[1] 30/4/2020
IF(__A1 > __A2, UPPER(__A3), "?") JOHN SMITH

See the full list of supported Excel functions. Suggest the implementation of missing functions by opening an issue.

You can test it live here.

Installation

TBD

Built with

API

Web client

Tests

Contributing

Contributions are welcome. Please contact the project maintainer.

Versions

For the versions available, see the tags on this repository.

Authors

  • Panos - Initial work - pkokki

License

This project is licensed under the MIT License - see the LICENSE.TXT file for details

Credits

documentcreator's People

Contributors

dependabot[bot] avatar pkokki avatar

Stargazers

 avatar

Watchers

 avatar

documentcreator's Issues

enhance excel mapping file

P13="INFORMATION"
P14=Agent --- emptymappings version
P15=TemplateName
P16=MappingName

  • Remove columns A (Id) and H (Id), hidden E and I(TargetId)
  • Add column "Formula" after Transformation(J) and formula "=FORMULATEXT(RC[-1])"

support output formatting in mapping worksheet

subtotal + tax = total

quantity = 1/3
price = 1,3
subtotal = quantity * price, but also need TEXT(F5, "0,00") or read formatting from excel cell or equivalent
tax = subtotal * 10%
total = subtotal + tax

add MacroOptions to user-defined functions

See

Public Functon MyUserDefinedFunction(ByVal sText As String) As String 
End Function 

Public Sub DefineFunction 
   Dim sFunctionName As String 
   Dim sFunctionCategory As String 
   Dim sFunctionDescription As String 
   Dim aFunctionArguments(1 To 2) As String 

   sFunctionName = "MyUserDefinedFunction" 
   sFunctionDescription = "This is my new user defined function" 
   sFunctionCategory = 7 ' Text category  
   aFunctionArguments(1) = "String to contain the name" 
   aFunctionArguments(2) = "Long to contain the value" 

   Application.MacroOptions Macro:=sFunctionName, _ 
         Description:=sFunctionDescription, _ 
         Category:=sFunctionCategory, _ 
         ArgumentDescriptions:=aFunctionArguments 
End Sub 

support activation/expiration

Toggle:
POST /templates/{name}/active
POST /templates/{name}/versions/{id}/active
POST /mappings/{name}/active
POST /mappings/{name}/versions/{id}/active

PUT { activation?: futureDate, expiration?: futureDate }

provide sources (optionally) during mappings creation

GET /templates/{{templateName}}/mappings/{{mappingName}} should return mappings data

add POST /templates/{{templateName}}/mappings/{{mappingName}} to define sources

{
  sources: [{name:'RQ', value:{json object}}]
}

support forward cell references in evaluation

var expressions = new List<TemplateFieldExpression>
{
    new TemplateFieldExpression() { Name = "F02", Cell = "J14", Expression = "=1" },
    new TemplateFieldExpression() { Name = "F03", Cell = "J15", Expression = "=J14+J16" },
    new TemplateFieldExpression() { Name = "F04", Cell = "J16", Expression = "=2" },
};
Assert.Equal("3", expressions[1].Result.Value);

fix order of repeating section items to match order of payload items

Payload:

"InterestTable": [
  {"Period": 1,"Interest": 0.2,"Points": 500},
  {"Period": 3,"Interest": 0.25,"Points": 1000},
  {"Period": 5,"Interest": 1.25,"Points": 2000}
]

Word:

Περίοδος | Επιτόκιο | Πόντοι
1 | 0,2 | 500
5 | 1,25 | 2000
3 | 0,25 | 1000

change payload schema for test mappings route

POST templates/{name}/mappings/{name}/test

{
  "templateName":"",
  "sources": [{ "name": "", "payload": {} }],
  "expressions": [{ "name": "", "cell": "", "expression": "", "parent": "", "isCollection": true }]
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.