亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

通過Java設(shè)置Word頁面背景色過程詳解

 更新時間:2019年07月09日 14:22:03   作者:Miaonly  
這篇文章主要介紹了通過Java設(shè)置Word頁面背景色過程詳解,Word中可以針對不同文檔排版設(shè)計要求來設(shè)置背景設(shè)置顏色。常見的可設(shè)置單一顏色、漸變色或加載圖片來設(shè)置成背景。下面通過Java來設(shè)置以上3種Word頁面背景色,需要的朋友可以參考下

前言

Word中可以針對不同文檔排版設(shè)計要求來設(shè)置背景設(shè)置顏色。常見的可設(shè)置單一顏色、漸變色或加載圖片來設(shè)置成背景。下面通過Java來設(shè)置以上3種Word頁面背景色。

使用工具:Spire.Doc for Java v2.2.0

Jar文件導入方法

方法1:通過官網(wǎng)下載。在程序下新建一個directory目錄,并命名(本示例中命名為lib);將控件包中l(wèi)ib文件夾下的Spire.Doc.jar(如下圖1)直接復制到程序中新建的目錄下。復制jar文件后,鼠標右鍵點擊jar文件,選擇”Add as Library”。完成導入(如下圖2)。

圖1:

圖2:

方法2:通過maven導入。參考導入方法。

Java代碼示例(供參考)

【示例1】添加單一顏色的背景色

import com.spire.doc.*;
import com.spire.doc.documents.BackgroundType;
import java.awt.*;
import java.io.IOException;

public class BackgroundColor_Doc {
  public static void main (String[] args) throws IOException{
    //加載測試文
    String input="test.docx";
    String output="backgroundcolor.docx";
    Document doc = new Document(input);

    //設(shè)置單色背景
    doc.getBackground().setType(BackgroundType.Color);
    doc.getBackground().setColor(Color.PINK);

    //保存文檔
    doc.saveToFile(output,FileFormat.Docx_2013);
  }
}

【示例2】添加漸變背景色

import com.spire.doc.*;
import com.spire.doc.documents.BackgroundType;
import com.spire.doc.documents.GradientShadingStyle;
import com.spire.doc.documents.GradientShadingVariant;
import java.awt.*;
import java.io.IOException;

public class GradientBackground_Doc {
  public static void main(String[] arg) throws IOException{
    //加載測試文檔
    String input= "test.docx";
    String output="GradientBackgound.docx";
    Document doc = new Document(input);

    //設(shè)置漸變色
    doc.getBackground().setType(BackgroundType.Gradient);
    doc.getBackground().getGradient().setColor1(Color.white);
    doc.getBackground().getGradient().setColor2(Color.green);
    doc.getBackground().getGradient().setShadingVariant(GradientShadingVariant.Shading_Middle);
    doc.getBackground().getGradient().setShadingStyle(GradientShadingStyle.Horizontal);

    //保存文檔
    doc.saveToFile(output, FileFormat.Docx_2010);
  }
}

【示例3】加載圖片設(shè)置成背景

import com.spire.doc.*;
import com.spire.doc.documents.BackgroundType;
import java.io.IOException;

public class ImgBackground_Doc {
  public static void main(String[] arg) throws IOException {
    //加載文件
    String input= "test.docx";
    String output="ImgBackgound.docx";
    String img= "lye.png";
    Document doc = new Document(input);

    //設(shè)置圖片背景
    doc.getBackground().setType(BackgroundType.Picture);
    doc.getBackground().setPicture(img);

    //保存文檔
    doc.saveToFile(output, FileFormat.Docx);
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論