操作excel表格和删除文件目录下所有文件

 Runtime r = Runtime.getRuntime();
     File file = new File(path);
     String[] filelist = file.list();
     File delfile = new File(path + "//" + filelist[0]);
     //FileInputStream fis=new FileInputStream(path+ "//" +delfile.getName());
     try
     {
  Runtime.getRuntime().exec(
   "cmd  /c  start  " + path + "//" + delfile.getName());
     } catch (Exception e)
     {
     }

 /**
     * @param args
     */
    //删除文件夹下的所有文件
    public static boolean deleteAllFile(String folderFullPath)
    {
 boolean ret = false;
 File file = new File(folderFullPath);
 if (file.exists())
 {
     if (file.isDirectory())
     {
  File[] fileList = file.listFiles();
  for (int i = 0; i < fileList.length; i++)
  {
      String filePath = fileList[i].getPath();
      deleteAllFile(filePath);
  }
     }
     if (file.isFile())
     {
  file.delete();
     }
 }
 return ret;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Python中的pandas库来实现合并同一文件夹下所有excel表格的功能。具体步骤如下: 1. 导入pandas库 ```python import pandas as pd ``` 2. 使用pandas的read_excel函数读取每个excel文件,并将其存储到一个列表中 ```python import os # 获取文件夹中所有的excel文件 folder_path = "path/to/folder" all_files = os.listdir(folder_path) excel_files = [f for f in all_files if f.endswith('.xlsx') or f.endswith('.xls')] # 读取每个excel文件,并将其存储到一个列表中 data_frames = [] for file in excel_files: file_path = os.path.join(folder_path, file) df = pd.read_excel(file_path) data_frames.append(df) ``` 3. 使用pandas的concat函数将所有数据框合并为一个 ```python # 使用concat函数将所有数据框合并为一个 merged_df = pd.concat(data_frames, ignore_index=True) ``` 4. 将合并后的数据框保存为一个新的excel文件 ```python # 将合并后的数据框保存为一个新的excel文件 merged_df.to_excel("path/to/output_file.xlsx", index=False) ``` 完整代码如下: ```python import pandas as pd import os # 获取文件夹中所有的excel文件 folder_path = "path/to/folder" all_files = os.listdir(folder_path) excel_files = [f for f in all_files if f.endswith('.xlsx') or f.endswith('.xls')] # 读取每个excel文件,并将其存储到一个列表中 data_frames = [] for file in excel_files: file_path = os.path.join(folder_path, file) df = pd.read_excel(file_path) data_frames.append(df) # 使用concat函数将所有数据框合并为一个 merged_df = pd.concat(data_frames, ignore_index=True) # 将合并后的数据框保存为一个新的excel文件 merged_df.to_excel("path/to/output_file.xlsx", index=False) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值