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

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

问题描述

我正在为我的应用程序使用 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天全站免登陆