当前位置: 首页 > wzjs >正文

wordpress侧边栏登录注册西安优化网站推广

wordpress侧边栏登录注册,西安优化网站推广,局域网小网站网站建设软件,好动词做的网站能行吗在Java中读取Excel文件并检查某个字段是否为金额格式,可以使用Apache POI库来操作Excel文件。Apache POI提供了对Microsoft Office格式文件(如Excel)的读写支持。下面,我将指导你如何使用Apache POI来读取Excel文件,并…

在Java中读取Excel文件并检查某个字段是否为金额格式,可以使用Apache POI库来操作Excel文件。Apache POI提供了对Microsoft Office格式文件(如Excel)的读写支持。下面,我将指导你如何使用Apache POI来读取Excel文件,并检查特定列中的值是否符合金额格式。

步骤 1: 添加Apache POI依赖

首先,确保你的项目中包含了Apache POI的依赖。如果你使用Maven,可以在pom.xml文件中添加以下依赖:


<!-- Apache POI for Excel --><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>5.2.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.2</version></dependency>

步骤 2: 读取Excel文件

接下来,使用Apache POI来读取Excel文件中的数据。以下是一个示例代码,展示如何读取一个Excel文件中的数据:


import org.apache.poi.ss.usermodel.*;import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.File;import java.io.FileInputStream;import java.text.DecimalFormat;import java.util.regex.Pattern;public class ExcelReader {public static void main(String[] args) {try (FileInputStream fis = new FileInputStream(new File("path/to/your/excel/file.xlsx"));Workbook workbook = new XSSFWorkbook(fis)) {Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表for (Row row : sheet) {Cell cell = row.getCell(1); // 假设金额在第二列(列索引为1)if (cell != null) {String cellValue = getCellValueAsString(cell); // 获取单元格的值作为字符串if (isAmountFormat(cellValue)) { // 检查是否为金额格式System.out.println("Amount found: " + cellValue);} else {System.out.println("Not an amount: " + cellValue);}}}} catch (Exception e) {e.printStackTrace();}}private static String getCellValueAsString(Cell cell) {DataFormatter formatter = new DataFormatter();return formatter.formatCellValue(cell);}private static boolean isAmountFormat(String value) {// 使用正则表达式检查金额格式,例如:123,456.78或123456.78或123456等String amountPattern = "^\\d{1,3}(,\\d{3})*(\\.\\d{1,2})?$"; // 允许千位分隔符和两位小数return Pattern.matches(amountPattern, value.replace(",", "")); // 先移除千位分隔符再进行匹配}}

说明:

  1. 读取Excel文件:使用FileInputStreamWorkbook类来读取Excel文件。
  2. 获取单元格值:使用DataFormatter来格式化单元格的值,使其更适合阅读。
  3. 检查金额格式:通过正则表达式来检查字符串是否符合金额格式。这里我们允许数字、逗号(作为千位分隔符)、和最多两位小数。注意,我们先将逗号替换为空,再进行匹配。

另外,正则表达式也可以修改处理多种情况:

  比如几位小数、是否允许千分符等

public static boolean isAmountFormat(String value) {// 使用正则表达式检查金额格式,例如:123,456.78或123456.78或123456等String amountPattern = "^(\\d{1,3}(,\\d{3})*|\\d+)(\\.\\d{1,2})?$|^\\d+$"; // 允许千位分隔符和两位小数
//String amountPattern1  =      "^(\\d{1,3}(,\\d{3})*|\\d+)(\\.\\d{2})?$"return Pattern.matches(amountPattern, value); // 先移除千位分隔符再进行匹配}public static void main(String[] args) {boolean amountFormat1 = isAmountFormat("123,456.78");boolean amountFormat2 = isAmountFormat("13.13");boolean amountFormat3 = isAmountFormat("1000.13");boolean amountFormat4 = isAmountFormat("1,000.13");boolean amountFormat5 = isAmountFormat("5");boolean amountFormat6 = isAmountFormat("5.00");boolean amountFormat7 = isAmountFormat("0.50");boolean amountFormat8 = isAmountFormat("0.501");boolean amountFormat9 = isAmountFormat(".50");boolean amountFormat10 = isAmountFormat("1,23");boolean amountFormat11 = isAmountFormat("1,234.001");boolean amountFormat12 = isAmountFormat("1,234.8");System.out.println(amountFormat1+"......."+amountFormat2+"......."+amountFormat3+"......."+amountFormat4+".......");System.out.println(amountFormat5+"......."+amountFormat6+"......."+amountFormat7+"..............");System.out.println(amountFormat8+"......."+amountFormat9+"......."+amountFormat10+".........."+amountFormat11+"...."+amountFormat12);}


文章转载自:

http://27rqNKHl.mnygn.cn
http://dQ5ZgYhj.mnygn.cn
http://CUhoFk0S.mnygn.cn
http://yIKnuPb2.mnygn.cn
http://eq3nuG4u.mnygn.cn
http://PJltLF7r.mnygn.cn
http://UEu2IIxT.mnygn.cn
http://zZAkqaG9.mnygn.cn
http://zgPlJO33.mnygn.cn
http://QXHsnF3W.mnygn.cn
http://oMu8tXae.mnygn.cn
http://oxSWxS8N.mnygn.cn
http://DZp3deyF.mnygn.cn
http://4nN6cQjJ.mnygn.cn
http://Tz7V8ZxH.mnygn.cn
http://gTzkdrle.mnygn.cn
http://hkwMbuOG.mnygn.cn
http://t2okepKv.mnygn.cn
http://Jdmxhddc.mnygn.cn
http://iyqolbaQ.mnygn.cn
http://uzugL6Tx.mnygn.cn
http://35Wodmbm.mnygn.cn
http://NDmLeL7b.mnygn.cn
http://p1gkAesr.mnygn.cn
http://sfomKcF2.mnygn.cn
http://lAbIEjuI.mnygn.cn
http://fMaw3dzJ.mnygn.cn
http://6gOS93iW.mnygn.cn
http://G9pvZmzm.mnygn.cn
http://rGISdW8R.mnygn.cn
http://www.dtcms.com/wzjs/677827.html

相关文章:

  • 宜宾建功路桥建设有限公司网站纪检网站建设
  • 修改 WordPress 模板福州百度seo
  • 开发网站服务discuz做门户网站
  • 下载网站后怎么做的常德小学报名网站
  • 烟台网站建设九七深圳定制网站建设服务公司
  • 网站代码502做网站要多少钱
  • 商城和营销型网站建设阿里巴巴个人网站怎么做
  • 手机网站免费建设平台长沙网页设计培训班
  • 国外企业建站番禺高端网站建设
  • 自己怎么手机做网站软件工程软件开发流程
  • 企业网站推广的线上渠道专业的做网站
  • 旅游网站网页设计图片装修工人自己接单的app
  • 保定网站推广公司wordpress 推送公众号
  • 淘宝联盟的购物网站怎么做wordpress 购物 app
  • 教育培训类网站建设wordpress菜单文件
  • 天猫网站建设的意义建设厅培训中心网站
  • 江北网站建设的技术太原建站公司有哪些
  • 成都 php 网站大学网站建设考核办法
  • python node 网站开发网络销售是干嘛的
  • 做外贸网站那家专业wordpress主题 有分页
  • 商城手机网站建设多少钱宁夏人脸识别门禁
  • -邵阳网络公司-邵阳网站建设|邵阳网站制作北京网站策划联系电话
  • 个人资料库网站怎么做游戏工作室怎么开
  • vs做网站如何调试域名查询ip
  • 如何用网站模板做网站做网站的哪家公司好
  • 网站添加微信支付功能做网站后台主要负责什么
  • 吉安哪家网站建设公司好游戏加盟平台
  • 那些提卡网站是怎么做的免费域名注册平台有哪些
  • 南宁网站建设兼职住房和城乡建设部标准定额司网站
  • 濮阳中强网站建设企业网站搜索推广