⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
package net.aetherial.gis.excel;

import java.io.*;
import jxl.*;
import jxl.write.*;
import java.util.*;

public class Test {
  private String filePath = "";
  jxl.write.WritableWorkbook wwb = null;
  private jxl.write.WritableCell wc = null;
  public String[] number = null, name = null, lat = null, lon;
  public int page = 1;
  public Test(String filePath) {
    this.filePath = filePath;
    try {
      wwb = Workbook.createWorkbook(new File(
          filePath), this.readStandard(
          "D:\\GIS\\Excel\\standard\\standard1.xls"));

    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void setNumber(String[] number) {
    this.number = number;
  }

  public void setName(String[] name) {
    this.name = name;
  }

  public void setLatAndLon(String[] Latitude, String[] Longitude) {
    this.lat = Latitude;
    this.lon = Longitude;
  }

  public Workbook readStandard(String filePath) {
    Workbook wb = null;
    try {
      wb = Workbook.getWorkbook(new File(filePath));
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    return wb;
  }

  public void setWcContent(String str, WritableSheet ws) {
    if (wc.getType() == CellType.LABEL) {
      Label l = (Label) wc;
      l.setString(str);
    }
    else if (wc.getType() == CellType.NUMBER) {
      NumberFormat fourdps = new NumberFormat("####.####");
      WritableCellFormat wcf = new WritableCellFormat(fourdps);
      try {
        wcf.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
        jxl.write.Number number = new jxl.write.Number(wc.getColumn(),
            wc.getRow(), Double.parseDouble(str), wcf);
        ws.addCell(number);
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    Date d = new Date();
    if (wc.getRow() == 1) {
      Label l = (Label) wc;
      l.setString("______________市_____________县(区)______________乡________________村       道路类型:拟建/已建     编制日期:   " +
                  String.valueOf(d.getYear()) + "年ttt    月    日");
    }
  }

  public void createFile() {
    try {
      jxl.write.WritableSheet ws = wwb.getSheet(0);
      ws.setName("Page" + page);

      ExcelStandard es = new ExcelStandard();
      int[] stand = es.standardNumber(10);
      //这里还有分页没写
      for (int i = 0, j = 0; i < stand.length; ) {

        wc = ws.getWritableCell(stand[i], stand[i + 1]);
        this.setWcContent(this.number[j], ws);
        i++;
        i++;
        j++;
      }
      System.out.println("number OK!");

      stand = es.standardName(10);
      for (int i = 0, j = 0; i < stand.length; ) {
        wc = ws.getWritableCell(stand[i], stand[i + 1]);
        this.setWcContent(this.name[j], ws);
        i++;
        i++;
        j++;
      }
      System.out.println("name OK!");

      stand = es.standardValue(10);
      for (int i = 0, j = 0; i < stand.length; ) {

        wc = ws.getWritableCell(stand[i], stand[i + 1]);
        this.setWcContent(this.lat[j], ws);

        wc = ws.getWritableCell(stand[i], stand[i + 1] + 1);
        this.setWcContent(this.lon[j], ws);
        i++;
        i++;
        j++;
      }
      System.out.println("value OK!");

      wwb.write();
      wwb.close();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public boolean fenye(String[] number, String[] name, String[] lat,
                       String[] lon) {
    String[] writeNumber = new String[80], newNumber = null;
    if (number.length > 80) {
      //先写80个,再减去80;继续判断余下的是否大于80

      for (int i = 0; i < 80; i++) {
        writeNumber[i] = number[i];
      }
      this.setNumber(writeNumber);

      newNumber = new String[number.length - 80];
      for (int i = 0; i < newNumber.length; i++) {
        newNumber[i] = number[i + 80];
        page++;
      }
      return fenye(newNumber, newNumber, newNumber, newNumber);
    }
    else if (number.length == 80) {
      //正好写

      return true;
    }
    else {
      //添充写
      return true;
    }
  }

  public static void main(String args[]) {
    Test t = new Test("D:\\GIS\\Excel\\test.xls");

    String[] number = new String[80], name = new String[80],
        lat = new String[80], lon = new String[80];
    for (int i = 0; i < number.length; i++) {
      number[i] = "" + (i + 1);
      name[i] = "名称" + (i + 1);
      lat[i] = "123." + i + "00";
      lon[i] = "789." + i + "00";
    }
    t.setNumber(number);
    t.setName(name);
    t.setLatAndLon(lat, lon);
    t.createFile();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -