查询通话详单

news/2025/2/12 16:36:55/

j题目来源:牛客网编程之美栏目

登录中国联通网上营业厅 /电信/移动    后选择「自助服务」 --> 「详单查询」,然后选择你要查询的时间段,点击「查询」按钮,查询结果页面的最下方,点击「导出」,就会生成类似于 2017年01月01日~2017年01月31日通话详单.xls 文件。写代码,对每月通话时间做个统计。

使用jxl.jar包读取excel数据
CallTimeCount类
public class CallTimeCount {public static void main(String[] args){ReadExcel readExcel = new ReadExcel("C:\\Users\\CAD\\Desktop\\telephonefee.xls");System.out.print("主叫通话时长:");readExcel.countTime(readExcel.getCallingTime());System.out.println("  通话次数:" + readExcel.getCallingInt());System.out.print("被叫通话时长:");readExcel.countTime(readExcel.getCalledTime());System.out.println("  通话次数:" + readExcel.getCalledInt());System.out.print("总通知时长: " + readExcel.outputTimeCnt());}
}

  

ReadExcel类
import jxl.*;
import java.io.*;
import java.util.*;public class ReadExcel {private int callingInt = 0;  //主叫次数private int calledInt = 0;  // 被叫次数private List<String> callingTime;  // 主叫时长private List<String> calledTime;  // 被叫时长private int day = 0;private int hour = 0;private int minute = 0;private int second = 0;// 读取表格中内容public ReadExcel(String filePath){callingTime = new ArrayList<>();calledTime = new ArrayList<>();Workbook readwb = null;try{// 构建Workbook对象,只读Workbook对象// 直接从本地文件创建WorkbookInputStream inStream = new FileInputStream(filePath);readwb = Workbook.getWorkbook(inStream);// Sheet下标从0开始,获取第一张sheet表Sheet readSheet = readwb.getSheet(0);// 获取Sheet表中的总列数,总行数int cntColumns = readSheet.getColumns();int cntRows = readSheet.getRows();// 获取单元格的对象引用for(int i = 1;i  < cntRows; i++){  //跳过第一行表格内容头for(int j = 0; j < cntColumns; j++){Cell cell = readSheet.getCell(j,i);if(j == 2){if(cell.getContents().equals("主叫")){  //  主叫统计callingInt++;callingTime.add(readSheet.getCell(j + 2,i).getContents());}else {  // 被叫统计calledInt++;calledTime.add(readSheet.getCell(j + 2,i).getContents());}}}}}catch (Exception e){e.printStackTrace();}finally{readwb.close();}}// 输出呼叫次数以及各自的时长public void countTime(List<String> time){int ad = 0,ah = 0,am = 0,as = 0;String res = "";for(String s : time){int indexOfHour = s.indexOf("时");int indexOfMinute = s.indexOf("分");int indexOfSecond = s.indexOf("秒");if(indexOfHour > 0){ah += Integer.parseInt(s.substring(0,indexOfHour));if(ah > 24){ah %= 24;ad++;day++;}}if(indexOfMinute > 0){am += Integer.parseInt(s.substring(indexOfHour + 1,indexOfMinute));if(am > 59){am %= 60;ah++;}}if(indexOfSecond > 0){as += Integer.parseInt(s.substring(indexOfMinute + 1,indexOfSecond));if(as > 59){as %= 60;am++;}}}if(ad > 0)res += ad + "天";if(ah > 0)res += ah + "时";res += am + "分" + as + "秒";System.out.print(res);hour += ah;minute += am;second += as;}public String outputTimeCnt(){String res = "";if(day > 0)res += day + "天";res += hour + "时" + minute + "分" + second + "秒";return res;}public int getCallingInt() {return callingInt;}public int getCalledInt() {return calledInt;}public List<String> getCallingTime() {return callingTime;}public List<String> getCalledTime() {return calledTime;}public int getDay() {return day;}public int getHour() {return hour;}public int getMinute() {return minute;}public int getSeoncd() {return second;}
}
表格样式:
 
运行结果:
 
参考链接:
1.  Java解释Excel数据(jxl.jar包的使用)
2. JAVA操作Excel文件 

转载于:https://www.cnblogs.com/coding-wtf/p/6283800.html


http://www.ppmy.cn/news/862595.html

相关文章

2023/7/13 platform实现中断,led,终端输出变量

platform驱动实现 1.使用驱动代码实现如下要求 a.应用程序通过阻塞的io模型来读取number变量的值 b.number是内核驱动中的一个变量 c.number的值随着按键按下而改变&#xff08;按键中断) 例如number0按下按键number1 ,再次按下按键numberOd .在按下按键的时候需要同时将led1…

MySQL数据库表数据的基本操作

目录 1.创建表 2.插入数据 3.修改表数据 3.1、将所有员工薪水修改为5000元 ​3.2、将姓名为张三的员工薪水修改为3000元 ​3.3、将姓名为李四的员工薪水修改为4000元gender改为女 ​3.4、将王五的薪水在原有基础上增加1000元 4、MySQL字符集 1.创建表 创建员工表emplo…

渗透测试 ( 3 ) --- Metasploit Framework ( MSF )

白嫖 Metasploit Pro 2022&#xff1a;https://zhuanlan.zhihu.com/p/449836479 白嫖 Metasploit Pro 2022&#xff1a;http://t.zoukankan.com/hxlinux-p-15787814.html 好东西之 metasploit pro&#xff1a;https://www.52pojie.cn/thread-1586222-1-1.html Metasploit Pro 英…

Ubuntu 8.04 优化设置

文章中部分TIGER修改Ubuntu 8.04 LTS(长期支持版)免费光盘已经接受预定! https://shipit.ubuntu.com/ 有刻录机的最好自己刻盘,体谅人家.总纲&#xff1a;分以下几部分工作 (更新截至4月27日&#xff0c;决定停止更新&#xff0c;文章写长了就没意思了&#xff0c;眼花&#xf…

Qt/C++编写物联网管理平台21-探测器管理

一、前言 探测器在整个系统中是最核心的关键的硬件&#xff0c;终端节点硬件&#xff0c;安装有探测芯片装置&#xff0c;负责探测前端对应气体浓度&#xff0c;并记录值&#xff0c;等待控制器轮训数据回复&#xff0c;控制器信息表也是字段最多的&#xff0c;要存储位号、控…

ZOOM H1n录音笔怎么连接电脑做音频输入麦克风【教程】

一、ZOOM 录音笔连接电脑做音频输入麦克风&#xff0c;以H1n为例 以前试过用usb连接&#xff0c;但是发现音质不对。又试过用公对公3.5mm接头连接电脑麦口和录音笔耳机输出口&#xff0c;一顿操作猛如虎&#xff0c;一听音质超级糊。 因为买的不是国行 &#xff08;不知道有没…

A40i T3开发板外扩接口的功能测试

A40i T3 开发板功能测试 硬件平台&#xff1a;飞凌嵌入式OKA40i-C/OKT3-C开发板&#xff0c; 基于国产芯片 A40i&#xff08;工业级&#xff09; T3&#xff08;车规级&#xff09;设计研发。 此章节主要说明A40i T3开发板外扩接口的使用方法。本章节测试所用到的测试程序在飞…

ubuntu设置全攻略

说明&#xff0c;本文档根据网上的文档修改而成&#xff0c;凡是经过自己实践的都做了修改。 硬盘安装&#xff1a; 将iso文件和wubi.exe(从iso中解压出来的)两个文件放到任意同一目录下&#xff0c;在windows下点击wubi.exe即可完成安装&#xff0c; 它将把ubuntu安装在windo…