Converting Excel (Calc) Spreadsheet to Code

A few months ago I needed to convert quite complex (kind of black box) computation from Excel spreadsheet to C code. At first I manually copied expressions from all cells but this was not simple as I had to check cells mentioned in expressions (formulas). It took long time and energy and the code didn’t work properly - results calculated by the spreadsheet differed from my program’s result.

Therefore I decided to save the Excel spreadsheet in ODF format ( Calc) and write a little helper called SpreadsheetToCode. It’s a command-line utility that does the following steps:

  1. Load OpenDocument Spreadsheet file (.ods) because it's basically XML file wrapped in ZIP and therefore super easy to handle
  2. Pick all cells which contain numerical values (inputs, parameters) or expressions with them (formulas)
  3. Print C-like source code with the spreadsheet's functionality expressed in lines of code

Continue reading

Overcoming the Same-Origin Policy in an Iframe

A lot of webmasters use the Access-Control-Allow-Origin header in order not to have their content displayed somewhere else on the web. It is quite understandable as they want to have their intellectual property protected. But sometimes it might be useful to have some website loaded into an iframe although the iframe is quite old-fashioned HTML element.

In order to do so I found interesting service called (which is an open Source clone of similar service called It just grabs content from a website specified in GET parameter and returns it together with HTTP status code as JSON data.

Continue reading

How to Load Native JNI Library from JAR

The JNI (Java Native Interface) is a framework that provides a bridge between Java and native applications. Java applications can define native methods which are implemented in dynamic library written in other languages such as C or C++. The dynamic library is able to call both static and dynamic methods. More information about JNI can be found on Wiki or in tutorial Beginning JNI with NetBeans (for Linux).

The problem is that for loading such a dynamic library you have to call method System.load(String filename) which requires an absolute filename. This approach is just fine if you have dynamic library outside the application’s JAR archive, but when bundling dynamic library within the JAR it is necessary to extract the library into filesystem before loading it. And that’s exactly what my code does.

Continue reading