Java Code Examples for org.apache.poi.ss.usermodel.PrintSetup#setFitHeight()

The following examples show how to use org.apache.poi.ss.usermodel.PrintSetup#setFitHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportTimetableXLS.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected Sheet createSheet(String name) {
	Sheet sheet = null;
	try {
		sheet = (name == null ? iWorkbook.createSheet() : iWorkbook.createSheet(name.replace('/', '-').replace('\\','-').replace('?', ' ').replace('*', ' ').replace(':', '-').replace('[', '(').replace(']', ')')));
	} catch (IllegalArgumentException e) {
		sheet = iWorkbook.createSheet();
	}
	sheet.setDisplayGridlines(false);
	sheet.setPrintGridlines(false);
	sheet.setFitToPage(true);
	sheet.setHorizontallyCenter(true);
       PrintSetup printSetup = sheet.getPrintSetup();
       printSetup.setLandscape(true);
       sheet.setAutobreaks(true);
       printSetup.setFitHeight((short)1);
       printSetup.setFitWidth((short)1);
       return sheet;
}
 
Example 2
Source File: Util.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private static void copySheetSettings(Sheet newSheet, Sheet sheetToCopy) {

		newSheet.setAutobreaks(sheetToCopy.getAutobreaks());
		newSheet.setDefaultColumnWidth(sheetToCopy.getDefaultColumnWidth());
		newSheet.setDefaultRowHeight(sheetToCopy.getDefaultRowHeight());
		newSheet.setDefaultRowHeightInPoints(sheetToCopy.getDefaultRowHeightInPoints());
		newSheet.setDisplayGuts(sheetToCopy.getDisplayGuts());
		newSheet.setFitToPage(sheetToCopy.getFitToPage());

		newSheet.setForceFormulaRecalculation(sheetToCopy.getForceFormulaRecalculation());

		PrintSetup sheetToCopyPrintSetup = sheetToCopy.getPrintSetup();
		PrintSetup newSheetPrintSetup = newSheet.getPrintSetup();

		newSheetPrintSetup.setPaperSize(sheetToCopyPrintSetup.getPaperSize());
		newSheetPrintSetup.setScale(sheetToCopyPrintSetup.getScale());
		newSheetPrintSetup.setPageStart(sheetToCopyPrintSetup.getPageStart());
		newSheetPrintSetup.setFitWidth(sheetToCopyPrintSetup.getFitWidth());
		newSheetPrintSetup.setFitHeight(sheetToCopyPrintSetup.getFitHeight());
		newSheetPrintSetup.setLeftToRight(sheetToCopyPrintSetup.getLeftToRight());
		newSheetPrintSetup.setLandscape(sheetToCopyPrintSetup.getLandscape());
		newSheetPrintSetup.setValidSettings(sheetToCopyPrintSetup.getValidSettings());
		newSheetPrintSetup.setNoColor(sheetToCopyPrintSetup.getNoColor());
		newSheetPrintSetup.setDraft(sheetToCopyPrintSetup.getDraft());
		newSheetPrintSetup.setNotes(sheetToCopyPrintSetup.getNotes());
		newSheetPrintSetup.setNoOrientation(sheetToCopyPrintSetup.getNoOrientation());
		newSheetPrintSetup.setUsePage(sheetToCopyPrintSetup.getUsePage());
		newSheetPrintSetup.setHResolution(sheetToCopyPrintSetup.getHResolution());
		newSheetPrintSetup.setVResolution(sheetToCopyPrintSetup.getVResolution());
		newSheetPrintSetup.setHeaderMargin(sheetToCopyPrintSetup.getHeaderMargin());
		newSheetPrintSetup.setFooterMargin(sheetToCopyPrintSetup.getFooterMargin());
		newSheetPrintSetup.setCopies(sheetToCopyPrintSetup.getCopies());

		Header sheetToCopyHeader = sheetToCopy.getHeader();
		Header newSheetHeader = newSheet.getHeader();
		newSheetHeader.setCenter(sheetToCopyHeader.getCenter());
		newSheetHeader.setLeft(sheetToCopyHeader.getLeft());
		newSheetHeader.setRight(sheetToCopyHeader.getRight());

		Footer sheetToCopyFooter = sheetToCopy.getFooter();
		Footer newSheetFooter = newSheet.getFooter();
		newSheetFooter.setCenter(sheetToCopyFooter.getCenter());
		newSheetFooter.setLeft(sheetToCopyFooter.getLeft());
		newSheetFooter.setRight(sheetToCopyFooter.getRight());

		newSheet.setHorizontallyCenter(sheetToCopy.getHorizontallyCenter());
		newSheet.setMargin(Sheet.LeftMargin, sheetToCopy.getMargin(Sheet.LeftMargin));
		newSheet.setMargin(Sheet.RightMargin, sheetToCopy.getMargin(Sheet.RightMargin));
		newSheet.setMargin(Sheet.TopMargin, sheetToCopy.getMargin(Sheet.TopMargin));
		newSheet.setMargin(Sheet.BottomMargin, sheetToCopy.getMargin(Sheet.BottomMargin));

		newSheet.setPrintGridlines(sheetToCopy.isPrintGridlines());
		newSheet.setRowSumsBelow(sheetToCopy.getRowSumsBelow());
		newSheet.setRowSumsRight(sheetToCopy.getRowSumsRight());
		newSheet.setVerticallyCenter(sheetToCopy.getVerticallyCenter());
		newSheet.setDisplayFormulas(sheetToCopy.isDisplayFormulas());
		newSheet.setDisplayGridlines(sheetToCopy.isDisplayGridlines());
		newSheet.setDisplayRowColHeadings(sheetToCopy.isDisplayRowColHeadings());
		newSheet.setDisplayZeros(sheetToCopy.isDisplayZeros());
		newSheet.setPrintGridlines(sheetToCopy.isPrintGridlines());
		newSheet.setRightToLeft(sheetToCopy.isRightToLeft());
		newSheet.setZoom(1, 1);
		copyPrintTitle(newSheet, sheetToCopy);
	}
 
