java调用Spire.Doc

1.导入maven

<!--Spire.Doc-->
        <dependency>
            <groupId>e-iceblue</groupId>
            <artifactId>spire.doc.free</artifactId>
            <version>3.9.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/main/webapp/WEB_INF/lib/Spire.Doc.jar</systemPath>

        </dependency>

        <dependency>
            <groupId>e-iceblue</groupId>
            <artifactId>spire.pdf</artifactId>
            <version>3.11.6</version>
            <scope>system</scope>
            <systemPath>${basedir}/src/main/webapp/WEB_INF/lib/Spire.Doc.jar</systemPath>

        </dependency>

        <!--用于生成图片  -->
        <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.19</version>
        </dependency>

2.基本方法

static{
    Document document = new Document();
    Section sec = document.addSection();
}


/**
     * 设置标题样式(大小:20;居中)
     */
    private static void titleStyle(Section sec, String text, BuiltinStyle builtinStyle) {
        Paragraph p = sec.addParagraph();
        TextRange tr = p.appendText(text);
        p.applyStyle(builtinStyle);
        //设置字体大小和颜色
        tr.getCharacterFormat().setTextColor(Color.black);
        tr.getCharacterFormat().setFontName("宋体");
        tr.getCharacterFormat().setFontSize(20);
        tr.getCharacterFormat().setItalic(false);
        p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
        //设置段后间距
        p.getFormat().setAfterSpacing(10);
    }

   

    /**
     * 设置表格标题行
     */
    private static void tableTitle(Table table, String[] header) {

        TableRow row = table.getRows().get(0);
        row.isHeader(true);
        row.setHeight(20);
        row.setHeightType(TableRowHeightType.Exactly);
        for (int i = 0; i < header.length; i++) {
            row.getCells().get(i).getCellFormat().setVerticalAlignment(VerticalAlignment.Middle);
            Paragraph p = row.getCells().get(i).addParagraph();
            p.getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
            TextRange range1 = p.appendText(header[i]);
            range1.getCharacterFormat().setFontName("Arial");
            range1.getCharacterFormat().setFontSize(12f);
            range1.getCharacterFormat().setBold(true);
        }
    }

    /**
     * 设置页边距
     */
    private static void setPageMargins(Section sec, Float top, Float bottom, Float left, Float right) {
        sec.getPageSetup().getMargins().setTop(top);
        sec.getPageSetup().getMargins().setBottom(bottom);
        sec.getPageSetup().getMargins().setLeft(left);
        sec.getPageSetup().getMargins().setRight(right);
    }





  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值