Excel(4) : 修改xls
程序员文章站
2022-04-17 15:54:13
...
参考 : https://blog.csdn.net/weixin_42394206/article/details/114055674
maven坐标
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
import jxl.Workbook;
import jxl.write.*;
import java.io.File;
public class ExcelUtil {
private static final File file = new File("/Users/ly/files/t1.xls");
public static void main(String[] args) {
modifyExcel(0, 1, 1, "修改111");
}
public static void modifyExcel(int SheetNo, int lieshu, int hangshu, String value) {
try {
Workbook rwb = Workbook.getWorkbook(file);
WritableWorkbook wwb = Workbook.createWorkbook(file, rwb);// copy
WritableSheet ws = wwb.getSheet(SheetNo);
WritableFont font = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.NO_BOLD);
WritableCellFormat format = new WritableCellFormat(font);
Label labelCF = new Label(lieshu, hangshu, value, format);
ws.addCell(labelCF);
wwb.write();
wwb.close();
rwb.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println("您是否打开了excel文件!请关闭后再试。");
}
}
}
上一篇: Springboot-修改项目启动端口