Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Get the tab name from an Excel spreadsheet

Hello QV Community - I have a spreadsheet with multiple tabs, and each tab name contains important information such as the region code for the source of the data.  What I want to do is include the tab name as a column in the QV data.  Is there a way to do that?

Thank you.

1 Solution

Accepted Solutions
cwolf
Creator III
Creator III

Helllo Ron,

you can do this with a macro:

function GetWorksheets(pExcelFile) 

  set ExApp = CreateObject("Excel.Application") 

  ExApp.Visible = False 

  set ExWrk = ExApp.Workbooks.Open(pExcelFile) 

  s = "" 

  for i = 1 to ExWrk.Sheets.Count 

    if i = ExWrk.Sheets.Count then 

      s = s + "'" + ExWrk.Sheets(i).Name + "'" 

    else 

      s = s + "'" + ExWrk.Sheets(i).Name + "'," 

    end if 

  next 

  ExWrk.Close 

  ExApp.Quit 

  GetWorksheets=s 

end function 

In the script:

set vExcelFile='C:\Temp\Test.xlsx'; 

 

let vSheets=GetWorksheets('$(vExcelFile)'); 

 

for Each vSheet in $(vSheets) 

  LOAD  

  '$(vSheet)' as Region, 

  *  

  FROM [$(vExcelFile)] (ooxml, embedded labels, table is [$(vSheet)]); 

next 

View solution in original post

4 Replies
Kushal_Chawda

Not applicable
Author

Hello Kush141087 -

Thank you for the speedy reply.  Where is this taking the tab name and making it a column?

Thank you.

cwolf
Creator III
Creator III

Helllo Ron,

you can do this with a macro:

function GetWorksheets(pExcelFile) 

  set ExApp = CreateObject("Excel.Application") 

  ExApp.Visible = False 

  set ExWrk = ExApp.Workbooks.Open(pExcelFile) 

  s = "" 

  for i = 1 to ExWrk.Sheets.Count 

    if i = ExWrk.Sheets.Count then 

      s = s + "'" + ExWrk.Sheets(i).Name + "'" 

    else 

      s = s + "'" + ExWrk.Sheets(i).Name + "'," 

    end if 

  next 

  ExWrk.Close 

  ExApp.Quit 

  GetWorksheets=s 

end function 

In the script:

set vExcelFile='C:\Temp\Test.xlsx'; 

 

let vSheets=GetWorksheets('$(vExcelFile)'); 

 

for Each vSheet in $(vSheets) 

  LOAD  

  '$(vSheet)' as Region, 

  *  

  FROM [$(vExcelFile)] (ooxml, embedded labels, table is [$(vSheet)]); 

next 

Kushal_Chawda

see this

  '$(vSheetName)' AS Sheet_name