如何设置列名 [英] How to set column names

查看:97
本文介绍了如何设置列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序使用Apache POI,我想设置列名称,而不是"A,B,C ..."

I'm using Apache POI for my app and I want to set columns names instead of "A, B, C..."

我使用以下代码,但仅在第一行添加数据:

I use the following code but it adds just data in first row:

 public void createHeaderRow(HSSFSheet sheet, List<String> headerRowList) {
    HSSFRow headerRow = sheet.createRow(0);
    for(int i=0;i<headerRowList.size();i++){
        HSSFCell cell = headerRow.createCell((short) i);
        cell.setCellValue(headerRowList.get(i).toString());
    }
}

有什么想法吗?

推荐答案

坏消息:AFAIK excel不能执行与A,B,C不同的任何操作.主要原因是:列名和行名不包含信息,只是一个编号.假设您要打印包含以下名称的文档:Excel将不了解格式,边框,甚至单元格的宽度/高度.

Bad news: AFAIK excel cannot do anything different than A, B, C. The main reason: Column and Row names don't contain information, it's just a numbering. Imagine you want to print a document including these names: Excel won't know about formatting, nor borders, not even cell widths/heights.

您有以下选择:

  • 使用MS Access,它使用数据库布局(例如,字段名称作为列名称)
  • 修复视图中的第一行并将其格式化为表格标题. Excel的表格自动格式设置功能采用相同的方法.

这篇关于如何设置列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