Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Getting sheet name in Javascript

Hello

Is it possible, in javascript, get the name of the sheet that is currently selected? I'm working in an extension and I need to get that information from QV.

Thanks,

Gabriel

4 Replies
fkeuroglian
Partner - Master
Partner - Master

Hi

You could get name or ID of active sheet using following expression

ActiveDocument.ActiveSheet.GetProperties.Name

ActiveDocument.ActiveSheet.GetProperties.SheetId

method to get all sheet id

sub LoopSheet

for i = 0 to ActiveDocument.NoOfSheets – 1

set ss= ActiveDocument.GetSheet(i)

msgbox(ss.GetProperties.SheetId)

next

end sub


good luck


Fernando

Anonymous
Not applicable
Author

Hi Fernando

Thanks for your help.

But I'm needing something a little different..

I need to get inside the javascript code what sheet is active, 'cause I'm trying to write it in a div that i've created by javascript.

Regards,

Gabriel

diogopereira89
Contributor II
Contributor II

Hi Grabriel,

Do you have any news on the subject ?


I've been searching the Javascript API for Qlikview but could not find anything related to the sheetID (only for objects).


Regards,

Diogo Pereira


Anonymous
Not applicable
Author

I found two ways.

WITH EXPRESSION

1. put this in your definition.xml

<Text Label="SheetID" Type="text" Initial="" Expression="=GetActiveSheetId()"/>

2. Then in your script name a var sheetID and put the value from above in it.

var sheetID=this.Layout.Text0.text;

3. Then put this inside the extension or wherever you want it.

var sheetName=document.getElementById(sheetID).querySelector("a").querySelector("span").innerHTML;

WITHOUT EXPRESSION

Just use this *not 100% sure that it works for all situations. As long as selectedtab class for the tabrow is always the first element when it looks for elementsbyclassname

var id=document.getElementsByClassName("selectedtab");

  sheetName=id[0].querySelector("a").querySelector("span").innerHTML;