Data pilot ImportDescriptor availlable since OOo 3.3

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Data pilot ImportDescriptor availlable since OOo 3.3

Post by Villeroy »

Since v3.3 we can access imported pilots via API. Before that version the API was completely blinded towards imported pilots.
The fixed issue with Basic code to create a pilot: http://www.openoffice.org/issues/show_bug.cgi?id=42199
A quick and dirty macro printing info about a pilot's import descriptor:

Code: Select all

Sub PrintPilotImportInfo()
oInitialTarget =ThisComponent
  Dim oSpreadsheet As Object
  Dim oDataPilotTables As Object
  Dim oObj_1 As Object
  Dim oPropertyValue As Object
  oSpreadsheet = oInitialTarget.Sheets.getByName("Pivot")
  oDataPilotTables = oSpreadsheet.DataPilotTables
  oObj_1 = oDataPilotTables.getByIndex(0)
  
  oPropertyValue = oObj_1.getPropertyValue("ImportDescriptor")
  '0 DatabaseName ="PVC"
  '1 SourceType =com.sun.star.sheet.DataImportMode.TABLE
  '2 SourceObject ="List"
  '3 IsNative =False
Dim sImport$
  select case oPropertyValue(1).Value
  	case is=com.sun.star.sheet.DataImportMode.NONE
  		sImport="Not Imported"
  	case is=com.sun.star.sheet.DataImportMode.SQL
	  If oPropertyValue(3).Value then
	  	sImport= "Source:"& oPropertyValue(0).Value &", "& "Native SQL:"
	  else
	  	sImport= "Source:"& oPropertyValue(0).Value &", "& "Parsed SQL:"
	  endif
  	case is=com.sun.star.sheet.DataImportMode.TABLE
  		sImport= "Source:"& oPropertyValue(0).Value &", "& "Table:"
  	case is=com.sun.star.sheet.DataImportMode.QUERY
	  If oPropertyValue(3).Value then
  		sImport= "Source:"& oPropertyValue(0).Value &", "& "Native Query:"
  	else
		sImport= "Source:"& oPropertyValue(0).Value &", "& "Parsed Query:"
	endif
  end select
Print sImport & oPropertyValue(2).Value 
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
mbrouillet
Posts: 1
Joined: Wed Dec 08, 2010 12:30 am

Re: Data pilot ImportDescriptor availlable since OOo 3.3

Post by mbrouillet »

For those who haven't yet upgraded to Ooo 3.3, here is a dirty solution, assuming you've got a linux-like command-line (or a cygwin or something similar):

Code: Select all

zipgrep -oi '<table:database-source[^>]*>' yourfile.ods content.xml 
OpenOffice 3.0.0 (build 3958) / 2.6.27-gentoo-r8
Post Reply