問題:Java 操作 OpenOffice 將excel 轉換爲 pdf ,因多列出現折行;
原因:OpenOffice 默認輸出爲A4 大小,源excel 存在隊列,總寬度超出 A4 寬度,所以出現折行;
解決方法:自定義一個類,繼承OpenOfficeDocumentConverter 類 重寫方法,與 refreshDocument 方法,設置 OpenOffice 輸出 pdf 的寬度參數:
參考代碼如下:
public class ConverterDocument extends OpenOfficeDocumentConverter {
public ConverterDocument(OpenOfficeConnection connection) {
super(connection);
}
public final static Size A5, A4, A3;
public final static Size B4, B5, B6;
public final static Size KaoqinReport;
static {
A5 = new Size(14800, 21000);
A4 = new Size(21000, 29700);
A3 = new Size(29700, 42000);
B4 = new Size(25000, 35300);
B5 = new Size(17600, 25000);
B6 = new Size(12500, 17600);
KaoqinReport = new Size(29700, 27940); //最大限度 寬 1600000
}
@Override
protected void refreshDocument(XComponent document) {
super.refreshDocument(document);
// The default paper format and orientation is A4 and portrait. To
// change paper orientation
// re set page size
XPrintable xPrintable = (XPrintable) UnoRuntime.queryInterface(XPrintable.class, document);
PropertyValue[] printerDesc = new PropertyValue[2];
// Paper Orientation
// printerDesc[0] = new PropertyValue();
// printerDesc[0].Name = "PaperOrientation";
// printerDesc[0].Value = PaperOrientation.PORTRAIT;
// Paper Format
printerDesc[0] = new PropertyValue();
printerDesc[0].Name = "PaperFormat";
printerDesc[0].Value = PaperFormat.USER;
// Paper Size
printerDesc[1] = new PropertyValue();
printerDesc[1].Name = "PaperSize";
printerDesc[1].Value = KaoqinReport;
try {
xPrintable.setPrinter(printerDesc);
} catch (Exception e) {
e.printStackTrace();
}
}
}
代碼參考大神!
如何解決OpenOffice轉excel爲pdf時出現折行?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
遠程桌面連接後實現copy文件的3個辦法
peachpi
2020-07-04 09:21:05
搭建thrift服務
heavendai
2020-06-19 13:33:45
2012.4.24 PHP調用外部函數問題
heavendai
2020-02-23 00:04:24
thrift shows CLOSE_WAIL error
heavendai
2018-09-05 00:58:47
2012.11.15
heavendai
2018-09-05 00:58:47
SecureCRT rz 上傳文件失敗問題
heavendai
2018-09-05 00:58:46
linux 與 windows下配VHOST
heavendai
2018-09-05 00:58:41
sort自定義類型排序
heavendai
2018-09-05 00:58:40
再談文本分析系統移植
heavendai
2018-09-05 00:58:40
Thrift框架中函數棧的大小對程序的影響
heavendai
2018-09-05 00:58:40
Thrift 的各項傳輸協議和Socket方式及各種Server的特性
heavendai
2018-09-05 00:58:39
sql語句中內聯左聯右聯的區別?
丛林雪狼code
2018-09-02 03:09:15