com.dataart.spreadsheetanalytics.demo.main.DependencyGraphDemo.java Source code

Java tutorial

Introduction

Here is the source code for com.dataart.spreadsheetanalytics.demo.main.DependencyGraphDemo.java

Source

/*
Copyright 2015 DataArt Apps, Inc
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.dataart.spreadsheetanalytics.demo.main;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.dataart.spreadsheetanalytics.api.engine.IAuditor;
import com.dataart.spreadsheetanalytics.api.model.ICellAddress;
import com.dataart.spreadsheetanalytics.api.model.IDataModel;
import com.dataart.spreadsheetanalytics.api.model.IExecutionGraph;
import com.dataart.spreadsheetanalytics.demo.util.DemoUtil;
import com.dataart.spreadsheetanalytics.engine.Converters;
import com.dataart.spreadsheetanalytics.engine.SpreadsheetAuditor;
import com.dataart.spreadsheetanalytics.model.A1Address;
import com.dataart.spreadsheetanalytics.model.CellAddress;

public class DependencyGraphDemo {

    public static void main(String[] args) throws Exception {

        //input arguments: filename and list of cells to evaluate
        if (args.length < 2) {
            System.err.println("Excel file path and Cell Address, please!");
            return;
        }

        final String excel = args[0];
        final String graphCell = args[1];

        //prepare DataModel to work with
        final IDataModel model = Converters.toDataModel(new XSSFWorkbook(excel));

        final ICellAddress addr = new CellAddress(model.getDataModelId(), A1Address.fromA1Address(graphCell));

        final IAuditor auditor = new SpreadsheetAuditor(model);
        final IExecutionGraph graph = auditor.buildDependencyGraph(addr.a1Address());

        //print graph
        DemoUtil.generateVisJsData(graph);
        DemoUtil.plainprint(graph);
    }

}