简体   繁体   English

我有一个 xlxs 解析器。 在代码中。 我不能太多改变我的方法

[英]I have an xlxs parser. In the code. I can't change my approach much

      public ResponseEntity<Object> importPcpXlsx(MultipartFile xlsx) {
      try {
        XSSFWorkbook xssfWorkbook = new XSSFWorkbook(xlsx.getInputStream());
        XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
        Row row;
        Cell cell;
        int i = 1;
      
        List<String> number = new ArrayList<>();
        while (true) {
         if (xssfSheet.getRow(i) != null) {
           row = xssfSheet.getRow(i);
           cell = row.getCell(0);
 
           if (cell.getSheet()
              .getRow(0)
              .getCell(0)
              .getRichStringCellValue()
              .getString()
              .equals("Number".trim())) {
            
             number.add(cell.getStringCellValue().trim());
 
             log.info("number: " + i + ".  № " + cell.getStringCellValue());
           }
         } else {
           i = 1;
           break;
         }
         i++;
        }
     
        List<String> kpgz = new ArrayList<>();
        while (true) {
          if (xssfSheet.getRow(i) != null) {
          
            row = xssfSheet.getRow(i);
            cell = row.getCell(1);
 
            if (cell.getSheet()
               .getRow(0)
               .getCell(1)
               .getRichStringCellValue()
               .getString()
               .equals("kpgz".trim())) {
 
             kpgz.add(cell.getStringCellValue().trim());
 
             log.info("kpgz: " + i + ". " + cell.getStringCellValue());
           }
         } else {
           i = 1;
           break;
         }
         i++;
       }

I go through the columns and read all the lines under each column.我 go 通过列并阅读每列下的所有行。 But what if I have some columns will not come in xlxs file.但是,如果我有一些列不会出现在 xlxs 文件中怎么办。 That is, I need an option where I do not have to strictly specify columns.也就是说,我需要一个不必严格指定列的选项。 Please predict.请预测。 In code Iread by columns, since columns have different types and should be processed differently.在按列读取的代码中,由于列具有不同的类型,因此应该进行不同的处理。 I need to do this so that I do not specify the number of columns in the column number code, as I did cell = row.getCell(0);我需要这样做,这样我就不会像我那样在列号代码中指定列数 cell = row.getCell(0); or row.getCell(1) or row.getCell(2)或 row.getCell(1) 或 row.getCell(2)

Read the columns one by one and bind their type, then check data under these columns.一一读取列并绑定它们的类型,然后检查这些列下的数据。

See example of type checking there: Best language to parse extremely large Excel 2007 files请参阅此处的类型检查示例: Best language to parse extremely large Excel 2007 files

If you can def.netely identify column, it is not a problem.如果你能 def.netely 识别列,那不是问题。 If not, you should think about changing api.如果不行,你应该考虑换api。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有(.dag)和(.dax)文件已被我的代码使用。 但我不知道如何打开它们或创建它们 - I have (.dag) and (.dax) files that have been used by my code. But I don't know how to open them or to create one 我无法签署我的代码。 对最终用户会有什么影响? - I can't sign my code. What will be the impact on end users? 我的Java代码有些麻烦。 在循环中告诉正数和负数之间的差异时,它将不会运行 - I have some trouble with my Java code. It won't run when telling the difference between positive and negative number when in a loop 我无法通过此代码找到最小的数字。 如何通过修改此代码找到最小的数字? - I can't find smallest number by this code. How I find smallest number by modifying this code? 如何从JSP页面获得登录名? 如何更正我的jsp代码。 - How can I get a Login from JSP page? How can I correct my jsp code.? Eclipse建议更改代码。 我必须如何在哪里实例化导入类的对象? - Eclipse suggesting change of code. How and where I must instantiate my objects of imported class? 我正在尝试在我的 gui 中放置一个 imageicon,但是当我运行代码时它没有出现。 有人可以告诉我如何解决它 - I am trying to put an imageicon in my gui but it doesn't appear when I run the code. Can somebody tell me how to fix it 我在使用这个字符串解析器时遇到了问题,我该如何解决? - I am having trouble with this String Parser, how can I approach it? 我在编写测试代码时有一个问题。 壮举 JUnit - I have a question while writing the test code. feat JUnit 我的代码中有一个第三方异步块。 我怎么知道什么时候结束? - I have a third-party asynchronous block in my code. How do I know when it has ended?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM