天天看点

jacob word竖排文字变横排

一列正常,两列需要修改

public static String getTxtFromCell(Dispatch selection,Dispatch doc,int tableIndex, int cellRowIdx, int cellColIdx) {

//  System.out.println(tableIndex+cellRowIdx+cellColIdx);

// 所有表格

 Dispatch tables = Dispatch.get(doc, "Tables").toDispatch(); 

 // 要填充的表格

 Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex)).toDispatch();  

 Dispatch cell = Dispatch.call(table, "Cell", new Variant(cellRowIdx),new Variant(cellColIdx)).toDispatch();

 Dispatch Range=Dispatch.get(cell,"Range").toDispatch();

 String text=Dispatch.get(Range,"Text").toString();

 text = text.substring(0, text.length() - 2); // 去掉最后的回车符;

 char[] chars=text.toCharArray();

 String ret="";

 Dispatch.call(cell, "Select");

// Dispatch ret = Dispatch.get(selection, "Text").toDispatch();

ret= Dispatch.get(selection, "Orientation").toString();

if(ret.equals("9999999")){

Dispatch.put(selection, "Orientation", 0);

String str="";

for(char a:chars){

str=str+a+"\n" ;

}

str = str.substring(0, str.length() - 1);

Dispatch.put(selection, "Text", str);

System.out.println("---------");

}

 return ret;

}