XIndexAccess.class, xSpreadsheets);
try
{
oSheet = (XSpreadsheet) AnyConverter.toObject (
new Type (XSpreadsheet.class),
oIndexAccess.getByIndex (0));
oSheet2 = (XSpreadsheet) AnyConverter.toObject (
new Type (XSpreadsheet.class),
oIndexAccess.getByIndex (1));
}
catch (com.sun.star.lang.WrappedTargetException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get a spreadsheet", e);
}
catch (com.sun.star.lang.IndexOutOfBoundsException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get a spreadsheet", e);
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get a spreadsheet", e);
}
try
{
log.println ("Filling a table");
for (int i = 1; i < mMaxFieldIndex; i++)
{
oSheet.getCellByPosition (i, 0).setFormula ("Col" + i);
oSheet.getCellByPosition (0, i).setFormula ("Row" + i);
oSheet2.getCellByPosition (i, 0).setFormula ("Col" + i);
oSheet2.getCellByPosition (0, i).setFormula ("Row" + i);
}
for (int i = 1; i < mMaxFieldIndex; i++)
{
for (int j = 1; j < mMaxFieldIndex; j++)
{
oSheet.getCellByPosition (i, j).setValue (i * (j + 1));
oSheet2.getCellByPosition (i, j).setValue (i * (j + 2));
}
}
oSheet.getCellByPosition (1, 1).setFormula ("aName");
oSheet.getCellByPosition (1, 2).setFormula ("otherName");
oSheet.getCellByPosition (1, 3).setFormula ("una");
oSheet.getCellByPosition (1, 4).setFormula ("otherName");
oSheet.getCellByPosition (1, 5).setFormula ("somethingelse");
}
catch (com.sun.star.lang.IndexOutOfBoundsException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't fill some cells", e);
}
// change a value of a cell and check the change in the data pilot
// (for the XDataPilotTable.refresh() test)
Object oChangeCell = null;
Object oCheckCell = null;
Integer aChangeValue = null;
try
{
// cell of data
oChangeCell = oSheet.getCellByPosition (1, 5);
int x = sCellAdress.Column;
int y = sCellAdress.Row + 3;
// cell of the data pilot output
oCheckCell = oSheet.getCellByPosition (x, y);
aChangeValue = new Integer (27);
}
catch (com.sun.star.lang.IndexOutOfBoundsException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get cells for changeing.", e);
}
// create the test objects
log.println ("Getting test objects");
XDataPilotTablesSupplier DPTS = (XDataPilotTablesSupplier) UnoRuntime.queryInterface (
XDataPilotTablesSupplier.class,
oSheet);
XDataPilotTables DPT = DPTS.getDataPilotTables ();
XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor ();
DPDsc.setSourceRange (sCellRangeAdress);
XPropertySet fieldPropSet = null;
try
{
Object oDataPilotField = DPDsc.getDataPilotFields ().getByIndex (0);
fieldPropSet = (XPropertySet) UnoRuntime.queryInterface (
XPropertySet.class, oDataPilotField);
fieldPropSet.setPropertyValue ("Orientation",
com.sun.star.sheet.DataPilotFieldOrientation.ROW);
oDataPilotField = DPDsc.getDataPilotFields ().getByIndex (1);
fieldPropSet = (XPropertySet) UnoRuntime.queryInterface (
XPropertySet.class, oDataPilotField);
fieldPropSet.setPropertyValue ("Function",
com.sun.star.sheet.GeneralFunction.SUM);
fieldPropSet.setPropertyValue ("Orientation",
com.sun.star.sheet.DataPilotFieldOrientation.DATA);
oDataPilotField = DPDsc.getDataPilotFields ().getByIndex (2);
fieldPropSet = (XPropertySet) UnoRuntime.queryInterface (
XPropertySet.class, oDataPilotField);
fieldPropSet.setPropertyValue ("Orientation",
com.sun.star.sheet.DataPilotFieldOrientation.COLUMN);
}
catch (com.sun.star.lang.WrappedTargetException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't create a test environment", e);
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't create a test environment", e);
}
catch (com.sun.star.beans.PropertyVetoException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't create a test environment", e);
}
catch (com.sun.star.beans.UnknownPropertyException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't create a test environment", e);
}
catch (com.sun.star.lang.IndexOutOfBoundsException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't create a test environment", e);
}
log.println ("Insert the DataPilotTable");
if (DPT.hasByName ("DataPilotTable"))
{
DPT.removeByName ("DataPilotTable");
}
DPT.insertNewByName ("DataPilotTable", sCellAdress, DPDsc);
XIndexAccess xIA = (XIndexAccess) UnoRuntime.queryInterface (XIndexAccess.class,DPTS.getDataPilotTables ());
XIndexAccess IA = null;
try
{
XDataPilotDescriptor xDPT = (XDataPilotDescriptor) UnoRuntime.queryInterface (XDataPilotDescriptor.class,xIA.getByIndex (0));
IA = xDPT.getRowFields ();
//getSRange(IA);
System.out.println ("COUNT: "+IA.getCount ());
datapilotfield = (XInterface) AnyConverter.toObject (
new Type (XInterface.class), IA.getByIndex (0));
}
catch (com.sun.star.lang.WrappedTargetException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get data pilot field", e);
}
catch (com.sun.star.lang.IndexOutOfBoundsException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get data pilot field", e);
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get data pilot field", e);
}
try
{
XDataPilotFieldGrouping dpfg = (XDataPilotFieldGrouping) UnoRuntime.queryInterface (XDataPilotFieldGrouping.class, datapilotfield);
String[] elements = new String[]{"aName","otherName"};
dpfg.createNameGroup (elements);
DataPilotFieldGroupInfo dpgi=null;
xIA = (XIndexAccess) UnoRuntime.queryInterface (XIndexAccess.class,DPTS.getDataPilotTables ());
try
{
XDataPilotDescriptor xDPT = (XDataPilotDescriptor) UnoRuntime.queryInterface (XDataPilotDescriptor.class,xIA.getByIndex (0));
IA = xDPT.getRowFields ();
}
catch (com.sun.star.lang.WrappedTargetException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get data pilot field", e);
}
catch (com.sun.star.lang.IndexOutOfBoundsException e)
{
e.printStackTrace ();
throw new StatusException ("Couldn't get data pilot field", e);
}
for (int i=0;i<IA.getCount ();i++)
{
datapilotfield = (XInterface) AnyConverter.toObject (
new Type (XInterface.class), IA.getByIndex (i));
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface (XPropertySet.class, IA.getByIndex (i));
if (((Boolean)xPropertySet.getPropertyValue ("IsGroupField")).booleanValue ())
{
xPropertySet = (XPropertySet) UnoRuntime.queryInterface (XPropertySet.class, datapilotfield);
XNamed xNamed = (XNamed) UnoRuntime.queryInterface (XNamed.class, IA.getByIndex (i));