main
黄海 2 years ago
parent ac0ac6ffad
commit 288ed7e84b

@ -5,7 +5,7 @@ import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import com.dsideal.QingLong.Util.AsposeUtil;
public class AsposeAddColumn {
public class AddColumn {
public static String path = "D:\\dsWork\\QingLong\\src\\main\\resource\\Excel\\";

@ -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");
}
}

@ -1,5 +1,9 @@
package UnitTest.ImportExcel.Bean;
/**
import com.aspose.cells.*;
import com.dsideal.QingLong.Util.AsposeUtil;
/**
* vo
*/
public class CellBean {
@ -31,5 +35,59 @@ package UnitTest.ImportExcel.Bean;
public void setType(String type) {
this.type = type;
}
public static 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");
}
}
public static 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");
}
}
}

@ -1,7 +1,7 @@
package UnitTest.ImportExcel;
import UnitTest.ImportExcel.Bean.CellBean;
import UnitTest.ImportExcel.Util.ChineseCharacterUtil;
import com.dsideal.QingLong.Util.ChineseCharacterUtil;
import com.jfinal.kit.Kv;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;

@ -1,4 +1,4 @@
package UnitTest.ImportExcel.Util;
package com.dsideal.QingLong.Util;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;

@ -1,15 +1,9 @@
package UnitTest.ImportExcel;
package com.dsideal.QingLong.Util;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class TestTitle {
public class PoiUtil {
/**
*
*
@ -86,59 +80,4 @@ public class TestTitle {
// 应用数据验证到单元格
sheet.addValidationData(validation);
}
//工作目录
public static String path = "D:\\dsWork\\QingLong\\src\\main\\resource\\Excel\\";
public static CellStyle getStyle(Workbook wb) {
// 创建单元格样式
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
// 创建字体样式
Font font = wb.createFont();
font.setFontName("宋体");//字体
font.setBold(true);//加粗
font.setFontHeightInPoints((short) 12);//字号
style.setFont(font);
// 设置背景颜色
short colorIdx = 13;
style.setFillForegroundColor(colorIdx);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
return style;
}
public static void main(String[] args) throws Exception {
//学校上传的Excel
String filePath = path + "1.xlsx";
String filePath2 = path + "2.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(filePath);
Workbook workbook = new XSSFWorkbook(fileIn)) {
//在指定单元格上添加背景黄色+标注提示信息
addComment(workbook, 0, r, c, fontSize, colorIdx, "此单元格应该是非空的!");
//添加下拉框校验
addValidation(workbook, 0, options, 4, 21, c - 1, c - 1);//范围
// 保存
FileOutputStream fileOut = new FileOutputStream(filePath);
workbook.write(fileOut);
} catch (IOException e) {
e.printStackTrace();
}
}
}

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save