import com.spire.xls.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class PageMargin {
public static void main(String[] args)throws IOException {
//加载测试文档
Workbook workbook = new Workbook();
workbook.loadFromFile("test.xlsx");
//获取第一个工作表
Worksheet sheet = workbook.getWorksheets().get(0);
//设置上下左右页边距
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setTopMargin(3);
pageSetup.setBottomMargin(2);
pageSetup.setLeftMargin(1);
pageSetup.setRightMargin(1);
//设置页眉页脚页边距
pageSetup.setHeaderMarginInch(2);
pageSetup.setFooterMarginInch(2);
//设置页面方向
pageSetup.setOrientation(PageOrientationType.Landscape);
//设置纸张大小
pageSetup.setPaperSize(PaperSizeType.PaperA4);
//设置页面缩放大小
pageSetup.setZoom(80);
//加载图片,设置成页面背景
BufferedImage image = ImageIO.read( new File("background.png"));
pageSetup.setBackgoundImage(image);
//设置页面打印区域
pageSetup.setPrintArea("A1:I16");
//保存文档
workbook.saveToFile("result.xlsx", ExcelVersion.Version2013);
workbook.dispose();
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.