Example 3
Source File: ExcelHelp.java    From hy.common.report with Apache License 2.0 4 votes vote down vote up
/**
 * 复制模板工作表的打印区域到数据工作表中
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-03-17
 * @version     v1.0
 * 
 * @param i_FromSheet  源工作表
 * @param i_ToSheet    目标工作表
 */
public final static void copyPrintSetup(Sheet i_FromSheet ,Sheet i_ToSheet) 
{
    PrintSetup v_FromPrintSetup = i_FromSheet.getPrintSetup();
    PrintSetup v_ToPrintSetup   = i_ToSheet  .getPrintSetup();
    
    v_ToPrintSetup.setCopies(       v_FromPrintSetup.getCopies());
    v_ToPrintSetup.setDraft(        v_FromPrintSetup.getDraft());          // 值为true时,表示用草稿品质打印
    v_ToPrintSetup.setFitHeight(    v_FromPrintSetup.getFitHeight());      // 设置页高
    v_ToPrintSetup.setFitWidth(     v_FromPrintSetup.getFitWidth());       // 设置页宽
    v_ToPrintSetup.setFooterMargin( v_FromPrintSetup.getFooterMargin());
    v_ToPrintSetup.setHeaderMargin( v_FromPrintSetup.getHeaderMargin());
    v_ToPrintSetup.setHResolution(  v_FromPrintSetup.getHResolution());
    v_ToPrintSetup.setLandscape(    v_FromPrintSetup.getLandscape());      // true,则表示页面方向为横向;否则为纵向
    v_ToPrintSetup.setLeftToRight(  v_FromPrintSetup.getLeftToRight());    // true表示“先行后列”;false表示“先列后行”
    v_ToPrintSetup.setNoColor(      v_FromPrintSetup.getNoColor());        // 值为true时,表示单色打印
    v_ToPrintSetup.setNoOrientation(v_FromPrintSetup.getNoOrientation()); 
    v_ToPrintSetup.setNotes(        v_FromPrintSetup.getNotes());          // 设置打印批注
    v_ToPrintSetup.setPageStart(    v_FromPrintSetup.getPageStart());      // 设置打印起始页码
    v_ToPrintSetup.setPaperSize(    v_FromPrintSetup.getPaperSize());      // 纸张类型 A4纸 HSSFPrintSetup.A4_PAPERSIZE
    v_ToPrintSetup.setScale(        v_FromPrintSetup.getScale());          // 缩放比例80%(设置为0-100之间的值)
    v_ToPrintSetup.setUsePage(      v_FromPrintSetup.getUsePage());        // 设置打印起始页码是否使用"自动"
    v_ToPrintSetup.setValidSettings(v_FromPrintSetup.getValidSettings());
    v_ToPrintSetup.setVResolution(  v_FromPrintSetup.getVResolution());
    
    // 设置打印参数
    if ( i_ToSheet instanceof HSSFSheet )
    {
        ((HSSFPrintSetup)v_ToPrintSetup).setOptions(((HSSFPrintSetup)v_FromPrintSetup).getOptions());
        
        i_ToSheet.setMargin(HSSFSheet.TopMargin     ,i_FromSheet.getMargin(HSSFSheet.TopMargin));     // 页边距(上)
        i_ToSheet.setMargin(HSSFSheet.BottomMargin  ,i_FromSheet.getMargin(HSSFSheet.BottomMargin));  // 页边距(下)
        i_ToSheet.setMargin(HSSFSheet.LeftMargin    ,i_FromSheet.getMargin(HSSFSheet.LeftMargin));    // 页边距(左)
        i_ToSheet.setMargin(HSSFSheet.RightMargin   ,i_FromSheet.getMargin(HSSFSheet.RightMargin));   // 页边距(右)
        i_ToSheet.setMargin(HSSFSheet.HeaderMargin  ,i_FromSheet.getMargin(HSSFSheet.HeaderMargin));  // 页眉
        i_ToSheet.setMargin(HSSFSheet.FooterMargin  ,i_FromSheet.getMargin(HSSFSheet.FooterMargin));  // 页脚
    }
    else if ( i_ToSheet instanceof SXSSFSheet )
    {
        ((XSSFPrintSetup)v_ToPrintSetup).setOrientation(((XSSFPrintSetup)v_FromPrintSetup).getOrientation());  // 设置方向 
        
        i_ToSheet.setMargin(SXSSFSheet.TopMargin    ,i_FromSheet.getMargin(SXSSFSheet.TopMargin));     // 页边距(上)
        i_ToSheet.setMargin(SXSSFSheet.BottomMargin ,i_FromSheet.getMargin(SXSSFSheet.BottomMargin));  // 页边距(下)
        i_ToSheet.setMargin(SXSSFSheet.LeftMargin   ,i_FromSheet.getMargin(SXSSFSheet.LeftMargin));    // 页边距(左)
        i_ToSheet.setMargin(SXSSFSheet.RightMargin  ,i_FromSheet.getMargin(SXSSFSheet.RightMargin));   // 页边距(右)
        i_ToSheet.setMargin(SXSSFSheet.HeaderMargin ,i_FromSheet.getMargin(SXSSFSheet.HeaderMargin));  // 页眉
        i_ToSheet.setMargin(SXSSFSheet.FooterMargin ,i_FromSheet.getMargin(SXSSFSheet.FooterMargin));  // 页脚
    }
    else if ( i_ToSheet instanceof XSSFSheet )
    {
        ((XSSFPrintSetup)v_ToPrintSetup).setOrientation(((XSSFPrintSetup)v_FromPrintSetup).getOrientation());  // 设置方向 
        
        i_ToSheet.setMargin(XSSFSheet.TopMargin     ,i_FromSheet.getMargin(XSSFSheet.TopMargin));     // 页边距(上)
        i_ToSheet.setMargin(XSSFSheet.BottomMargin  ,i_FromSheet.getMargin(XSSFSheet.BottomMargin));  // 页边距(下)
        i_ToSheet.setMargin(XSSFSheet.LeftMargin    ,i_FromSheet.getMargin(XSSFSheet.LeftMargin));    // 页边距(左)
        i_ToSheet.setMargin(XSSFSheet.RightMargin   ,i_FromSheet.getMargin(XSSFSheet.RightMargin));   // 页边距(右)
        i_ToSheet.setMargin(XSSFSheet.HeaderMargin  ,i_FromSheet.getMargin(XSSFSheet.HeaderMargin));  // 页眉
        i_ToSheet.setMargin(XSSFSheet.FooterMargin  ,i_FromSheet.getMargin(XSSFSheet.FooterMargin));  // 页脚
    }
    
    i_ToSheet.setHorizontallyCenter(i_FromSheet.getHorizontallyCenter());  // 设置打印页面为水平居中
    i_ToSheet.setVerticallyCenter(  i_FromSheet.getVerticallyCenter());    // 设置打印页面为垂直居中
    
    copyHeaderFooter(i_FromSheet.getHeader() ,i_ToSheet.getHeader());
    copyHeaderFooter(i_FromSheet.getFooter() ,i_ToSheet.getFooter());
}
 
