package skuPrice;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; public class JDSku { public static void main(String[] args) {
String[] strs = args;
String filename = strs[0];
String sheetname = strs[1];
getSkuPrice(filename,sheetname);
}
/**
* @author wk
* @date 2019/09/18
* @param fileName
* @param bookName
*/
public static void getSkuPrice(String fileName,String bookName){
System.out.println("进入解析价格方法..........");
InputStream input = null;
FileOutputStream output = null;
long start = System.currentTimeMillis();
try {
System.out.println("**********正在读取“"+fileName+".xlsx”文件**************");
input = new FileInputStream(new File("D:\\"+fileName+".xlsx"));
String skujson = "";
String skus = "";
XSSFWorkbook work = new XSSFWorkbook(input);
XSSFSheet sheet = work.getSheet(bookName);
int linenum = sheet.getLastRowNum();//获取excel
System.out.println(sheet.getLastRowNum());
int flag = 0;
try{
for (int i = 1; i <= linenum; i++) {//读取每一行数据
flag = i;
XSSFRow row = sheet.getRow(i);
short lastcellnum= row.getLastCellNum();
row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
skujson= row.getCell(7).getStringCellValue(); //获取包含sku的价格
skus = row.getCell(9).getStringCellValue(); //获取sku
System.out.println("EXPAND_INFO:"+skujson.toString());
JSONObject skuob = JSONArray.parseObject(skujson);
String pricestr = skuob.getString("price");
JSONObject pricejson = JSONArray.parseObject(pricestr);
String price= pricejson.getString(skus);
System.out.println(skus+"============"+price);
try{
row.createCell(lastcellnum+1, Cell.CELL_TYPE_STRING);
// row.getCell(15).setCellType(Cell.CELL_TYPE_STRING);
row.getCell(lastcellnum+1).setCellValue(price);
}catch (Exception e) {
e.printStackTrace();
continue;
}
}
}catch(Exception e){
output = new FileOutputStream(new File("D:\\"+fileName+"解析后文件.xlsx"));
work.write(output);//写入excel
System.out.println("解析到第"+(flag+1)+"行,部分解析成功,请重试.........");
e.printStackTrace();
}
output = new FileOutputStream(new File("D:\\"+fileName+"解析后文件.xlsx"));
work.write(output);//写入excel
long end = System.currentTimeMillis();
long use = (end-start)/60000;
System.out.println("*********SUCCESS*********");
System.err.println("共用时:"+use+"分钟");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}

POI 读取Excel文件 并解析JSON数据的更多相关文章

  1. 项目一:第四天 1、快递员的条件分页查询-noSession,条件查询 2、快递员删除(逻辑删除) 3、基于Apache POI实现批量导入区域数据 a)Jquery OCUpload上传文件插件使用 b)Apache POI读取excel文件数据

    1. 快递员的条件分页查询-noSession,条件查询 2. 快递员删除(逻辑删除) 3. 基于Apache POI实现批量导入区域数据 a) Jquery OCUpload上传文件插件使用 b) ...

  2. JAVA使用POI读取EXCEL文件的简单model

    一.JAVA使用POI读取EXCEL文件的简单model 1.所需要的jar commons-codec-1.10.jarcommons-logging-1.2.jarjunit-4.12.jarlo ...

  3. 使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10

    使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10 [问题点数:40分,结帖人xieyongqiu]             不显示删除回复             ...

  4. POI 读取Excel文档中的数据——兼容Excel2003和Excel2007

    Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. HSSF - 提供读写Microsoft Exce ...

  5. Java实现POI读取Excel文件,兼容后缀名xls和xlsx

    1.引入所需的jar包: maven管理项目的话直接添加以下坐标即可: <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -- ...

  6. 使用POI读取excel文件内容

    1.前言 项目中要求读取excel文件内容,并将其转化为xml格式.常见读取excel文档一般使用POI和JExcelAPI这两个工具.这里我们介绍使用POI实现读取excel文档. 2.代码实例: ...

  7. spring boot 使用 POI 读取Excel文件

    内容简介 本文主要介绍使用POI进行Excel文件的相关操作,涉及读取文件,获取sheet表格,对单元格内容进行读写操作,以及合并单元格的操作. Excel文件目录 Excel模板文件存了resour ...

  8. 使用jxl,poi读取excel文件

    作用:在java后台添加一个方法,读取导入的excel内容,根据需要返回相应的sql语句,以完成对临时表的插入操作. 使用jxl读取excel文件 package com.sixthf.bi.sapp ...

  9. jspsmart(保存文件)+poi(读取excel文件)操作excel文件

    写在前面: 项目环境:jdk1.4+weblogic 需求:能上传excel2003+2007 由于项目不仅需要上传excel2003,还要上传excel2007,故我们抛弃了jxl(只能上传exce ...

随机推荐

  1. 使用NB Exploit Kit攻击的APT样本分析——直接看流程图,就是网页挂马,利用java和flash等漏洞来在你主机安装和运行恶意软件

    使用NB Exploit Kit攻击的APT样本分析 from:https://cloud.tencent.com/developer/article/1092136 1.起因 近期,安恒工程师在某网 ...

  2. discuz x3.3标题的最少字数限制设置方法

    Discuz帖子标题默认字数最多是80个字节,却没有最少的字节限制.最近看到很多站长想限制一下帖子标题最少字数,不管是利于seo,还是禁止灌水,都有必要.为此把设置方法发上来分享. 1.找到并打开st ...

  3. python应用-表格式输出一组数据

    def main(): names=['关羽','张飞','赵云','马超','貂蝉'] subjects=['语文','数学','Python'] table=[[0 for _ in range( ...

  4. python + redis +ipset实现IP黑名单的动态添加及解封禁

    1.抽空用python做了一个 动态添加/删除IP黑名单 的程序(或者说实现方案),项目地址: https://gitee.com/lowmanisbusy/ip_blacklists, 2.这里的实 ...

  5. 在swift项目中若要通过pod引入第三方的swift项目,必须加上use_frameworks!

    因为swift没法打.a https://www.jianshu.com/p/ac629a1cb8f5

  6. Async/await promise实现

    An async function can contain an await expression that pauses the execution of the async function an ...

  7. Codeforces 484 E. Sign on Fence

    [传送门] 题意就是给一排围栏,每个围栏都有一个高度,查询区间$\left[l, r\right]$之间长度为$w$的子区间的最小高度的最大值.首先,这个最大值肯定是这个区间里的围栏的某个高度,如果是 ...

  8. (0)开始 Raspberry Pi 项目前需要知道的 10 件事

    https://www.digikey.cn/zh/articles/techzone/2017/feb/10-things-to-know-before-starting-a-raspberry-p ...

  9. OKR究竟适不适合国内企业?

    某天见到知乎上有人提问,OKR在中国能行的通吗?细看下面的回复,多数人觉得大部分企业都是不适合的,他们认为让普通员工主动付出努力去达到更高的要求是不可能的,并且公司环境也不适合OKR的推行.但我却有不 ...

  10. chart.xkcd 可绘制粗略,开通,手绘样式的图表库

    chart.xkcd 可以用来绘制手绘样式的图表,使用简单,样式也挺好看 简单使用 代码 index.html <!DOCTYPE html> <html lang="en ...