Managing Hyperlinks in Cells

Some Excel sheet may have cells with attached hyperlinks. A hyperlink is not a cell type but an object attached to the cell. A cell can contain one and only one Hyperlink.

Reading a hyperlink

The following extract of code shows how to read hyperlinks in the model.

Directly from the model

import com.sodius.mdw.metamodel.excel.Cell;
import com.sodius.mdw.metamodel.excel.Hyperlink;
import com.sodius.mdw.core.model.Model;
...
Model model = ...
String fileNameFullPath = ...
...
Model model = getWorkbench().getMetamodelManager().getMetamodel("excel").readModel("Excel Workbook", fileNameFullPath);
MDWList<Hyperlink> links = model.getInstances(ExcelPackage.Literals.HYPERLINK);

Directly from the cell

import com.sodius.mdw.metamodel.excel.Cell;
import com.sodius.mdw.metamodel.excel.Hyperlink;
import com.sodius.mdw.core.model.Model;
...
Model model = ...
String fileNameFullPath = ...
...
Model model = getWorkbench().getMetamodelManager().getMetamodel("excel").readModel("Excel Workbook", fileNameFullPath);
MDWList<Cell> cells = model.getInstances(ExcelPackage.Literals.CELL);
for (Cell cell : cells) {
	// A cell may or may not have a hyperlink
	Hyperlink link = cell.getHyperlink();
	if (link != null) {
	    ....
	}
}
...

Creating a hyperlink

import com.sodius.mdw.metamodel.excel.Cell;
import com.sodius.mdw.metamodel.excel.Hyperlink;
import com.sodius.mdw.core.model.Model;
...
Model model = ...
...

Cell cell = model.create(ExcelPackage.Literals.CELL)
cell.setValueString("My Cell Link label");

// Now create the hyperlink attached to the cell
Hyperlink hyperlink = model.create(ExcelPackage.Literals.HYPERLINK);
hyperlink.setAddress("http://www.sodius.com");
hyperlink.setLabel("Sodius Link");
hyperlink.setType(HyperlinkType.URL);
cell.setHyperlink(hyperlink);