zoukankan      html  css  js  c++  java
  • 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();

    }

    }

  • 相关阅读:
    Java面试:用set集合的时候,重写过hashcode()和equal()方法吗?有什么作用?
    Bootstrap起步
    Java NIO
    Dobbo和SpringCloud区别
    Java虚拟机类加载机制和双亲委派模型
    继承和组合的特点和区别
    LinkedList和ArrayList底层原理
    聚集索引和非聚集索引
    Stream和迭代器的区别
    悲观锁和乐观锁
  • 原文地址:https://www.cnblogs.com/luo-mao/p/5872581.html
Copyright © 2011-2022 走看看