Git Product home page Git Product logo

jmarxuach / json2xlsm Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 2.0 54 KB

Command line tool for update data into xlsm first sheet of a macro excel file. Usefull from PHP, Python or any language that doesn't have Excel Macro library that keeps visual basic and macro code after updating xlsm data.

License: GNU General Public License v3.0

Java 100.00%
cli java excel xslm macro phpexcel python openpyxl phpspreadsheet

json2xlsm's Introduction

json2xlsm

Command line tool to update data into xlsm first sheet of a macro excel file. Usefull from PHP, or any language that doesn't have Excel Macro library that keeps visual basic and macro code after updating xlsm data.

Usage

Usually you create a xlsm with your macros in Vb and you do not need to edit macros, but you need to replace sheet data in XLSM files.

java -jar json2xlsm.jar <strFileJSON> <strMacroExcelFileIn> <strMacroExcelFileOut>

Where :

  • strFileJSON : Is the data to insert into the first excel sheet.
  • strMacroExcelFileIn : Is your report template with macros in and the first sheet empty.
  • strMacroExcelFileOut : Is the resulting excel file with json data in the first sheet and your vb code intact. I you have an Workbook_Open report will generate on open excel.

Creating JSON file from Python and executing json2xlsm

import json
import os

data = [
{'field1': 'Value', 'field2': 'Value', 'field3': 'Value'},
{'field1': 'Value', 'field2': 'Value', 'field3': 'Value'},
{'field1': 'Value', 'field2': 'Value', 'field3': 'Value'},
]

with open('jsonFilename.json', 'w') as fout:
    json.dump(data , fout)

os.system('java -jar json2xlsm.jar jsonFilename.json MacroExcelTemplateFile.xlsm MacroExcelFileOut.xlsm')

Creating JSON file from PHP and executing json2xlsm

All values must be in UTF8.

$array = array(
    0 => array("field1" => "Value", "field2" => "Value"),
    1 => array("field1" => "Value", "field2" => "Value"),
    2 => array("field1" => "Value", "field2" => "Value"),
);

$jsonString = json_encode($array);

file_put_contents("jsonFilename.json", $jsonString);

shell_exec("java -jar json2xlsm.jar jsonFilename.json MacroExcelTemplateFile.xlsm MacroExcelFileOut.xlsm");

json2xlsm's People

Contributors

dependabot[bot] avatar jmarxuach avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

crawc zouzhy

json2xlsm's Issues

The xlsm it appears it doesn't have the support mark

Hi! your tool looks very interesting for me..
When I compile this I get this error message:

java -jar json2xlsm.jar arr1x.json sample.xlsm salida.xlsm
java.io.IOException: getFileMagic() only operates on streams which support mark(int)
at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:131)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.hasPOIFSHeader(NPOIFSFileSystem.java:370)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:69)
at json2xlsm.lib.json2xlsm.json2excel(json2xlsm.java:109)
at json2xlsm.lib.json2xlsm.ExecuteExport(json2xlsm.java:65)
at json2xlsm.cli.Main.main(Main.java:31)

When I do it with a pre-compiled version I found, it works great...
I want to make a few changes, since I need this tool to add a new worksheet (insert a new one), and I may try to change it a little bit.. For my solution I need to add several workseets..

But I can't get it to compile right since in my compiled version I get that error..

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.