Open Xml -- Excel文件解析



1、转换。Excel > 后缀名改为.zip >解压

2、详细解析

     1) docProps\app.xml

     <TitlesOfParts><vt:vectorbaseType="lpstr"size="4">

        <vt:lpstr>Early</vt:lpstr>

        <vt:lpstr>Late</vt:lpstr>

        <vt:lpstr>Night</vt:lpstr>

        <vt:lpstr>Summary</vt:lpstr></vt:vector></TitlesOfParts>

         -- 4sheet,并且列出所有sheet的名称

    2) docProps\core.xml

             <cp:lastModifiedBy>wendy_w</cp:lastModifiedBy>           --修改人的用户名

    3) \xl\sharedStrings.xml

         -- Excel表格中所有的字符串

    4)关于Cell内容

         \xl\worksheets\sheet1.xml

         第一种:有公式的

         <sheetData>  -- 表格内容

         <row r="1">  --  首行

         <c r="AG1">  --  编号为AG1的单元格

         <f>  --  公式

         <v>  --  默认值

         第二种:无公式的

         <v>标签中的值,为这个字符串在\xl\sharedStrings.xml中的序号


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个示例代码,演示如何使用Java下载zip文件解析其中的Excel文件,获取数据。 ```java import java.io.*; import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.*; public class ZipExcelParser { public static void main(String[] args) throws Exception { // Step 1: 下载zip文件 String url = "https://example.com/file.zip"; // zip文件的URL String zipFilePath = "file.zip"; // 下载后的zip文件路径 downloadFile(url, zipFilePath); // Step 2: 解析Excel文件 String excelFilePath = null; // Excel文件路径 try (ZipInputStream zip = new ZipInputStream(new FileInputStream(zipFilePath))) { ZipEntry entry = zip.getNextEntry(); while (entry != null) { String fileName = entry.getName(); if (fileName.endsWith(".xlsx")) { // 只处理.xlsx文件 excelFilePath = fileName; File file = new File(excelFilePath); FileOutputStream fos = new FileOutputStream(file); byte[] bytes = new byte[1024]; int length; while ((length = zip.read(bytes)) >= 0) { fos.write(bytes, 0, length); } fos.close(); break; } entry = zip.getNextEntry(); } } // Step 3: 获取Excel数据 List<List<String>> data = new ArrayList<>(); Workbook workbook = new XSSFWorkbook(new FileInputStream(excelFilePath)); Sheet sheet = workbook.getSheetAt(0); // 假设数据在第一个Sheet中 for (Row row : sheet) { List<String> rowData = new ArrayList<>(); for (Cell cell : row) { rowData.add(cell.toString()); } data.add(rowData); } workbook.close(); // 打印数据 for (List<String> rowData : data) { System.out.println(String.join(",", rowData)); } } // 下载文件 private static void downloadFile(String url, String filePath) throws Exception { BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fos = new FileOutputStream(filePath); byte[] dataBuffer = new byte[1024]; int bytesRead; while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) { fos.write(dataBuffer, 0, bytesRead); } fos.close(); in.close(); } } ``` 请注意,此示例代码使用了Apache POI库来解析Excel文件。如果您尚未安装它,请在项目中添加以下依赖项: ```xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值