标签:公式 http 改变 label group 分享 class ack info
jxl的maven坐标:
<!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl -->
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
作为示例,我们新建按一个excel,它的第一个工作页内容如下:
其中,C2=A2+B2。(是两个数的和)
它的第二个工作页内容如下:
其中,A2=Sheet1!A2-Sheet1!B2。(是两个数的差)
我们接下来要做的事情是使用jxl修改Sheet1中A2和B2的值,然后查看Sheet1中C2和Sheet2中A2是否发生了改变。
Java代码:
package com.zifeiy.test.normal;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
public class Test20181218JxlModifyXls {
// main for test
public static void main(String[] args) throws IOException, WriteException, BiffException {
InputStream inputStream = new FileInputStream(new File("D:\\\\test.xls"));
Workbook workbook = Workbook.getWorkbook(inputStream);
WritableWorkbook writableWorkbook = Workbook.createWorkbook(new File("D:\\test_out.xls"), workbook);
WritableSheet writableSheet = writableWorkbook.getSheet(0);
WritableCell writableCell = writableSheet.getWritableCell(0, 1);
Label label = new Label(0, 1, "1");
writableSheet.addCell(label);
WritableCell writableCell2 = writableSheet.getWritableCell(0, 2);
Label label2 = new Label(1, 1, "2");
writableSheet.addCell(label2);
writableWorkbook.write();
writableWorkbook.close();
workbook.close();
}
}
可以看到,生成了一个test_out.xls文件,其内容如下:
可以看到,修改了参数之后,公示的结果也跟着改变了。
Java使用jxl修改现有Excel文件内容,并验证其是否对公式的结果产生影响
标签:公式 http 改变 label group 分享 class ack info
原文地址:https://www.cnblogs.com/zifeiy/p/10135936.html