public void processAccountDetail(){
try {
URL httpurl=new URL("https://hsh-web.oss-.com/wx/111.xls");
URLConnection urlConnection = httpurl.openConnection();
InputStream is = urlConnection.getInputStream();
Workbook wb = null;
wb = new HSSFWorkbook(is);//解析xls格式
Sheet sheet = wb.getSheetAt(0);//第一个工作表 ,第二个则为1,以此类推...
// 获取第一个实际行的下标
int firstRowIndex = sheet.getFirstRowNum();
// 获取最后一个实际行的下标
int lastRowIndex = sheet.getLastRowNum();
//循环获取每一行
for(int rIndex = firstRowIndex+1; rIndex <= lastRowIndex; rIndex ++){
Row row = sheet.getRow(rIndex);
if(row != null){
Account account = new Account();
//获取列数据指标从0开始
Cell userId = row.getCell(1);
Cell balance = row.getCell(3);
//这里转换的时候一定要指定类型,不然会报错
userId.setCellType(CellType.STRING);
balance.setCellType(CellType.STRING);
XxlJobLogger.log("处理账务错误第一次循环userId{}>>>>>>>>>.",userId.getStringCellValue());
//Long changeValue = new BigDecimal(balance.getStringCellValue()).longValue();
//XxlJobLogger.log("处理账务错误>>>>>>>>>.");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Java如何把网络地址上的exl文件读取到数据
最新推荐文章于 2024-07-25 03:52:45 发布
本文详细介绍了一种使用Java从远程URL下载Excel文件并解析其内容的方法。通过具体代码示例,展示了如何读取Excel表格的第一张工作表,并遍历所有行来获取特定列的数据,如用户ID和余额。此外,还解释了如何将单元格数据转换为字符串类型,以避免类型转换错误。
1609

被折叠的 条评论
为什么被折叠?



