本文介绍使用Spire.Cloud.SDK for Java来设置Excel单元格格式,包括字体、字号、单元格背景、字体下滑线、字体加粗、字体倾斜、字体颜色、单元格对齐方式、单元格边框等

一、下载SDK及导入jar

1. 下载地址

2. 下载后,创建Maven项目程序(程序使用的IDEA,如果是Eclipse,参照这里的方法),并在pom.xml文件中配置 Maven 仓库路径:

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>cloud</name>
<url>http://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>

在 pom.xml 文件中指定 Spire.cloud.sdk的 Maven 依赖:

<dependencies>
<dependency>
<groupId> cloud </groupId>
<artifactId>spire.cloud.sdk</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId> com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId> com.squareup.okhttp</groupId>
<artifactId>logging-interceptor</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId> com.squareup.okhttp </groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId> com.squareup.okio </groupId>
<artifactId>okio</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId> io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.18</version>
</dependency>
<dependency>
<groupId> org.threeten </groupId>
<artifactId>threetenbp</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>

配置完成后,在 IDEA 中,点击”Import Changes”即可导入所需要的所有jar文件:

如下导入结果:

二、创建应用获取ID和Key

方法参考如下图中的步骤:

三、文档路径

程序使用的文档路径是“文档管理”目录下的文件夹路径,冰蓝云提供的2G的免费存储空间。

四、Java 代码示例

import spire.cloud.excel.sdk.Configuration;
import spire.cloud.excel.sdk.api.CellsApi;
import spire.cloud.excel.sdk.model.Border;
import spire.cloud.excel.sdk.model.Color;
import spire.cloud.excel.sdk.model.Font;
import spire.cloud.excel.sdk.model.Style; import java.util.ArrayList;
import java.util.List; public class SetCellStyle {
//配置App ID和App Key等应用账号信息
static String appId = "App ID";
static String appKey = "App Key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
static CellsApi cellsApi = new CellsApi(configuration); public static void main(String[] args) throws Exception{
String name = "newtest.xlsx";//用于测试的excel文档
String folder = "input";//云端excel文件所在文件夹
String storage = null;//使用冰蓝云配置的2G存储空间,可设置为null
String sheetName = "Sheet1";//指定Excel中的工作表
String cellName = "C3";//指定单元格 Style style = new Style();//创建Style
Font font = new Font();//创建字体
font.setIsBold(true);//字体加粗
font.setIsItalic(true);//字体倾斜
font.setUnderline("Single");//下划线样式
font.setName("楷体");//字体名称
font.setSize(15);//字体大小
font.setColor(new Color(120,220,20,60));//字体颜色
style.setFont(font);//应用字体样式 style.setBackgroundColor(new Color(138,43,226,252));//设置单元格背景颜色
style.setHorizontalAlignment("Center");//水平对齐方式(居中对齐)
style.setVerticalAlignment("Center");//垂直对齐方式(居中对齐) //添加边框
List<Border> list1= new ArrayList<Border>();//创建数组
Border border1 = new Border();//创建边框1
border1.setLineStyle("Medium");//边框线条样式
border1.setColor(new Color(255, 252, 39, 4));//边框颜色
border1.setBorderType("EdgeTop");//边框类型
list1.add(border1);//添加边框1到数组 Border border2 = new Border();//创建边框2
border2.setLineStyle("DashDot");
border2.setColor(new Color(255, 252, 39, 4));
border2.setBorderType("EdgeRight");
list1.add(border2);//添加边框2到数组
style.setBorderCollection(list1);//设置边框到单元格样式 //调用方法设置单元格样式
cellsApi.setCellStyle(name, sheetName, cellName, style, folder, storage);
}
}

单元格设置效果前后对比:

设置前:

设置后:

(完)

