java向excel写数据

package pymongo1;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class out_put {
// String device_name;
// String MacDevice_mip;
// String Interface_name;
// String TopoLink_dataFlag;
// String device2_name;
// String MacDevice2_mip;
// String Media_uniName;
// String path;
//
// public int j;
// public int k;

public void out_put(){}

public static void out1(databean data,String path,int k,int j) throws IOException, RowsExceededException, WriteException
{
String device_name=data.device_name;
String MacDevice_mip=data.MacDevice_mip;
String Interface_name=data.Interface_name;
String TopoLink_dataFlag=data.TopoLink_dataFlag;
String device2_name=data.device2_name;
String MacDevice2_mip=data.MacDevice2_mip;
String Media_uniName=data.Media_uniName;

//创建工作薄

File file=new File(path);
if(!file.exists())
{
file.createNewFile();

}
WritableWorkbook workbook = Workbook.createWorkbook(file);
//创建新的一页
WritableSheet sheet = workbook.createSheet("NG7.0topo",0);
//创建要显示的内容,创建一个单元格,第一个参数为列坐标,第二个参数为行坐标,第三个参数为内容
if (k==0){
Label column1 = new Label(0,0,"device_name");
sheet.addCell(column1);
Label column2 = new Label(1,0,"MacDevice_mip");
sheet.addCell(column2);
Label column3 = new Label(2,0,"Interface_name");
sheet.addCell(column3);
Label column4 = new Label(3,0,"TopoLink_dataFlag");
sheet.addCell(column4);
Label column5 = new Label(4,0,"device2_name");
sheet.addCell(column5);
Label column6 = new Label(5,0,"MacDevice2_mip");
sheet.addCell(column6);
Label column7 = new Label(6,0,"Media_uniName");
sheet.addCell(column7);
k++;
}
// 心累 没想到输出excel竟然是个大坑 。。。。。。。。。。。。。
int i=0;
Label column11 = new Label(i,j,device_name);
sheet.addCell(column11);
System.out.println(i);
System.out.println(device_name);
i++;
Label column21 = new Label(i,j,MacDevice_mip);
sheet.addCell(column21);
i++;
Label column31 = new Label(i,j,Interface_name);
sheet.addCell(column31);
i++;
Label column41 = new Label(i,j,TopoLink_dataFlag);
sheet.addCell(column41);
i++;
Label column51 = new Label(i,j,device2_name);
sheet.addCell(column51);
i++;
Label column61 = new Label(i,j,MacDevice2_mip);
sheet.addCell(column61);
i++;
Label column71 = new Label(i,j,Media_uniName);
sheet.addCell(column71);
j++;
System.out.println(i);

System.out.println(j);

workbook.write();
workbook.close();

}

}

posted on 2016-09-14 16:00  猫儿爹  阅读(1839)  评论(0编辑  收藏  举报

导航