2014-03-28 48 views
0

我是activePivot的新手。我們調用了一個mdx查詢並返回了一個CellSetDTO。是否有任何庫代碼可用於將此CellSetDTO對象轉換爲CSV,Excel或其他類型的格式?ActivePivot:將CellSetDTO對象轉換爲csv,excel或其他格式的任何代碼?

我正在從CellSetDTO類的quartetfs中查找javadoc,但javaDoc沒有說明。另外,我可以編寫我自己的代碼來生成CSV,但由於我對此並不熟悉,並且沒有關於javaDoc的描述,所以啓動起來有點困難。

任何指向任何文檔的指針表示讚賞。

謝謝 格雷斯

回答

1

你可以使用,你可以在沙盤項目找到樣本,請參閱CellSetPrinter類,設置在構造ARG的CellSetDTO。 查看CellSetPrinter類:

public class CellSetPrinter { 

protected final CellSetDTO cellSet; 

protected final AxisDTO slicer; 

protected final List<AxisDTO> axes; 

protected final List<CellDTO> cells; 

public CellSetPrinter(CellSetDTO cellSet) { 
    this.cellSet = cellSet; 
    this.axes = cellSet.getAxes().getAxis(); 
    this.slicer = cellSet.getSlicerAxis(); 
    this.cells = cellSet.getCells().getCell(); 
} 

/** 
* Compute axis positions from the cell ordinal with the classic formula: 
* <ul> 
* <li>(x0, x1, x2) -> x0 + x1 * n0 + x2 * n1 * n2 
* <li>ordinal -> (ordinal % n0, (ordinal/n0) % n1, (ordinal/(n0*n1)) % n2) 
* </ul> 
* 
* @param ordinal 
* @return tuple expressed by coordinates 
*/ 
protected List<String> getTuple(int ordinal) { 
    List<String> tuple = new ArrayList<>(); 

    // Lookup positions on axes 
    final int[] axisCoordinates = new int[axes.size()]; 

    int coeff = 1; 
    for(int a = 0; a < axisCoordinates.length; a++) { 
     int positionCount = axes.get(a).getPositions().getPosition().size(); 
     axisCoordinates[a] = (ordinal/coeff) % positionCount; 
     coeff *= positionCount; 
    } 

    for(int a = 0; a < axisCoordinates.length; a++) { 
     AxisPositionDTO position = axes.get(a).getPositions().getPosition().get(axisCoordinates[a]); 
     for(MemberDTO member : position.getMembers().getMember()) { 
      for(String pathElement : member.getPath().getItems().getItem()) { 
       if(!"AllMember".equals(pathElement)) { 
        tuple.add(pathElement); 
       } 
      } 
     } 
    } 

    // Append slicer content 
    for(AxisPositionDTO position : slicer.getPositions().getPosition()) { 
     for(MemberDTO member : position.getMembers().getMember()) { 
      for(String pathElement : member.getPath().getItems().getItem()) { 
       if(!"AllMember".equals(pathElement)) { 
        tuple.add(pathElement); 
       } 
      } 
     } 
    } 
    return tuple; 
} 

public void print(PrintStream out) { 
    for(CellDTO cell : cells) { 
     System.out.println(getTuple(cell.getOrdinal()) + " " + cell.getFormattedValue()); 
    } 
} 
} 
+0

謝謝Tuxmobil。這很有幫助。我注意到有兩個cellDTO類,它們都非常相似。 com.quartetfs.biz.pivot.dto.CellDTO和com.quartetfs.webservices.CellDTO類。我不確定爲什麼有兩個這樣的類似的類。我有dto.CellDTO對象。當你提到樣本時,你能指出我哪個包? – user3474390

+0

在導入中添加以下類:import com.quartetfs.webservices.AxisDTO; import com.quartetfs.webservices.AxisPositionDTO; import com.quartetfs.webservices.CellDTO; import com.quartetfs.webservices.CellSetDTO; import com.quartetfs.webservices.MemberDTO; – tuxmobil

相關問題