Quick Start

“Hello World” console application

import com.intechcore.scomponents.scell.api.init.ScellApiEntryPoint;
import com.intechcore.scomponents.scell.api.spreadsheet.IScellCoreApiFactory;
import com.intechcore.scomponents.scell.api.spreadsheet.model.IWorkbook;

import java.io.File;

public class TestApp {
    public static void main(String[] args) {
        ScellApiEntryPoint.getApiResolverAsync().thenAccept(resolver -> {
            IScellCoreApiFactory apiFactory = resolver.resolve(IScellCoreApiFactory.class);
            IWorkbook newWorkbook = apiFactory.createNew();
            IWorkbook existingWorkbook = apiFactory.load(new File("/path/to/existing/file.xlsx"));
            // ...
        }).whenComplete((unused, throwable) -> {
            if (throwable != null) {
                System.out.println(throwable.getMessage());
            }
        }).join();
    }
}

The call ScellApiEntryPoint.getApiResolverAsync() returns the IScellApiResolver implementation which is used to resolve API entry points or register custom implementation of API interfaces.

IScellCoreApiFactory creates the main API object - IWorkbook, by creating a new empty spreadsheet or loading one of the existing ones for further work.

“Hello World” UI Java FX application

import com.intechcore.scomponents.scell.api.fx.IScellUiApi;
import com.intechcore.scomponents.scell.api.fx.IScellUiApiBuilder;
import com.intechcore.scomponents.scell.api.fx.IScellUiFxApiBuilder;
import com.intechcore.scomponents.scell.api.init.ScellApiEntryPoint;
import com.intechcore.scomponents.scell.api.spreadsheet.IScellCoreApiFactory;
import com.intechcore.scomponents.scell.api.spreadsheet.model.IWorkbook;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;


import java.util.concurrent.CompletableFuture;

public class TestAppUi extends Application {
    @Override
    public void start(Stage primaryStage) {
        BorderPane root = new BorderPane(new Label("Initializing ..."));

        ScellApiEntryPoint.getApiResolverAsync().thenApplyAsync(resolver -> {
            IScellCoreApiFactory apiFactory = resolver.resolve(IScellCoreApiFactory.class);
            IWorkbook workbook = apiFactory.createNew();

            IScellUiApiBuilder<Node> uiBuilder = resolver.resolve(IScellUiFxApiBuilder.class);
            IScellUiApi<Node> uiApi = uiBuilder
                    .readOnly(false)
                    .create(workbook);
            return uiApi.getControl();
        }, Platform::runLater).whenCompleteAsync((node, throwable) -> {
            if (throwable != null) {
                node = new Label("Failed to init: " + throwable.getCause().getMessage());
            }
            root.setCenter(node);
        }, Platform::runLater);

        primaryStage.setScene(new Scene(root, 800, 600));
        primaryStage.show();
    }

}

To create the Java FX API entry point you need the implementation of IScellUiApiBuilder<Node> (or its alias IScellUiFxApiBuilder) and CompletableFuture of IWorkbook interface.

Adding content to cells and saving the workbook to file example

import com.intechcore.scomponents.scell.api.init.ScellApiEntryPoint;
import com.intechcore.scomponents.scell.api.spreadsheet.IScellCoreApiFactory;
import com.intechcore.scomponents.scell.api.spreadsheet.model.IWorkbook;
import com.intechcore.scomponents.scell.api.spreadsheet.service.builder.IRangeAddressBuilder;

import java.util.UUID;
import java.util.stream.IntStream;

public class FillExample {
    public static void main(String[] args) {
        ScellApiEntryPoint.getApiResolverAsync().thenAccept(resolver -> {
            IScellCoreApiFactory apiProvider = resolver.resolve(IScellCoreApiFactory.class);

            IWorkbook workbook = apiProvider.createNew();

            IRangeAddressBuilder addressBuilder = resolver.resolve(IRangeAddressBuilder.class);

            workbook.all().findFirst().ifPresent(worksheet -> {
                worksheet.getValueService().parseContent("A2", "Date");
                worksheet.getValueService().parseContent("A3", "Signature");

                IntStream.range(2, 40).forEach(rowNumber -> {
                    int columnNumber = 2;
                    worksheet.getValueService().parseContent(
                            addressBuilder.setTopLeft(rowNumber, columnNumber++).buildCell(),
                            UUID.randomUUID().toString());

                    worksheet.getValueService().parseContent(
                            addressBuilder.setTopLeft(rowNumber, columnNumber).buildCell(),
                            UUID.randomUUID().toString());
                });
            });

            workbook.getWriter().fileName("fillExample.xlsx", true).save();
        }).whenComplete((unused, throwable) -> {
            if (throwable != null) {
                System.out.println(throwable.getMessage());
            }
        }).join();
    }
}

GitHub DEMO Gradle project

Next - Reference/ScellApiEntryPoint