Excel Office JS filter data -
in excel user can select range , hit ctrl+shift+l show filters. trying equivalent behavior office.js add-in.
the closest have come adding table on range want filter , adding filter table. there seem couple of significant problems however.
first, adding table way 30000+ rows slow , using tables larger that. if ctrl+shift+l on range size instantaneous.
additionally, when add table, office.js stylizes range. not want new styling range want filter added.
my current code looks this:
await excel.run(async ctx => { const table = await getorcreatedatatable(ctx, "costdata", new excelrange(this.stateservice.headerrow)); //see below const validationcolumn: excel.tablecolumn = table.columns.getitemornullobject("validation"); validationcolumn.filter.applycustomfilter(`*${searchstring}*`) await ctx.sync(); }); export const getorcreatedatatable = async(ctx: excel.requestcontext, tablename: string, headerrow: excelrange): promise < excel.table > => { let table: excel.table = ctx.workbook.tables.getitemornullobject(tablename) await ctx.sync(); if (!table.isnullobject) console.log(`table: ${tablename} found`) else { const sheet = await getsheet(ctx, headerrow.sheet) const headerrange = sheet.getrange(headerrow.getrange()).getentirerow().getusedrange() const usedrange: excel.range = sheet.getusedrange() const tablerange = headerrange.getboundingrect(usedrange.getlastcell()) table = ctx.workbook.tables.add(tablerange, true) table.name = tablename await ctx.sync(); } return table; }
currently excelapi
supports filtering on table object.
what you're looking here support filtering range. highly recommending visiting uservoice , suggestion.
wiki
Comments
Post a Comment