2019独角兽企业重金招聘Python工程师标准>>>

package cn.jiguang.base64;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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

/**
 * 
 * @Description: Excel自动导出txt,构建java代码
 * @Author: zengxiaochi
 *
 * @Date: 下午11:37:27
 */
public class ExcelExport {

public static void main(String[] args) {
        // TODO Auto-generated method stub
        String filepath = "sjd_pdl.xls";

excelOutTxt(filepath);
    }

private static void excelOutTxt(String filepath) {
        try {
            Workbook workbook = Workbook.getWorkbook(new File(filepath));
            Sheet sheet = workbook.getSheet("配置表");
            Sheet sheet2 = workbook.getSheet("模型逻辑");
            // rows为行数,columns列数,getCell("列号","行号")
            int rows = sheet2.getRows();
            int columns = sheet2.getColumns();
            Cell c2 = null;
            NumberCell numberCellOne = null;
            List<String> strList = new ArrayList<String>();
            List<Object> doubleList = new ArrayList<Object>();

// 用来记录要比较的字符串

List<String> storage = new ArrayList<String>();
            for (int i2 = 0; i2 < rows; i2++) {
                for (int j2 = 0; j2 < columns; j2++) {
                    // 根据横纵轴获取单元格数据
                    c2 = sheet2.getCell(j2, i2);
                    if (c2.getColumn() == 0) {
                        strList.add(c2.getContents());
                    } else if (c2.getColumn() == 1) {
                        if (CellType.NUMBER == c2.getType()) {
                            numberCellOne = (NumberCell) c2;
                            doubleList.add(numberCellOne.getValue());
                        } else {
                            doubleList.add(c2.getContents());
                        }
                    }

}
            }
            for (Object object : doubleList) {
                System.out.println(object);
            }
            System.out.println("==============");
            for (String str : strList) {
                System.out.println(str);
            }

File fileSuccess = new File("success.txt");
            FileWriter fwSuccess = new FileWriter(fileSuccess);
            BufferedWriter bwSuccess = new BufferedWriter(fwSuccess);

// j为行数,getCell("列号","行号")
            int j = sheet.getRows();
            int y = sheet.getColumns();
            Cell c = null;
            NumberCell numberCell = null;

for (int i = 0; i < j; i++) {
                StringBuffer stringBuffer = new StringBuffer();
                for (int x = 0; x < y; x++) {
                    c = sheet.getCell(x, i);
                    if (CellType.NUMBER == c.getType()) {
                        numberCell = (NumberCell) c;
                    }

if (c.getColumn() == 0) {
                        storage.add(c.getContents());
                        stringBuffer.append("antifraudSjdModelEntityList.add(new AntifraudSjdModelEntity( " + '"'
                                + c.getContents() + '"');
                    } else if (c.getColumn() == 1 || c.getColumn() == 2) {
                        continue;
                    } else if ("inf".equals(c.getContents())) {
                        stringBuffer.append(", " + "Double.MAX_VALUE");
                    } else if ("-inf".equals(c.getContents())) {
                        stringBuffer.append(", " + "-Double.MAX_VALUE");
                    } else if (c.getColumn() == 5) {
                        if (CellType.NUMBER == c.getType()) {
                            stringBuffer.append(", " + numberCell.getValue());
                        } else {
                            stringBuffer.append(", " + c.getContents());
                        }
                    } else if (c.getColumn() == 6) {
                        for (int k = 0; k < strList.size(); k++) {
                            if (storage.get(0).trim().equals(strList.get(k).trim())) {
                                stringBuffer.append(", " + doubleList.get(k) + "));");
                            }
                        }
                        storage.remove(0);
                    } else if ("".equals(c.getContents())) {
                        stringBuffer.append(", " + "null");
                    } else {
                        if (CellType.NUMBER == c.getType()) {
                            stringBuffer.append(", " + numberCell.getValue());
                        } else {
                            stringBuffer.append(", " + c.getContents());
                        }
                    }
                }

bwSuccess.write(stringBuffer.toString());
                bwSuccess.write(" ");
                bwSuccess.flush();
                // 读取一行后换行
                bwSuccess.newLine();
                // 刷新
            }
            System.out.println("写入结束");
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

转载于:https://my.oschina.net/u/3744350/blog/1609380

空间复杂度,实现从excel导出到txt文件中的java代码自动构建,逻辑条件不同实现则不同...相关推荐

  1. 如何避免JSP文件中的Java代码?

    本文翻译自:How to avoid Java code in JSP files? I'm new to Java EE and I know that something like the fol ...

  2. matlab怎么导出矩阵,如何将matlab中矩阵导出到txt文件中

    Excel Link是一个在Windows环境下实现Excel与Matlab进行链接的插件.通过连接Excel和Matlab,用户可以在Excel工作表空间和宏编程工具中使用Matlab的数值计算,图 ...

  3. jsp文件里java代码的作用_如何使用JSP 2避免JSP文件中的Java代码?

    小编典典 自从2001年标签库(例如JSTL)和EL(表达语言,那些东西)的诞生以来,在JSP中确实不建议使用scriptlet(那些东西).${} scriptlet的主要缺点是: 可重用性:您无法 ...

  4. java 文件 字符串_java将字符串写入到txt文件中

    将字符串写入到txt文件中import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundExceptio ...

  5. 基于python处理excel大量数据并导出至txt文件

    实现功能:Excel文件中有一万个数据,根据第一列字段分类,相同字段下第四列数值进行求和,并将字段和和值一并导出至一个txt文件中. 用到的库函数有xlrd,只需要读excel就行了.上代码: imp ...

  6. Angular导出功能(excel导出功能、文件数据流导出功能、图片的下载导出功能)

    Angular导出功能(excel导出功能.文件数据流导出功能.图片的下载导出功能) 场景1:(直接返回网络地址进行导出的excel) 后台返回的是 : "http://192.168.0. ...

  7. 用python将txt文件中的内容导入到excel文件中

    背景 日志文件中的内容不方便阅读统计,需要用excel表格的形式显示出来 日志文件内容如下: info***LCAM_SC.DM_RP_DIS_DEVICE_TEMP*1*1*0*0*0*0*N*Y* ...

  8. 将SQL Server表导出为txt文件

    方法-:用BCP命令 bcp 实用工具 Sqlclub.cn bcp 实用工具在 Microsoft® SQL Server™ 2000 实例和数据文件之间以用户指定的格式复数据. 语法 Sqlclu ...

  9. 从word、wps、excel、pdf和txt文件中查找文本的工具

    从word.wps.excel.pdf和txt文件中查找文本的工具. 因工作中要经常从大量word文档中查找固定的文本,所以自己就做了本工具. 可以批量从doc.docx.wps.xls.xlsx.p ...

最新文章

  1. Java项目:网上书城+后台管理系统(java+jsp+servlert+mysql+ajax)
  2. 淘淘商城FTP服务器、Redis和solr集群配置
  3. 网站优化离不开内容更新
  4. 2020年应届生找工作难?Python爬虫解析疫情之下用人市场中的机遇与挑战
  5. 【今晚8点半】:对话袁家军——成都的多媒体圈
  6. Socket通信---网络通信学习笔记(一)
  7. WeScale 技术篇 —— mpvue 与微信小程序的火花
  8. 光线跟踪是什么? 光能传递(radiosity lighting)是什么?
  9. android 设置editext只能输入数字
  10. C语言反汇编 - 函数与结构体
  11. 基于matlab人脸识别论文,基于matlab的人脸识别系统设计 毕业论文
  12. 51单片机温度控制调速风扇仿真设计
  13. 战神笔记本安装win7,解决USB3.0、核显驱动、独显驱动
  14. 通过银行卡号查询银行卡类型接口
  15. centos修改键盘布局
  16. Python开发培训怎么样?
  17. 【转】基金入门:如何买基金?
  18. PG数据库源码-SysCache部分匹配机制
  19. 3D Fe3O4@Au@Ag nanoflowers assembled magnetoplasmonic chains for in situ SERS monitoring of plasmon-
  20. java对对碰游戏设计报告_手把手带你用Java打造一款对对碰游戏(下篇)

热门文章

  1. jmeter 通过ant集成到jenkins
  2. SharePoint 上传附件
  3. JavaScript开发工具--Aptana
  4. Netty工作笔记0058---Netty群聊系统客户端
  5. Netty工作笔记0035---Reactor模式图剖析
  6. SpringCloud学习笔记018---SpringBoot前后端分离_集成_SpringSecurity_简单实现
  7. android学习笔记---37_采用广播接收者实现系统短信操作_获取短信_收发短信等
  8. Android异常总结---W/System.err(661): java.lang.IllegalStateException: End of document.
  9. linux快速删除海量文件
  10. NOX的使用之学习篇【三】