检测所需的打印方向

检测所需的打印方向

本文介绍了使用 Apache POI 检测所需的打印方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache POI 创建 xls 电子表格.有没有办法检测数据是否适合纵向模式,或者我是否必须将工作表设置为横向模式?我知道如何设置模式,但我不知道如何确定数据是否适合当前的打印方向.

I'm using Apache POI to create xls spreadsheets. Is there a way to detect if the data fits in portrait mode or if I have to set the sheet to landscape mode? I know how to set the modes, but I don't know how to find out if the data fits the current print orientation.

推荐答案

我已经尝试过,但看不出有什么方法可以让这个工作正常进行.

I've tried but cant see a way to get this working.

当您创建工作簿时,poi 默认适合高度"和宽度"分别为 1.

When you create the workbook, poi defaults the Fit Height and Width to 1 each.

Fit Height 是页面高度适合工作表

Fit Width 是页面宽度适合工作表

除非您像这样将工作表打印高度和宽度设置为更高的值,

Unless you set the sheet print height and width to a higher value like so,

sheet.getPrintSetup().setFitHeight((short)10);

System.out.println (sheet.getPrintSetup().getFitWidth());
System.out.println (sheet.getPrintSetup().getFitHeight());

总是返回 1 和 1

问题是 Excel 将始终将数据(以缩放大小)压缩到 10% 以适应 1 x 1 页面布局.[在 MS_Excel 中,这显示为 Print Preview >页面设置 >缩放 >低至实际尺寸的 X% ]

The problem is Excel will always compress the data (in zoom size) down to 10% to fit the 1 x 1 page layout. [In MS_Excel, this shows up as Print Preview > Page Setup > Scaling > Down to X% of actual size ]

一旦缩放到 10%,它就会将数据溢出到第 2 页,依此类推.

Once the zoom is at 10%, it then overflows the data onto page 2 and so on.

我尝试了一张包含大量数据的工作表,甚至发送了一个很大的 PrintArea

I've tried a sheet with lots of data and even sent a large PrintArea

workBook.setPrintArea(
                    0, //sheet index
                    0, //start column
                    50, //end column
                    0, //start row
                    520  //end row
            );

在各种打印尺寸上.

sheet.getPrintSetup().setPaperSize((short)11); // A5

因此除非您覆盖它们,否则默认的可打印区域/方向不会更改,因此我认为无法检测到数据大于可打印区域 - 这就是您想要获得的.

So the default printable area / orientation are not changed unless you override them, so I dont think the data can be detected to be larger than the printable area - which is what you're trying to obtain.

这可能是 POI 邮件列表的一个.

This might be one for the POI mailing lists.

更新以在 OP 已经要求的 POI 邮件列表中包含此讨论的链接.

Updated to include link to this discussion on POI mailing lists as already asked by OP.

http:///mail-archives.apache.org/mod_mbox/poi-user/201010.mbox/%[email protected]%3e

这篇关于使用 Apache POI 检测所需的打印方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:55