📄 expdataagent.java
字号:
package bookselection;
import jade.core.Agent;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.sql.SQLException;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class ExpDataAgent extends Agent{
jdbcConn oc;
result r;
public static String outputFile = "e:\\订单.xls";
public void CreateExcel() {
try {
HSSFCell cell = null;
// 创建新的Excel 工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
// 在Excel工作簿中建一工作表,其名为缺省值
// 如要新建一名为"效益指标"的工作表,其语句为:
HSSFSheet sheet = workbook.createSheet("订单");
// HSSFSheet sheet = workbook.createSheet();
// 在索引0的位置创建行(最顶端的行)
HSSFRow row = sheet.createRow((short) 0);
//在索引0的位置创建单元格(左上端)
// HSSFCell cell = row.createCell((short) 0);
// 定义单元格为字符串类型
// cell.setCellType(HSSFCell.CELL_TYPE_STRING);
// 在单元格中输入一些内容
oc=new jdbcConn();
r=new result();
int j=0;
// HSSFRow row = sheet.createRow((short) 0);
for(int i=0;i<3;i++)
{
if(i==0)
{
cell = row.createCell((short) (i));
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("ISBN");
}
else if(i==1)
{
cell = row.createCell((short) (i));
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("书名");
}
else if(i==2)
{
cell = row.createCell((short) (i));
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("结果");
}
}
j++;
try
{
String Sql="SELECT * FROM result ";
if(oc.query(oc.con(), Sql))
{
//System.out.println("启动加工系统...");
//MachineStateFrame.MillingBufferState.setText("启动加工系统...");
oc.rs.beforeFirst();
// oc.rs.next();
while(oc.rs.next())
{
row = sheet.createRow((short) (j++));
for (int i = 0; i <3; i++) {
if(i==0)
{
cell = row.createCell((short) (i));
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(oc.rs.getString("ISBN"));
}
else if(i==1)
{
cell = row.createCell((short) (i));
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(oc.rs.getString("书名"));
}
else if(i==2)
{
cell = row.createCell((short) (i));
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(oc.rs.getString("结果"));
}
}
//
}
}
else{
System.out.println("没有要处理的结果记录!");
//
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
oc.closeMe();
// cell.setCellValue("sweater");
// 新建一输出文件流
FileOutputStream fOut = new FileOutputStream(outputFile);
// 把相应的Excel 工作簿存盘
workbook.write(fOut);
fOut.flush();
// 操作结束,关闭文件
fOut.close();
System.out.println("文件生成...");
JOptionPane.showMessageDialog(null,"生成订单!");
} catch (Exception e) {
System.out.println("已运行 xlCreate() : " + e);
}
}
protected void setup() {
System.out.println("Hello! ExpData-agent "+getAID().getName()+" is ready.");
DFAgentDescription dfd = new DFAgentDescription();
dfd.setName(getAID());
ServiceDescription sd = new ServiceDescription();
sd.setType("ExpData");
sd.setName("JADE-book-selection");
dfd.addServices(sd);
try {
DFService.register(this, dfd);
}
catch (FIPAException fe) {
fe.printStackTrace();
}
// myGui = new entryGui(this);
// myGui.show();
// POItest poi = new POItest();
ExpDataAgent poi =new ExpDataAgent();
//poi.CreateExcel();
poi.CreateExcel();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -