读excel

来源:互联网 发布:软件销售是什么职位 编辑:程序博客网 时间:2024/06/04 23:58

之前没想到写个程序转换下,手动写了大约1个多小时,还有很多没写完,实在是写不下去才。。。。。。

之前怕写程序浪费时间,没想到手写更浪费时间,写程序才花一个多小时就全部搞定了,

似乎像这种重复的工作最好是用程序完成,吸取教训。。。。。。

 

 

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

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class create {
 public static void main(String[] args) {
  
  
  File f = new File("f://企業間詳細スケジュール.xls");
  Workbook wb;
  try {
   wb = Workbook.getWorkbook(f);
   Sheet s = wb.getSheet("Sheet2");
   createNodes(s);
   //createCase(s);

  } catch (BiffException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }
 
 public static void createCase(Sheet s){
  int row = s.getRows();
  String outputNodes="";
  String menuMn = "興人 再変換起動";
  String menuId = s.getCell(11, 0).getContents();
  outputNodes += "case /"" + menuMn + "/":/n"
  + "    open_window(/"" + menuId + "Form/", /"MP.Kikan.Edi." + menuId.substring(0,6)
  + "/", /"MP.Kikan.Edi." + menuId.substring(0,6) + "." + menuId + ".WinUI." + menuId + "Form/");/n" + "    break;/n";
  for (int i = 1; i < row; i++) {
   if(!"1".equals(s.getCell(5, i).getContents())){
    i++;
    continue;
   }
   if(!menuMn.equals(s.getCell(11, i).getContents())){
    menuId = s.getCell(11, i).getContents();
    menuMn = s.getCell(4, i).getContents();
    outputNodes += "case /"" + menuMn + "/":/n"
    + "    open_window(/"" + menuId + "Form/", /"MP.Kikan.Edi." + menuId.substring(0,6)
    + "/", /"MP.Kikan.Edi." + menuId.substring(0,6) + "." + menuId + ".WinUI." + menuId + "Form/");/n" + "    break;/n";
   }
   i++;
  }
  System.out.println(outputNodes);
 }
 public static void createNodes(Sheet s){

  String rank1 = "興人";
  String rank2 = "興人 再変換";
  String rank3 = "興人 再変換起動";
  String outputNodes="";
  outputNodes += "this.trvMenu.Nodes[3].Nodes.Add(/"" + rank1  + "/");/n";
  outputNodes += "this.trvMenu.Nodes[3].Nodes[" + 0 +"].Nodes.Add(/"" + rank2 + "/");/n";

  int row = s.getRows();
  int j = 0;
  int k = -1;
  int l = 0;
  
  for (int i = 1; i < row; i++) {
   if(!"1".equals(s.getCell(5, i).getContents())){
    i++;
    continue;
   }
   if(!rank1.equals(s.getCell(0, i).getContents())){
    rank1 = s.getCell(0, i).getContents();
    outputNodes += "this.trvMenu.Nodes[3].Nodes.Add(/"" + rank1  + "/");/n";
    j++;
    k = -1;
   }
   if(!rank2.equals(s.getCell(2, i).getContents())){
    rank2 = s.getCell(2, i).getContents();
    outputNodes += "this.trvMenu.Nodes[3].Nodes[" + j +"].Nodes.Add(/"" + rank2 + "/");/n";
    k++;
    l = 0;
   }
   

   rank3 = s.getCell(4, i).getContents();
   if(k==-1) k=0;
   outputNodes += "this.trvMenu.Nodes[3].Nodes["+ j +"].Nodes[" + k + "].Nodes.Add(/""+ rank3+"/");/n";
   outputNodes += "this.trvMenu.Nodes[3].Nodes["+ j +"].Nodes[" + k + "].Nodes[" + l + "].NodeFont = DISABLE_ITEM_FONT;/n";
   outputNodes += "this.trvMenu.Nodes[3].Nodes["+ j +"].Nodes[" + k + "].Nodes[" + l + "].ForeColor = Color.Blue;/n";
   i++;
   l++;
  }

  System.out.println(outputNodes);
 }
}

原创粉丝点击