小编Ser*_*hyi的帖子

获取字符串值,当我使用日期类型 (apache poi) 从 excel 读取时

我有一个正在阅读的xlsx 文件- Apache POI 库。

例如,在某些行中,我有这样的单元格值:

13 年 9 月 1 日 | 15136.00| 马特|......


我的目标是: 将行中的所有单元格读取为字符串值。但正如我所见,我无法将01-Sep-13读取为字符串,它只表示像 Date 类型 () 和 cell.getDateCellValue();


1)我可以以某种方式将 01-Sep-13 读为字符串:“01-Sep-13”;2)如果我有不同的日期模式(ddMMyyyy)和(dd-MMM-yy),我可以将日期值转换为字符串吗?

代码:

当我遍历行和单元格时,Apache POI 会分析每种单元格类型:

String normalizeCellType(Cell cell) {

    switch (cell.getCellType()) {
        case Cell.CELL_TYPE_STRING:
           return cell.getRichStringCellValue().getString());            
        case Cell.CELL_TYPE_NUMERIC:
            if (DateUtil.isCellDateFormatted(cell)) {

                Date date = cell.getDateCellValue(); ????????????
                System.out.println(date);

            } else {

                ....
            }
            break;
        case Cell.CELL_TYPE_BOOLEAN:
           return ....
        case Cell.CELL_TYPE_FORMULA:
           return ....
        default:
            System.out.println();
    }
}
Run Code Online (Sandbox Code Playgroud)

java apache-poi simpledateformat xssf

7
推荐指数
2
解决办法
4万
查看次数

Maven不会使用mavenAssemblyPlugin附加未归档的文件

我有一些文件列表(.jil)。我想使用maven-assembly-plugin将它们附加到构建中。

我毫不费力地以“ zip”格式部署它们。
但是,“ dir”格式引发异常:

[警告]汇编文件:C:\ Branches \ project-branch \ target \ project \ output \目录不是常规文件(可能是目录)。不能将其附加到项目版本以进行安装或部署。

pom文件:

<build>
  <plugins>

    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>2.2.1</version>
      <executions>

        <execution>
          <id>make-devq</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <descriptors>
              <descriptor>
                ${basedir}/environments/dev/assembly/descriptor.xml
              </descriptor>
            </descriptors>
            <finalName>project</finalName>
            <appendAssemblyId>true</appendAssemblyId>
            <workDirectory>              
              ${project.build.directory}/${project.artifactId}/work/project
            </workDirectory>
            <outputDirectory>
              ${project.build.directory}/${project.artifactId}/output
            </outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

程序集描述符:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

    <id>project-id</id>
    <formats>
        <format>dir</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>

        <fileSet>
            <directory>${basedir}/environments/dev/jils/</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.jil</include>
            </includes>       
        </fileSet>

    </fileSets>

</assembly>
Run Code Online (Sandbox Code Playgroud)

maven maven-assembly-plugin

5
推荐指数
1
解决办法
4261
查看次数

通过程序集插件MAVEN排除文件目录

如果你能帮助我找出这个问题,我会很愉快的.

当我使用maven < assembly >插件将项目构建到.zip时.

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<id>dev</id>
<formats>
    <format>zip</format>
</formats>

<fileSets>

    <fileSet>
        <directory>${basedir}</directory>
        <includes>
            <include>/environments/dev/**/*.sh</include>
            <include>/environments/dev/**/*.jil</include>
            <include>/environments/dev/**/*.properties</include>
            <include>/environments/dev/**/log4j2.xml</include>  
        </includes>  
    </fileSet>

</fileSets>

<dependencySets>
    <dependencySet>
        <outputDirectory>/lib</outputDirectory>
        <useProjectArtifact>true</useProjectArtifact>
        <scope>runtime</scope>
    </dependencySet>
</dependencySets>
Run Code Online (Sandbox Code Playgroud)

我收到以下文件结构:

build.zip----> environments__
                            |_DEV_
                                  |_bin
                                  |_properties
                                  |_....
Run Code Online (Sandbox Code Playgroud)

我的目标是:

要在maven构建之后获得以下文件结构:

 build.zip----> 
                                  |_bin
                                  |_properties
                                  |_....
Run Code Online (Sandbox Code Playgroud)

没有环境和DEV文件夹.

我已经阅读了maven文档(http://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html),我们可以排除一些文件目录.这条路:

<assembly> 
    ....

    <fileSets> 
        <fileSet>
            <directory>${basedir}</directory>
            <includes>
              ....
            </includes>
            <excludes>
                <exclude>/environments/dev</exclude>
            </excludes>
        </fileSet> 
    </fileSets>

    <dependencySets>
        <dependencySet>
            <outputDirectory>/lib</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
</assembly>
Run Code Online (Sandbox Code Playgroud)

但它没有帮助.我还有以前的文件结构.

java maven-plugin maven maven-assembly-plugin

4
推荐指数
1
解决办法
8017
查看次数

Apache POI xlsx读取,单元格具有#值-错误意外的单元格类型(5)

你能帮我解决这个问题吗?

我需要将每个单元格读取为String值。在这种情况下,我正在使用appache poi lib。以及使每个单元格规范化的方法:

String getNormilizedCell(Cell cell){
return new DataFormatter().formatCellValue(cell);}
Run Code Online (Sandbox Code Playgroud)

但是当在.xlsx文件中时,我面临这样的价值:

|#N / A |#N / A | ... | ... | ...

我收到错误[意外的单元格类型(5)],但我不知道该如何处理。在Google中,我找不到必要的信息。

java xlsx apache-poi

3
推荐指数
1
解决办法
7936
查看次数

将List <Product>转换为Map <Integer,List <Product >>

您可以向我假设最好或更优雅的方式,将List<Product>所有Map<Integer, List<Product>>产品转换 为按ProductNumber分组的产品.

例如我的产品POJO.

public class Product{
.. 
private Integer productCode;
private String productName;
...
//getters, setters
}
Run Code Online (Sandbox Code Playgroud)

这是我的尝试,但我认为它不那么优雅:

public Map<Integer, List<Product>> getProductsByIndex (List<Product> products){
        Map<Integer, List<Product>> resultMap = new HashMap<>();
        Set<Integer> productCodes = getProductCodes(products);

        for(Integer productCode: productCodes){
            List<Product> productsByCode = new ArrayList<>();
            for(Product product : products){
                if(productCode == product.getCode()){
                    productsByCode.add(product);    
                }
            }
            resultMap.put(productCode, productsByCode);
        }
        return resultMap;
    }

    public Set<Integer> getProductCodes (List<Product> products){
        Set<Integer> productCodes = new HashSet<>();
        for(Product product: products){
            productCodes.add(product.getCode());
        }
        return productCodes; …
Run Code Online (Sandbox Code Playgroud)

java collections list map

1
推荐指数
1
解决办法
544
查看次数