Note: This code is intended to merge the tables from Comparison of remote desktop software - Wikipedia. I’ve deleted some fields I don’t care about.
'use strict';
// jshint esversion: 8
importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.sheet.XSpreadsheetDocument);
importClass(Packages.com.sun.star.container.XNameAccess);
importClass(Packages.com.sun.star.table.XCellRange);
importClass(Packages.com.sun.star.table.XCell);
importClass(Packages.com.sun.star.table.CellContentType);
importClass(Packages.com.sun.star.text.XTextRange)
//get the document object from the scripting context
var oDoc = XSCRIPTCONTEXT.getDocument();
//get the XSpreadsheetDocument interface from the document
var xSDoc = UnoRuntime.queryInterface(XSpreadsheetDocument, oDoc);
//get the XIndexAccess interface used to access each sheet
var xSheetsNameAccess = UnoRuntime.queryInterface(XNameAccess, xSDoc.getSheets());
var cellrangeBasic = UnoRuntime.queryInterface(XCellRange, xSheetsNameAccess.getByName("Basic"));
var cellrangeOS = UnoRuntime.queryInterface(XCellRange, xSheetsNameAccess.getByName("OS_Support"));
var cellrangeFeatures = UnoRuntime.queryInterface(XCellRange, xSheetsNameAccess.getByName("Features"));
var cellrangeResults = UnoRuntime.queryInterface(XCellRange, xSheetsNameAccess.getByName("Results"));
var cellrangeRejects = UnoRuntime.queryInterface(XCellRange, xSheetsNameAccess.getByName("Rejects"));
var cellrangeIncomplete = UnoRuntime.queryInterface(XCellRange, xSheetsNameAccess.getByName("Incomplete"));
function findProductLine(strNameToFind, cellrangeToUse)
{
var iCurRow = 1;
var strProductNameInCurRow = getCellAutoValByPos(cellrangeToUse, 0, iCurRow);
while(strProductNameInCurRow != null && strProductNameInCurRow != strNameToFind)
{
iCurRow++;
strProductNameInCurRow = getCellAutoValByPos(cellrangeToUse, 0, iCurRow);
}
return strProductNameInCurRow == null ? -1 : iCurRow;
}
function getCellByPos(cellrangeToUse, iCol, iRow)
{
return UnoRuntime.queryInterface(XCell, cellrangeToUse.getCellByPosition(iCol, iRow));
}
function getCellAutoValByPos(cellrangeToUse, iCol, iRow)
{
var cell = getCellByPos(cellrangeToUse, iCol, iRow);
switch(cell.getType())
{
case CellContentType.EMPTY:
return null;
case CellContentType.VALUE:
case CellContentType.FORMULA:
return cell.getValue();
case CellContentType.TEXT:
default:
return cell.getFormula();
}
}
function getCellBoolValByPos(cellrangeToUse, iCol, iRow)
{
var strValFound = getCellAutoValByPos(cellrangeToUse, iCol, iRow).toLowerCase();
if(strValFound == "?")
return undefined;
if(strValFound.includes("partial"))
return "Partial";
if(strValFound.includes("yes"))
return true;
return false;
}
function getCellNumValByPos(cellrangeToUse, iCol, iRow)
{
var strValFound = getCellAutoValByPos(cellrangeToUse, iCol, iRow).toLowerCase();
if(strValFound == "?")
return undefined;
var numResult = parseFloat(strValFound);
return numResult == NaN ? undefined : numResult;
}
function Product(strName)
{
this.strName = strName;
var iBasicRow = findProductLine(strName, cellrangeBasic);
var iOsSupportRow = findProductLine(strName, cellrangeOS);
var iFeatureRow = findProductLine(strName, cellrangeFeatures);
if(iBasicRow > -1)
{
this.strProtocols = getCellAutoValByPos(cellrangeBasic, 1, iBasicRow);
this.strCreator = getCellAutoValByPos(cellrangeBasic, 2, iBasicRow);
this.strFirstPublicReleaseDate = getCellAutoValByPos(cellrangeBasic, 2, iBasicRow);
this.strLatestStableRelease = getCellAutoValByPos(cellrangeBasic, 3, iBasicRow);
this.strLicense = getCellAutoValByPos(cellrangeBasic, 4, iBasicRow);
this.bFree = getCellBoolValByPos(cellrangeBasic, 5, iBasicRow);
}
if(iOsSupportRow > -1)
{
this.bHasServer = getCellBoolValByPos(cellrangeOS, 1, iOsSupportRow);
this.bHasClient = getCellBoolValByPos(cellrangeOS, 2, iOsSupportRow);
}
if(iFeatureRow > -1)
{
this.strListening = getCellAutoValByPos(cellrangeFeatures, 1, iFeatureRow);
this.builtInEncryptionOpt = getCellAutoValByPos(cellrangeFeatures, 2, iFeatureRow);
this.bFivarransferSupported = getCellBoolValByPos(cellrangeFeatures, 3, iFeatureRow);
this.bAudioSupport = getCellBoolValByPos(cellrangeFeatures, 4, iFeatureRow);
this.bMultiSession = getCellBoolValByPos(cellrangeFeatures, 5, iFeatureRow);
this.bSeamlessWnds = getCellBoolValByPos(cellrangeFeatures, 6, iFeatureRow);
this.bRemoteAssist = getCellBoolValByPos(cellrangeFeatures, 7, iFeatureRow);
this.bIPV6 = getCellBoolValByPos(cellrangeFeatures, 8, iFeatureRow);
this.bDragDrop = getCellBoolValByPos(cellrangeFeatures, 9, iFeatureRow);
this.bUsbForwarding = getCellBoolValByPos(cellrangeFeatures, 10, iFeatureRow);
this.bH264 = getCellBoolValByPos(cellrangeFeatures, 11, iFeatureRow);
this.bBrowserSupport = getCellBoolValByPos(cellrangeFeatures, 12, iFeatureRow);
this.bSessionPersists = getCellBoolValByPos(cellrangeFeatures, 13, iFeatureRow);
}
this.bFoundBasicInfo = iBasicRow > -1;
this.bFoundOsSupportInfo = iOsSupportRow > -1;
this.bFoundFeatureInfo = iFeatureRow > -1;
}
var listAllProductNamesFound = [];
function addAllKnownProductsInCellRange(cellrangeToUse)
{
var iCurRow = 1;
var strProductNameInCurRow = getCellAutoValByPos(cellrangeToUse, 0, iCurRow);
while(strProductNameInCurRow != null)
{
iCurRow++;
strProductNameInCurRow = getCellAutoValByPos(cellrangeToUse, 0, iCurRow);
listAllProductNamesFound.push(strProductNameInCurRow);
}
}
addAllKnownProductsInCellRange(cellrangeBasic);
addAllKnownProductsInCellRange(cellrangeOS);
addAllKnownProductsInCellRange(cellrangeFeatures);
var listAllProductDetailsFound = [];
for(var iCurProductIndex = 0; iCurProductIndex < listAllProductNamesFound.length; iCurProductIndex++)
{
listAllProductDetailsFound.push(new Product(listAllProductNamesFound[iCurProductIndex]));
}
var iCurResultRow = 1;
var iCurRejectRow = 1;
var iCurIncompleteRow = 1;
function setCellVal(cellrangeDataDest, iCol, iRow, val)
{
var cell = UnoRuntime.queryInterface(XCell, cellrangeDataDest.getCellByPosition(iCol, iRow));
if(val == null)
return;
if(val == undefined)
cell.setFormula("Unknown");
else
switch(typeof(val))
{
case "number":
cell.setValue(val);
break;
case "string":
UnoRuntime.QueryInterface(XTextRange, cell).setString(val);
break;
case "boolean":
cell.setFormula("=" + val.toString().toUpperCase() + "()");
break;
}
}
for(var iCurProductIndex = 0; iCurProductIndex < listAllProductDetailsFound.length; iCurProductIndex++)
{
var productCur = listAllProductDetailsFound[iCurProductIndex];
var cellrangeDataDest = cellrangeResults;
if(!productCur.bFoundBasicInfo || !productCur.bFoundOsSupportInfo || !productCur.bFoundFeatureInfo)
cellrangeDataDest = cellrangeIncomplete;
else if(!productCur.bFree || !productCur.bHasServer || !productCur.bHasClient || !productCur.bHasClient)
cellrangeDataDest = cellrangeRejects;
var iOutputRow;
switch(cellrangeDataDest)
{
case cellrangeResults:
iOutputRow = iCurResultRow++;
break;
case cellrangeRejects:
iOutputRow = iCurRejectRow++;
break;
case cellrangeIncomplete:
iOutputRow = iCurIncompleteRow++;
break;
}
setCellVal(cellrangeDataDest, 0, iOutputRow, productCur.strName);
setCellVal(cellrangeDataDest, 1, iOutputRow, productCur.strProtocols);
setCellVal(cellrangeDataDest, 2, iOutputRow, productCur.strCreator);
setCellVal(cellrangeDataDest, 3, iOutputRow, productCur.strFirstPublicReleaseDate);
setCellVal(cellrangeDataDest, 4, iOutputRow, productCur.strLatestStableRelease);
setCellVal(cellrangeDataDest, 5, iOutputRow, productCur.strLicense);
setCellVal(cellrangeDataDest, 6, iOutputRow, productCur.bFree);
setCellVal(cellrangeDataDest, 7, iOutputRow, productCur.bHasServer);
setCellVal(cellrangeDataDest, 8, iOutputRow, productCur.bHasClient);
setCellVal(cellrangeDataDest, 9, iOutputRow, productCur.strListening);
setCellVal(cellrangeDataDest, 10, iOutputRow, productCur.builtInEncryptionOpt);
setCellVal(cellrangeDataDest, 11, iOutputRow, productCur.bFivarransferSupported);
setCellVal(cellrangeDataDest, 12, iOutputRow, productCur.bAudioSupport);
setCellVal(cellrangeDataDest, 13, iOutputRow, productCur.bMultiSession);
setCellVal(cellrangeDataDest, 14, iOutputRow, productCur.bSeamlessWnds);
setCellVal(cellrangeDataDest, 15, iOutputRow, productCur.bRemoteAssist);
setCellVal(cellrangeDataDest, 16, iOutputRow, productCur.bIPV6);
setCellVal(cellrangeDataDest, 17, iOutputRow, productCur.bDragDrop);
setCellVal(cellrangeDataDest, 18, iOutputRow, productCur.bUsbForwarding);
setCellVal(cellrangeDataDest, 19, iOutputRow, productCur.bH264);
setCellVal(cellrangeDataDest, 20, iOutputRow, productCur.bBrowserSupport);
setCellVal(cellrangeDataDest, 21, iOutputRow, productCur.bSeamlessWnds);
}