📄 jexcel.java
字号:
package myprojects.monitor;
import java.io.File;
import jxl.Workbook;
import jxl.write.WritableWorkbook;
import jxl.write.WritableSheet;
import jxl.write.WritableCell;
import jxl.write.Label;
import jxl.write.WriteException;
import java.io.IOException;
public class Jexcel {
private WritableWorkbook workbook;
private WritableSheet sheet;
public Jexcel(String name) throws IOException,WriteException
{
String excelName = name+".xls";
workbook =
Workbook.createWorkbook(new File(excelName));
sheet = workbook.createSheet("sheet1",0);
Label A=new Label(0,0,"Time");
Label B=new Label(1,0,"Temperature");
Label C=new Label(2,0,"H2S");
Label D=new Label(3,0,"CO3");
Label E=new Label(4,0,"PH");
sheet.addCell(A);
sheet.addCell(B);
sheet.addCell(C);
sheet.addCell(D);
sheet.addCell(E);
}
//add data into the sheet:
public void save(String time,String temperature,String H2S,String SO4,
String PH,int rowNumber)
throws WriteException
{
Label A=new Label(0,rowNumber,time);
Label B=new Label(1,rowNumber,temperature);
Label C=new Label(2,rowNumber,H2S);
Label D=new Label(3,rowNumber,SO4);
Label E=new Label(4,rowNumber,PH);
this.sheet.addCell(A);
this.sheet.addCell(B);
this.sheet.addCell(C);
this.sheet.addCell(D);
this.sheet.addCell(E);
}
//write the data into the workbook and close it to free up memory:
public void close()throws IOException, WriteException
{
this.workbook.write();
this.workbook.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -