如何将文件设置为“适用于一页上的所有列”

时间:2021-03-28 21:16:22

I have a requirement where files generated by Apache POI need to produce a fie with the fit all columns on one page setting set. I've tried a bunch of variations with the API but so far I haven't been able to do it. Nor can I really find if it can be done.

我有一个需求,Apache POI生成的文件需要在一个页面设置集中生成一个5,包含所有列。我也不知道是否真的能做到。

It seems like the setFitToPage(true) function resizes both the height and width not just the width like I want. Using setFitWidth and setFitHeight like I find in various other stack overflow questions doesn't seem to affect anything.

似乎setFitToPage(true)函数同时调整了高度和宽度,而不是像我希望的那样调整宽度。使用setFitWidth和setFitHeight就像我在其他堆栈溢出问题中发现的那样,似乎不会对任何事情产生影响。

Here is what I have so far:

这是我到目前为止所得到的:

public void setPrintSettings(Sheet sheet) {   sheet.setFitToPage(true); //this will resize both height and width to fit   sheet.getPrintSetup().setLandscape(true);   sheet.getPrintSetup().setFitWidth((short) 1);   sheet.getPrintSetup().setFitHeight((short) 1);}

1 个解决方案

#1


14  

It's not the call to setFitToPage(true) that makes Excel resize both the height and width to fit one page. This call is necessary, but for a different reason. In Excel's Page Setup screen, this method call controls which radio button is active in the dialog box. The value true sets the radio button for "Fit to:", allowing you to control the page(s) wide by page(s) tall boxes. The value false sets the radio button for "Adjust to: ", percentage normal size.

对setFitToPage(true)的调用并不能使Excel调整高度和宽度以适应一个页面。这个呼吁是必要的,但出于不同的原因。在Excel的页面设置屏幕中,此方法调用控制对话框中哪个单选按钮处于活动状态。值true设置了“适合”的单选按钮,允许您通过页面(s)高的框来控制页面。值false设置“调整到:”的单选按钮,百分比正常大小。

In this case, you want to fit it to 1 page wide by "don't care" pages tall. The value to use for pages tall (setFitHeight method) is 0 here.

在这种情况下,你想要把它填满1页宽的“不在乎”页高。在这里,用于page tall (setFitHeight方法)的值为0。

sheet.setFitToPage(true);PrintSetup ps = sheet.getPrintSetup();ps.setFitWidth( (short) 1);ps.setFitHeight( (short) 0);

When I write out a Workbook containing a Sheet with these settings, and I open it in Excel, the Page Setup dialog box has the "Fit to:" radio button selected, and "1 page(s) wide by (blank) tall". In the "Print Preview" screen, the print settings options lists "Fit All Columns on One Page" as selected.

当我写一个包含这些设置的工作簿时,我在Excel中打开它,页面设置对话框有“Fit to:”选择单选按钮,“1页宽(空)高”。在“打印预览”屏幕中,“打印设置”选项列出了所选的“适合一个页面上的所有列”。

#1


14  

It's not the call to setFitToPage(true) that makes Excel resize both the height and width to fit one page. This call is necessary, but for a different reason. In Excel's Page Setup screen, this method call controls which radio button is active in the dialog box. The value true sets the radio button for "Fit to:", allowing you to control the page(s) wide by page(s) tall boxes. The value false sets the radio button for "Adjust to: ", percentage normal size.

对setFitToPage(true)的调用并不能使Excel调整高度和宽度以适应一个页面。这个呼吁是必要的,但出于不同的原因。在Excel的页面设置屏幕中,此方法调用控制对话框中哪个单选按钮处于活动状态。值true设置了“适合”的单选按钮,允许您通过页面(s)高的框来控制页面。值false设置“调整到:”的单选按钮,百分比正常大小。

In this case, you want to fit it to 1 page wide by "don't care" pages tall. The value to use for pages tall (setFitHeight method) is 0 here.

在这种情况下,你想要把它填满1页宽的“不在乎”页高。在这里,用于page tall (setFitHeight方法)的值为0。

sheet.setFitToPage(true);PrintSetup ps = sheet.getPrintSetup();ps.setFitWidth( (short) 1);ps.setFitHeight( (short) 0);

When I write out a Workbook containing a Sheet with these settings, and I open it in Excel, the Page Setup dialog box has the "Fit to:" radio button selected, and "1 page(s) wide by (blank) tall". In the "Print Preview" screen, the print settings options lists "Fit All Columns on One Page" as selected.

当我写一个包含这些设置的工作簿时,我在Excel中打开它,页面设置对话框有“Fit to:”选择单选按钮,“1页宽(空)高”。在“打印预览”屏幕中,“打印设置”选项列出了所选的“适合一个页面上的所有列”。