Java 设置Excel单元格格式—基于Spire.Cloud.SDK for Java的更多相关文章

  1. 【JAVA】POI设置EXCEL单元格格式为文本、小数、百分比、货币、日期、科学计数法和中文大写

    POI设置EXCEL单元格格式为文本.小数.百分比.货币.日期.科学计数法和中文大写 博客分类:,本文内容转自 http://javacrazyer.iteye.com/blog/894850 FIL ...

  2. POI设置EXCEL单元格格式为文本、小数、百分比、货币、日期、科学计数法和中文大写

    再读本篇文章之前,请先看我的前一篇文章,前一篇文章中有重点讲到POI设置EXCEL单元格格式为文本格式,剩下的设置小数.百分比.货币.日期.科学计数法和中文大写这些将在下面一一写出 以下将要介绍的每一 ...

  3. Python生成文本格式的excel\xlwt生成文本格式的excel\Python设置excel单元格格式为文本\Python excel xlwt 文本格式

    Python生成文本格式的excel\xlwt生成文本格式的excel\Python设置excel单元格格式为文本\Python excel xlwt 文本格式 解决: xlwt 中设置单元格样式主要 ...

  4. Java 设置、删除、获取Word文档背景(基于Spire.Cloud.SDK for Java)

    本文介绍使用Spire.Cloud.SDK for Java 提供的BackgroundApi接口来操作Word文档背景的方法,可设置背景,包括设置颜色背景setBackgroundColor().图 ...

  5. Java 将PDF/XPS转为Word/html /SVG/PS/PCL/PNG、PDF和XPS互转(基于Spire.Cloud.SDK for Java)

    Spire.Cloud.SDK for Java提供了接口PdfConvertApi通过convert()方法将PDF文档以及XPS文档转为指定文档格式,如转PDF为Word(支持Docx.Doc). ...

  6. Java 添加、下载、读取PDF附件信息(基于Spire.Cloud.SDK for Java)

    Spire.Cloud.SDK for Java提供了PdfAttachmentsApi接口添加附件addAttachment().下载附件downloadAttachment().获取附件信息get ...

  7. Java 添加、删除、替换、格式化Word中的文本(基于Spire.Cloud.SDK for Java)

    Spire.Cloud.SDK for Java提供了TextRangesApi接口可通过addTextRange()添加文本.deleteTextRange()删除文本.updateTextRang ...

  8. POI中设置Excel单元格格式样式(居中,字体,边框等)

    创建sheet什么的就不多说了,直接进入正题 HSSFCellStyle cellStyle = wb.createCellStyle();   一.设置背景色: cellStyle.setFillF ...

  9. POI 设置EXCEL单元格格式(日期数字文本等)

    HSSFCellStyle style0 = workbook2003.createCellStyle(); style0.setBorderBottom(HSSFCellStyle.BORDER_T ...

随机推荐

  1. 洛谷 p1605 迷宫问题 详解

    题解:dfs搜索 #include <iostream> #include <algorithm> #include <cstring> #include < ...

  2. python3.x 基础六:面向对象

    面向对象特性 class 类 一个类是对一类拥有相同属性的对象的描述,在类中定义了这些对象都具备的属性/共同方法 object对象 一个对象指一个类实例化后的实例,一个类必须经过实例化后才能在程序中调 ...

  3. netty 实现简单的rpc调用

    yls 2020/5/23 netty 实现简单rpc准备 使用netty传输java bean对象,可以使用protobuf,也可以通过json转化 客户端要将调用的接口名称,方法名称,参数列表的类 ...

  4. PAT-1080 Graduate Admission (结构体排序)

    1080. Graduate Admission It is said that in 2013, there were about 100 graduate schools ready to pro ...

  5. Unity读取StreamingAssets路径下的文件

    /// <summary> ///读取StreamingAssets中的文件 /// </summary> /// <param name="path" ...

  6. corosync+pacemaker实现httpd高可用

    corosync+pacemaker 官方网址 https://clusterlabs.org/ 一.开源高可用了解 OPEN SOURCE HIGH AVAILABILITY CLUSTER STA ...

  7. ngnix随笔一

    nginx安装及启动 1.用yum源安装,首先配置yum源 在“/etc/yum.repo.d/”下创建yum源文件 例如:cd /etc/yum.repo.d/nginx.repo [nginx-s ...

  8. 使用 git add -p 整理 patch

    背景 当我们修改了代码准备提交时,本地的改动可能包含了不能提交的调试语句,还可能需要拆分成多个细粒度的 pactch. 本文将介绍如何使用 git add -p 来交互式选择代码片段,辅助整理出所需的 ...

  9. PowerPC-object与elf中的符号引用

    https://mp.weixin.qq.com/s/6snzjEpDT4uQuCI2Nx9VcQ   一. 符号引用 编译会先把每个源代码文件编译成object目标文件,然后把所有目标文件链接到一起 ...

  10. 跨域解决方案 - 跨域资源共享cors

    目录 1. cors 介绍 2. 原理 3. cors 解决跨域 4. 自定义HTTP 头部字段解决跨域 5. 代码演示 5. 参考链接 1. cors 介绍 cors 说的是一个机制,其实相当于一个 ...