POI拷贝Excel模版的打印设置

59 篇文章 0 订阅
/**
	* 设置打印配置
	* @param source_sheet
	* @param target_sheet
	*/
	public static void setPrintSetup(HSSFSheet source_sheet,HSSFSheet target_sheet) {
		HSSFPrintSetup s_printSetup = source_sheet.getPrintSetup();
		HSSFPrintSetup t_printSetup = target_sheet.getPrintSetup();
		t_printSetup.setCopies(s_printSetup.getCopies());
		t_printSetup.setDraft(s_printSetup.getDraft());
		t_printSetup.setFitHeight(s_printSetup.getFitHeight());
		t_printSetup.setFitWidth(s_printSetup.getFitWidth());
		t_printSetup.setFooterMargin(s_printSetup.getFooterMargin());
		t_printSetup.setHeaderMargin(s_printSetup.getHeaderMargin());
		t_printSetup.setHResolution(s_printSetup.getHResolution());
		t_printSetup.setLandscape(s_printSetup.getLandscape());
		t_printSetup.setLeftToRight(s_printSetup.getLeftToRight());
		target_sheet.setMargin(HSSFSheet.TopMargin,source_sheet.getMargin(HSSFSheet.TopMargin));// 页边距(上)    
		target_sheet.setMargin(HSSFSheet.BottomMargin,source_sheet.getMargin(HSSFSheet.BottomMargin));// 页边距(下)    
		target_sheet.setMargin(HSSFSheet.LeftMargin,source_sheet.getMargin(HSSFSheet.LeftMargin));// 页边距(左)    
		target_sheet.setMargin(HSSFSheet.RightMargin,source_sheet.getMargin(HSSFSheet.RightMargin));// 页边距(右    
		t_printSetup.setNoColor(s_printSetup.getNoColor());
		t_printSetup.setNoOrientation(s_printSetup.getNoOrientation());
		t_printSetup.setNotes(s_printSetup.getNotes());
		t_printSetup.setOptions(s_printSetup.getOptions());
		t_printSetup.setPageStart(s_printSetup.getPageStart());
		t_printSetup.setPaperSize(s_printSetup.getPaperSize());
		t_printSetup.setScale(s_printSetup.getScale());
		t_printSetup.setUsePage(s_printSetup.getUsePage());
		t_printSetup.setValidSettings(s_printSetup.getValidSettings());
		t_printSetup.setVResolution(s_printSetup.getVResolution());
	}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
POI 中,可以通过创建单元格样式和设置数据验证来实现在 Excel 中添加复选框。具体步骤如下: 1. 创建工作簿和工作表 ``` Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("Sheet1"); ``` 2. 创建单元格样式并设置为复选框样式 ``` CellStyle checkboxStyle = workbook.createCellStyle(); checkboxStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); checkboxStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); checkboxStyle.setBorderBottom(BorderStyle.THIN); checkboxStyle.setBorderTop(BorderStyle.THIN); checkboxStyle.setBorderLeft(BorderStyle.THIN); checkboxStyle.setBorderRight(BorderStyle.THIN); // 设置为复选框样式 checkboxStyle.setLocked(false); checkboxStyle.setIndention((short) 1); checkboxStyle.setAlignment(HorizontalAlignment.LEFT); ``` 3. 在需要添加复选框的单元格中设置该样式 ``` Row row = sheet.createRow(0); Cell cell = row.createCell(0); // 设置单元格样式为复选框样式 cell.setCellStyle(checkboxStyle); ``` 4. 设置数据验证 ``` DataValidationHelper validationHelper = sheet.getDataValidationHelper(); DataValidationConstraint constraint = validationHelper.createExplicitListConstraint(new String[]{"true","false"}); CellRangeAddressList rangeList = new CellRangeAddressList(0, 0, 0, 0); // 设置数据验证为复选框 DataValidation validation = validationHelper.createValidation(constraint, rangeList); validation.setShowErrorBox(true); sheet.addValidationData(validation); ``` 通过以上步骤,就可以在 Excel 中添加复选框了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值