excel 设置图片页眉

使用 aspose cells 相关 api 可以设置

public static void main(String[] args) throws Exception
{

 // 验证License
    if (!getLicense()) {
        return;
    }
    Workbook workbook = new Workbook("C:/Users/Administrator/Desktop/电子履历.xls");
    PageSetup pageSetup = workbook.getWorksheets().get(1).getPageSetup();
    //Setting picture at the central footer
    pageSetup.setHeader(0, "&G");
    FileInputStream fis = new FileInputStream("C:/Users/Administrator/Desktop/logo.jpg");
    byte[] picData = new byte[fis.available()];
    fis.read(picData);
    pageSetup.setHeaderPicture(0, picData);
    
    //Pull the picture out
    Picture pic = pageSetup.getPicture(true, 0);
   
    //Set the aspect ratio to lock and keep it relative to the original
    pic.setLockAspectRatio(true);
    pic.setRelativeToOriginalPictureSize(true);
    //Set the height only
    pic.setHeightInch(0.8);
    pic.setWidthInch( pic.getWidthInch()*pic.getHeightScale() /95);

    
    fis.close();
    workbook.save("C:/Users/Administrator/Desktop/电子履历.xls");
}

/**
 * 获取license
 * 
 * @return */
public  static  boolean  getLicense() {
    boolean result = false;
    try {
        license = new FileInputStream("C:/Users/Administrator/Desktop/AsposeCells/AsposeCells/source/license.xml");// 凭证文件

        License aposeLic = new License();
        aposeLic.setLicense(license);
        result = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}