如何在Java中编写xls文件?

huangapple 未分类评论58阅读模式
英文:

How to write xls file in java?

问题

我尝试了这个方法:链接

这对于 csv 文件运行良好,但我需要对 .xls 文件进行相同操作。

在 Java 侧

public StringBuilder columnsForCsv(){
    StringBuilder result = new StringBuilder();
    List<String> columns = new ArrayList<>();
    columns.add("id");
    columns.add("from");
    columns.add("to");

    for(String column : columns){
        result.append(column + ",");
    }
    return result;
}

这段代码将在 csv 文件中创建名为 idfromto 的 3 列。

但是,当我尝试对 .xls 文件进行相同操作时,这并不起作用。

是否有任何方法可以在不使用任何外部库的情况下向 xls 文件中写入数据?

英文:

I tried out this approach: link

It works fine with csv file, but i need to do the same for .xls file

In java side

public StringBuilder columnsForCsv(){
    StringBuilder result = new StringBuilder();
    List&lt;String&gt; columns = new ArrayList&lt;&gt;();
    columns.add(&quot;id&quot;);
    columns.add(&quot;from&quot;);
    columns.add(&quot;to&quot;);

    for(String column : columns){
        result.append(column + &quot;,&quot;);
    }
    return result;
}

This code will create 3 different columns with name id from to in csv file

but when when i tried out the same for .xls file. This doesn't work.

Is there any way to write data in xls file without using any external library.

huangapple
  • 本文由 发表于 2020年5月5日 20:47:30
  • 转载请务必保留本文链接:https://java.coder-hub.com/61613531.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定