parent
ac0ac6ffad
commit
288ed7e84b
@ -0,0 +1,41 @@
|
||||
package UnitTest.ImportExcel;
|
||||
|
||||
import com.dsideal.QingLong.Util.PoiUtil;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AddComment {
|
||||
//工作目录
|
||||
public static String path = "D:\\dsWork\\QingLong\\src\\main\\resource\\Excel\\";
|
||||
public static void main(String[] args) throws Exception {
|
||||
//学校上传的Excel
|
||||
String source = path + "1.xlsx";
|
||||
//要进行标注的行和列
|
||||
int r = 5, c = 6;//第6行第7列
|
||||
//字号
|
||||
int fontSize = 12;
|
||||
//标识的颜色,比如黄色、白色
|
||||
short colorIdx = IndexedColors.YELLOW.getIndex();
|
||||
|
||||
// 创建下拉框的选项
|
||||
String[] options = new String[]{"男", "女", "未知"};
|
||||
|
||||
//对文件进行校验,标注
|
||||
try (FileInputStream fileIn = new FileInputStream(source);
|
||||
Workbook workbook = new XSSFWorkbook(fileIn)) {
|
||||
//在指定单元格上添加背景黄色+标注提示信息
|
||||
PoiUtil.addComment(workbook, 0, r, c, fontSize, colorIdx, "此单元格应该是非空的!");
|
||||
//添加下拉框校验
|
||||
PoiUtil.addValidation(workbook, 0, options, 4, 21, c - 1, c - 1);//范围
|
||||
// 保存
|
||||
FileOutputStream fileOut = new FileOutputStream(source);
|
||||
workbook.write(fileOut);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package UnitTest.ImportExcel;
|
||||
|
||||
import com.aspose.cells.*;
|
||||
import com.dsideal.QingLong.Util.AsposeUtil;
|
||||
|
||||
public class AsposeAddCommet {
|
||||
//工作目录
|
||||
public static String path = "D:\\dsWork\\QingLong\\src\\main\\resource\\Excel\\";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
//获取授权
|
||||
AsposeUtil.getLicense();
|
||||
// 打开现有的工作簿
|
||||
Workbook workbook = new Workbook(path + "\\1.xlsx");
|
||||
Worksheet sheet = workbook.getWorksheets().get(0);
|
||||
//添加新的批注
|
||||
CommentCollection comments = sheet.getComments();
|
||||
comments.clear();
|
||||
|
||||
int idx = comments.add(7, 3);
|
||||
Comment comment = comments.get(idx);
|
||||
//System.out.println(comment.getCommentShape().getFill());
|
||||
comment.setNote("我是内容");
|
||||
comment.setAuthor("黄海");
|
||||
comment.getFont().setName("黑体");
|
||||
// 设置批注的背景颜色为黄色
|
||||
// 保存工作簿
|
||||
workbook.save(path + "\\4.xlsx");
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package UnitTest.ImportExcel;
|
||||
|
||||
import com.aspose.cells.*;
|
||||
import com.dsideal.QingLong.Util.AsposeUtil;
|
||||
|
||||
public class AsposeAddXiaLaKuang {
|
||||
//工作目录
|
||||
public static String path = "D:\\dsWork\\QingLong\\src\\main\\resource\\Excel\\";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
//获取授权
|
||||
AsposeUtil.getLicense();
|
||||
// 打开现有的工作簿
|
||||
Workbook workbook = new Workbook(path+"\\1.xlsx");
|
||||
// 获取第一个工作表
|
||||
Worksheet worksheet = workbook.getWorksheets().get(0);
|
||||
// 创建下拉列表
|
||||
Validation validation = worksheet.getValidations().get(worksheet.getValidations().add());
|
||||
validation.setType(ValidationType.LIST);
|
||||
validation.setFormula1("男,女,未知"); // 设置下拉列表的选项
|
||||
// 设置下拉列表的范围
|
||||
CellArea area = new CellArea();
|
||||
area.StartRow = 1; // 从第2行开始
|
||||
area.EndRow = 29; // 到第30行结束
|
||||
area.StartColumn = 0; // 第一列
|
||||
validation.addArea(area);
|
||||
// 应用到工作表
|
||||
worksheet.getValidations().add(validation);
|
||||
// 保存工作簿
|
||||
workbook.save(path+"\\3.xlsx");
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
package UnitTest.ImportExcel.Util;
|
||||
package com.dsideal.QingLong.Util;
|
||||
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue