You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
2 years ago
|
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();
|
||
|
|
||
|
//对文件进行校验,标注
|
||
|
try (FileInputStream fileIn = new FileInputStream(source);
|
||
|
Workbook workbook = new XSSFWorkbook(fileIn)) {
|
||
|
//在指定单元格上添加背景黄色+标注提示信息
|
||
|
PoiUtil.addComment(workbook, 0, r, c, fontSize, colorIdx, "此单元格应该是非空的!");
|
||
|
// 保存
|
||
|
FileOutputStream fileOut = new FileOutputStream(source);
|
||
|
workbook.write(fileOut);
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|