java excel设置单元格格式为会计专用,货币单位HKD

HSSFCellStyle currencyDecimalStyle = wb.createCellStyle();
		HSSFDataFormat format = wb.createDataFormat();
		currencyDecimalStyle.setDataFormat(format.getFormat("_(\"HKD\"* #,##0.00_);_(\"HKD\"* (#,##0.00);_(\"HKD\"* \"-\"??_);_(@_)"));
		currencyDecimalStyle.setFont(bodyFont);
		currencyDecimalStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);


writeAmountData(row, (short) 3, totalAmountByPayitemKey, currencyDecimalStyle);

public void writeAmountData(HSSFRow row, short cellnum, Object value, HSSFCellStyle cellStyle) {
		Double amount = new Double(value.toString());
		double amountDouble = amount.doubleValue();
		if (amountDouble < 0) {
			amountDouble = amountDouble * -1;
		}

		HSSFCell cell = row.createCell(cellnum);
		cell.setCellValue(amountDouble);
		cell.setCellStyle(cellStyle);
		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
	}

下载excel效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,这个问题可以回答。您可以使用Python的requests和BeautifulSoup库来爬取中国银行外汇牌价网的数据,然后使用pandas库将数据存入Excel文件中。以下是一个示例代码: ```python import requests from bs4 import BeautifulSoup import pandas as pd from datetime import datetime, timedelta # 设置需要爬取的货币种类和日期范围 currencies = ['USD', 'JPY', 'HKD', 'EUR', 'RUB', 'GBP', 'AUD', 'CHF', 'SGD'] start_date = datetime.now() - timedelta(days=365) end_date = datetime.now() # 创建一个空的DataFrame来存储数据 df = pd.DataFrame(columns=['Date'] + currencies) # 循环遍历每一天 current_date = start_date while current_date <= end_date: # 构造URL并发送请求 url = f'https://srh.bankofchina.com/search/whpj/search_cn.jsp?erectDate={current_date.strftime("%Y-%m-%d")}&nothing={current_date.strftime("%Y-%m-%d")}&pjname=1316' response = requests.get(url) # 解析HTML并提取数据 soup = BeautifulSoup(response.text, 'html.parser') table = soup.find('table', class_='BOC_main publish') if table: row = [current_date.strftime('%Y-%m-%d')] for currency in currencies: td = table.find('td', text=currency) if td: row.append(td.find_next_sibling('td').text.strip()) else: row.append('') df.loc[len(df)] = row # 增加一天 current_date += timedelta(days=1) # 将数据保存到Excel文件中 df.to_excel('~/Desktop/forex.xlsx', index=False) ``` 请注意,这个代码仅供参考,具体实现可能需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值