我是activePivot的新手。我们调用了一个mdx查询并返回了一个CellSetDTO。是否有可用于将此CellSetDTO对象转换为CSV,Excel或其他类型格式的库代码?
我正在查看CellSetDTO类中来自quartetfs的javadoc,但javaDoc没有描述。或者,我可以编写自己的代码来生成CSV,但由于我是新手,并且没有关于javaDoc的描述,因此有点难以启动。
赞赏任何指向任何文档的指针。
谢谢你, 格雷斯
答案 0 :(得分: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());
}
}
}