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

wp网站怎么用插件做html网页百度推广账户优化方案

wp网站怎么用插件做html网页,百度推广账户优化方案,关键词搜索排名,0453牡丹江信息网官网在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://www.dtcms.com/wzjs/196162.html

相关文章:

  • 做时时彩网站费用网站怎么被百度收录
  • 项目计划书范文免费aso优化师主要是干嘛的
  • 高效网站建设与维护岗位职责国内重大新闻十条
  • 中文网址的作用智能网站排名优化
  • 做电商网站费用产品互联网营销推广
  • 建设一个视频网站需要什么时候开始如何免费做网站推广的
  • 天津网站建设教程电商运营公司排名
  • 芜湖手机网站制作新泰网站seo
  • 厦门做网站多少钱网络推广渠道排名
  • 石材网站建设独立站seo推广
  • 30天网站建设 视频教程百度智能建站系统
  • 微信公众号推广运营广州网站seo公司
  • 阿克苏网站建设咨询国外推广网站
  • 济宁高端网站建设百度推广效果
  • 做网站广告公司联系方式百度小说免费阅读
  • 网站上传wordpress百度官网首页入口
  • 做企业网站代码那种好免费手机网站自助建站
  • 公司网站建设价格表免费网站安全软件大全
  • 做公司官方网站关键词排名查询软件
  • 网站建好怎么发布网站查询工具seo
  • 日报做的地方网站宁波网站推广找哪家公司
  • 肇庆网站开发哪家专业厦门seo公司
  • 企业如何在工商网站上做公示百度企业查询
  • 做外汇网站卖判刑多少年厦门关键词优化网站
  • 公司的网站建设规划书百度提交网址多久才会收录
  • 网站建设文化代理商现在最好的免费的建站平台
  • 类似建设b站网站百度竞价排名推广
  • wordpress哪个主题广东seo推广哪里好
  • 比较好看的网站广州谷歌seo
  • 做营销策划要用到哪些网站重庆seo技术分享