Excel file export

A lot of people must met the question like File Export. There are some solutions to do that thing.

  • First, POI is an easy-to-use framework to operate the office document besides Excel file.

  • Second, jexcelapi is a very good tool to export the Excel file.

All two open source software are extremely easy-to-use and there are very detailed document and examples to refer to.

Today, I'm gonna express one thing: there's requirement like following image.


result

The condition is that there are two group of data. one is (1,1,1,1,1,1), another is (2,2,2,2,2,2).

The question is how to do to show the result like that image?

import java.util.ArrayList;
import java.util.List;

public class Example {
    public static void main(String[] args) {
        String[] strArr = {"1", "2"};
        int count = 0;
        List<String> strList = createData();
        for (String par: strArr) {
            while(strList.size() > 0) {
                String str = strList.get(0);
                if (par.equals(str)) {
                    if (count == 0) {
                        System.out.println(str);
                    } else {
                        System.out.println(str+":grey");
                    }
                    strList.remove(str);
                    count ++;
                } else {
                    count = 0;
                    break;
                }
            }
        }
    }  

    public static List<String> createData() {
        List<String> arrayList = new ArrayList<String>();
        arrayList.add("1");
        arrayList.add("1");
        arrayList.add("1");
        arrayList.add("1");
        arrayList.add("1");
        arrayList.add("1");
        arrayList.add("2");
        arrayList.add("2");
        arrayList.add("2");
        arrayList.add("2");
        arrayList.add("2");
        arrayList.add("2");
        return arrayList;
    }
}

Notice:

  • the consequence of strArr must be equel to the arrayList.
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,486评论 0 10
  • (一) 关于战略,相信不少人都看过罗辑思维的最近一期的什么是战略,其中一句话说战略是对最终均衡点的倒推,其知识背景...
    黑客咖啡屋阅读 239评论 0 0
  • 他的心 好硬 无论我怎么写 都写不出指间的柔软 他的心 好冷 无论我怎么写 都写不出手心的温暖 他的心 好漠然 无...
    喵二LIN阅读 205评论 0 0
  • 12306 日点击量达到1577.8亿,在刚上线的时候,买火车票太卡。他们做了很多的改进。有哪些呢? 咱不是开发人...
    taiji1985阅读 3,713评论 0 0