假设我们定义一个POJO如下
package com.unity.excel.demo; import java.util.Date; import com.unity.excel.annotations.UColumn; import com.unity.excel.annotations.UFormatter; import com.unity.excel.annotations.UTable; @UTable() public class DemoObject { @UColumn(Index = 1) private String name; @UColumn(Index = 2) private int age; @UColumn(Index = 3) private double width; @UColumn(Index = 4) @UFormatter(FormatPartten = "yyyy-MM-dd") private Date birthday; public DemoObject() { } public DemoObject(String name) { super(); this.name = name; } public DemoObject(String name, int age) { super(); this.name = name; this.age = age; } public DemoObject(String name, int age, double width) { super(); this.name = name; this.age = age; this.width = width; } public DemoObject(String name, int age, double width, Date birthday) { super(); this.name = name; this.age = age; this.width = width; this.birthday = birthday; } public int getAge() { return age; } public Date getBirthday() { return birthday; } public String getName() { return name; } public double getWidth() { return width; } public void setAge(int age) { this.age = age; } public void setBirthday(Date birthday) { this.birthday = birthday; } public void setName(String name) { this.name = name; } public void setWidth(double width) { this.width = width; } @Override public String toString() { return "DemoObject [name=" + name + ", age=" + age + ", width=" + width + ", birthday=" + birthday + "]"; } }
上面代码中,我们看到了UTable UColumn 这两个注解,很明显这是支撑我们导出使用的注解。
回顾第一章的代码
private static void ExportTest() { List<DemoObject> temp=new ArrayList<DemoObject>(); //---------------------------------姓名 ,年龄,腰围,生日 temp.add(new DemoObject("小妹",1,33.500,new Date())); temp.add(new DemoObject("山炮",2,23.5,new Date())); Unity u=new Unity97(); try { u.exportUTable(temp, new FileOutputStream("src/temp.xls")).close(); } catch (IOException e) { e.printStackTrace(); } }
如此就完成了导出,那么导出的数据格式是怎么控制的呢?
来介绍一下 UTable 和 UColumn这两个注解
@UTable(EnableSequence=true,SequenceHead="序号",TitleRowsCount=1)
以上属性均是默认值,等效于@UTable()
EnableSequence 开启序号列 值 true | false 默认 true
SequenceHead 序号列标题
TitleRowsCount 标题行数量 //这个是读取时使用
@UColumn(Index=1)
Index代表导出时 字段所在列的索引位置,从1开始 因为 第0列是序号列
Head代表导出时标题列的文字内容 ,默认为字段定义名字
需要第三方类库清单
unity-excel-1.0.1.jar见附件
相关推荐
《Unity3D平台AR与VR开发快速上手》针对没有编程经验的初学者,通过详细的讲解,《Unity3D平台AR与VR开发快速上手》将Unity3D开发增强现实和虚拟现实的方法介绍给读者,《Unity3D平台AR与VR开发快速上手》使读者能够...
Excel VBA 快速上手教程,对新手很有用的。
Excel VBA 快速上手之宝典 第一章 Excel VBA 简明语言之基础 第二章 Excel VBA常用对象之使用 第三章 Excel VBA高级使用 第四章 Excel VBA优化及结束语
Excel VBA之快速上手(DOC) Excel VBA之快速上手(DOC)
第二章 Excel VBA常用对象之使用 第一节 文件的操作 1) Excel文件 2) 文本文件 3) Access文件 第二节 工作表操作 1) 新建与删除 2) 隐藏与显示 3) 保护与撤销 第三节 单元格操作 1) 如何引用单元格和区域 ...
《51单片机C语言快速上手》的第一版非常好!现在出第二版啦!想学习单片机请快点下载吧! 《51单片机C语言快速上手》(第二版)
STM32嵌入式微控制器快速上手.pdf。深入浅出的讲解stm32的开发,是入门学习者的一个不错选择。
自己查找总结的一个,轻量级、易上手的插件,一个二维数组解决所有问题,基于EPPlus的优化
完全手册Excel_VBA典型实例大全:通过368个例子掌握,Excel_VBA_之快速上手
Excel_VBA_快速上手,和大家一起分享
本书共分为14章,详细讲解了Unity3D的安装、发布、界面等主要功能,并深入介绍AR(增强现实)、VR(虚拟现实)开发方法,以及地图定位、摄像机、声音播放等开发技巧,让读者了解到如何使用Unity3D制作AR\VR产品,...
学习python的一个pdf书籍,编程快速上手
Python游戏编程快速上手(pdf+源码).zip
Excel VBA 之快速上手
本文档主要讲述了蜂鸟 E203 快速上手说明,有助于新手快速入门
Excel VBA 之快速上手 Excel VBA 基础
React快速上手开发 作 者 :(保)斯托扬·斯特凡诺夫(Stoyan Stefanov) 出版发行 : 北京:人民邮电出版社 , 2017.02 ISBN号 :978-7-115-44773-9 页 数 : 188 丛书名 : 图灵程序设计丛书 原书定价 : 49.00 主题...