This add-in creates columns showing the number of sheets, worksheets, and charts in Excel files.
function OnInit(initData) {
initData.name = 'ExcelWorkbook';
initData.version = '2022-06-29';
initData.url = 'https://resource.dopus.com/t/column-excel-workbook-info/41595';
initData.desc = 'Display Info about Exel Workbooks in columns';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnAddColumns(addColData) {
var col = addColData.AddColumn();
col.name = 'SheetsCount';
col.label = 'SheetsCount';
col.header = 'SheetsCount';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.type = 'number';
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'WorksheetsCount';
col.label = 'WorksheetsCount';
col.header = 'WorksheetsCount';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.type = 'number';
col.method = 'OnColumn';
var col = addColData.AddColumn();
col.name = 'ChartsCount';
col.label = 'ChartsCount';
col.header = 'ChartsCount';
col.justify = 'left';
col.multicol = true;
col.autogroup = true;
col.type = 'number';
col.method = 'OnColumn';
}
var excelApp = new ActiveXObject('Excel.Application');
function OnColumn(scriptColData) {
if (excelApp == null) return;
var item = scriptColData.item;
if (item.is_dir) return;
if (item.ext.substring(0, 3) != '.xl') return;
if (item.name_stem.substring(0, 1) == '~') return;
var wb = excelApp.Workbooks.Open(String(item.realpath));
scriptColData.columns('SheetsCount').value = wb.Sheets.Count;
scriptColData.columns('WorksheetsCount').value = wb.Worksheets.Count;
scriptColData.columns('ChartsCount').value = wb.Charts.Count;
wb.Close();
}
To toggle the columns, use
Set COLUMNSTOGGLE="scp:ExcelWorkbook/SheetsCount(!,a,0)"
Set COLUMNSTOGGLE="scp:ExcelWorkbook/WorksheetsCount(!,a,0)"
Set COLUMNSTOGGLE="scp:ExcelWorkbook/ChartsCount(!,a,0)"
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Toggle ExcelWorkbook</label>
<icon1>#office</icon1>
<function type="normal">
<instruction>Set COLUMNSTOGGLE="scp:ExcelWorkbook/SheetsCount(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:ExcelWorkbook/WorksheetsCount(!,a,0)"</instruction>
<instruction>Set COLUMNSTOGGLE="scp:ExcelWorkbook/ChartsCount(!,a,0)"</instruction>
</function>
</button>
ColumnExcelWorkbook.js.txt (1.8 KB)