10、Table的Excel导出功能
表格上的Excel导出功能还是比较实用的功能,企业应用一般都会用到,这里提供相关代码
02 |
WritableCellFormat titleFormat = new WritableCellFormat(
|
03 |
new WritableFont(WritableFont.createFont( "黑体" ), 16 ,
|
04 |
WritableFont.NO_BOLD));
|
05 |
titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
|
06 |
titleFormat.setAlignment(Alignment.CENTRE);
|
07 |
titleFormat.setWrap( true );
|
09 |
WritableCellFormat headerFormat = new WritableCellFormat();
|
10 |
headerFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
|
11 |
headerFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
|
12 |
headerFormat.setAlignment(Alignment.CENTRE);
|
13 |
headerFormat.setWrap( true );
|
15 |
WritableCellFormat countFormat = new WritableCellFormat(
|
16 |
new NumberFormat( "0.000" ));
|
17 |
countFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
|
18 |
countFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
|
19 |
countFormat.setAlignment(Alignment.RIGHT);
|
20 |
countFormat.setWrap( true );
|
22 |
WritableCellFormat moneyFormat = new WritableCellFormat(
|
23 |
new NumberFormat( "0.00" ));
|
24 |
moneyFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
|
25 |
moneyFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
|
26 |
moneyFormat.setAlignment(Alignment.RIGHT);
|
27 |
moneyFormat.setWrap( true );
|
29 |
WritableCellFormat intFormat = new WritableCellFormat(
|
30 |
new NumberFormat( "0" ));
|
31 |
intFormat.setBorder(Border.ALL, BorderLineStyle.THIN);
|
32 |
intFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
|
33 |
intFormat.setAlignment(Alignment.RIGHT);
|
34 |
intFormat.setWrap( true );
|
36 |
WritableWorkbook book = Workbook.createWorkbook(exportFile);
|
37 |
WritableSheet sheet = book.createSheet( "综合统计报表" , 0 );
|
41 |
sheet.mergeCells( 0 , titleRow, model.getColumnCount() - 1 ,
|
43 |
Label titleLab = new Label( 0 , titleRow, tableTitleTxfd.getText(), titleFormat);
|
44 |
sheet.addCell(titleLab);
|
47 |
for ( int j = 0 ; j < model.getColumnCount(); j++) {
|
48 |
sheet.mergeCells(j, headerRow, j, headerRow + 1 );
|
49 |
Label lab = new Label(j, headerRow, model.getColumnName(
|
54 |
for ( int row = 0 ; row < model.getRowCount(); row++) {
|
55 |
for ( int col = 0 ; col < model.getColumnCount(); col++) {
|
56 |
Object obj = model.getValueAt(row, col);
|
57 |
if (obj instanceof String) {
|
58 |
Label lab = new Label(col, dataRow + row,
|
59 |
(String) obj, headerFormat);
|
61 |
} else if (obj instanceof Integer) {
|
62 |
Number labelN = new Number(col, dataRow
|
63 |
+ row, (Integer) obj, intFormat);
|
64 |
sheet.addCell(labelN);
|
67 |
new Label(col, dataRow + row, "" ,
|
75 |
int footerRow = dataRow + model.getRowCount() + 1 ;
|
77 |
( int ) ((( double ) (model.getColumnCount() - 2 ) / 3 )
|
79 |
Label footerLab = new Label( 0 , footerRow, "部门负责人:" );
|
80 |
sheet.addCell(footerLab);
|
81 |
footerLab = new Label(step, footerRow, "制表:" + creatorTxfd.getText());
|
82 |
sheet.addCell(footerLab);
|
83 |
footerLab = new Label(model.getColumnCount() - 2 , footerRow,
|
84 |
NazcaFormater.getSimpleDateString( new Date()));
|
85 |
sheet.addCell(footerLab);
|
87 |
sheet.setColumnView( 0 , 16 );
|
88 |
sheet.setRowView(titleRow, 600 );
|
93 |
} catch (Throwable ex) {
|
11、Table的打印功能
打印这块,之前已经提过,可以参考之前的文章 JTable Print
12、在Table上选择多行
1 |
int rowcounts=table.getSelectedRows().length;
|
3 |
int [] rows=table.getSelectedRows();
|
4 |
for ( int i= 0 ;i<rows.length;i++){
|
5 |
String value=(String) tableModel.getValueAt(i, 1 );
|
分享到:
相关推荐
1. 可以用来作为学习swing的辅助工具 ...3. 使用方式 java -jar swing-tips-helper.jar ,如果你需要源码及资源及更多详细介绍参考该地址 https://blog.csdn.net/x308561498/article/details/123211860
java-swing-tips, 包含 Java Swing的示例 java-swing-tips英语: 使用小源代码示例介绍 Java Swing的GUI 程序。 许可证https://github.com/aterai/java-swing-tips/blob/master/L
aterai_java-swing-tips_1743030688
java源代码块java-swing-tips :介绍一个带有源代码的小样本的Java Swing GUI程序。 :使用小源代码示例介绍Java Swing的GUI程序。 什么是摇摆 Swing是一组Java标准组件(库、 UI工具包),用于创建GUI (图形用户...
1. **控件使用类**:在许多编程语言中,都有专门的控件类库,如Java的Swing或AWT,C#的Windows Forms或WPF,以及Python的Tkinter等。这些类库提供了一系列预定义的控件,如按钮、文本框、标签等,同时也包括了Tips...
### 二、Databases & Beans(数据库与Bean) - **JDBC基础**:学习如何使用JDBC连接数据库,执行SQL查询和更新操作。 - **数据源管理**:掌握如何配置数据源,以实现数据库连接池的管理。 - **实体Bean**:了解如何...
### Java--330--Tips:实用开发指南 #### 前言 “Java--330--Tips”是一本汇集了330个实用Java技巧的手册,这些技巧覆盖了多个方面,包括网络编程、多线程处理、图形用户界面(GUI)、数据库操作等。该书的目标读者...
- **Graphics, AWT, Swing**:这部分内容主要围绕Java图形界面开发,包括如何使用AWT和Swing库创建GUI应用程序。 - **General Java**:这一系列部分覆盖了Java编程的一般性主题,如语法、数据类型、流程控制等。 - *...
### 二、内容结构 #### 1. Absolute Java FAQ: Career Center 这部分提供了与职业发展相关的资源,包括IT职位的招聘信息等。用户可以注册并获取即时访问权限,以便了解当前市场上优质的IT职位空缺。 #### 2. ...
8. **Swing与JavaFX**:这两个是Java的GUI库,用于创建桌面应用程序。熟悉这些库可以创建美观且用户友好的界面。 9. **反射API**:反射允许在运行时检查类、接口、字段和方法的信息,甚至动态调用方法。它是实现元...
- **AWT与Swing**:掌握Java图形用户界面编程,包括布局管理器、事件处理等。 - **JavaFX**:了解JavaFX的基础组件和高级功能,如动画、多媒体集成等。 ### 三、数据库与Java集成 #### 1. JDBC - **数据库连接**:...
6. **Swing与AWT**:这是Java的图形用户界面(GUI)库,用于创建桌面应用。 7. **JDBC**:Java数据库连接(JDBC)是访问数据库的标准API,可用于执行SQL查询和管理数据库连接。 8. **设计模式**:文档可能涵盖了...
The aim is not to teach LATEX programming, but to give a quick reference to all the tips and tricks that can be used if you are encountering a (difficult) problem, or simply facing a question which ...
### Qt学习之路(1~60 + tips)彩版带书签 #### 重要知识点概览 1. **Qt简介** - Qt不仅是一个GUI库,而是一个全面的跨平台应用开发框架。 - 提供一站式服务,包括但不限于字符串处理、网络编程、数据库访问等。 ...
简单的FTP服务器 ... FTP Server By: Bryan Cairns ...If youre a Dephi Pro, you can probably give me some tips as I am still new to Delphi programming. Bryan Cairns cairnsb@ameritech.net
12. 设置窗体标题栏的属性是 `Caption`,而不是 `Tips`, `Name`, 或 `Text`。 13. `COPYTO FOR` 命令在数据库操作中实现了选择性地复制记录。 14. ASCII 编码中,所有大写英文字母的 ASCII 码值都小于小写英文字母...
Swing and the Model-View-Controller Design Pattern 362 Introduction to Layout Management 368 Text Input 377 Choice Components 385 Menus 406 Sophisticated Layout Management 424 Dialog Boxes 452 ...
Ask the Expert--Q&A sections filled with bonus information and helpful tips Try This--Hands-on exercises that show you how to apply your skills Self Tests--End-of-chapter questions that test your ...