Example 4
Source File: XLSPrinter.java    From unitime with Apache License 2.0 4 votes vote down vote up
public XLSPrinter(OutputStream output, boolean checkLast) {
	iOutput = output;
	iCheckLast = checkLast;
	iWorkbook = new HSSFWorkbook();
	iSheet = iWorkbook.createSheet();
	iSheet.setDisplayGridlines(false);
	iSheet.setPrintGridlines(false);
	iSheet.setFitToPage(true);
	iSheet.setHorizontallyCenter(true);
       PrintSetup printSetup = iSheet.getPrintSetup();
       printSetup.setLandscape(true);
       iSheet.setAutobreaks(true);
       printSetup.setFitHeight((short)1);
       printSetup.setFitWidth((short)1);
       iStyles = new HashMap<String, CellStyle>();
       
       CellStyle style;
       
       style = iWorkbook.createCellStyle();
       style.setBorderBottom(BorderStyle.THIN);
       style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
       style.setAlignment(HorizontalAlignment.LEFT);
       style.setVerticalAlignment(VerticalAlignment.TOP);
       style.setFont(getFont(true, false, false, Color.BLACK));
       style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
       style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
       style.setWrapText(true);
       iStyles.put("header", style);
       
       style = iWorkbook.createCellStyle();
       style.setAlignment(HorizontalAlignment.LEFT);
       style.setVerticalAlignment(VerticalAlignment.TOP);
       style.setFont(getFont(false, false, false, Color.BLACK));
       style.setWrapText(true);
       iStyles.put("plain", style);
       
       style = iWorkbook.createCellStyle();
       style.setAlignment(HorizontalAlignment.RIGHT);
       style.setVerticalAlignment(VerticalAlignment.TOP);
       style.setFont(getFont(false, false, false, Color.BLACK));
       iStyles.put("number", style);
}