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
java源代码块java-swing-tips :介绍一个带有源代码的小样本的Java Swing GUI程序。 :使用小源代码示例介绍Java Swing的GUI程序。 什么是摇摆 Swing是一组Java标准组件(库、 UI工具包),用于创建GUI (图形用户...
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 ...
简单的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
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 ...
Learn how to maximize the flexibility of these libraries and use them most effectively. * Performance: Follow in-depth discussions and tips throughout the book that will help you write high-...
For detailed coverage of XML processing, networking, databases, internationalization, security, advanced AWT/Swing, and other advanced features, look for the forthcoming eighth edition of Core Java™,...
This book will navigate through the features of IntelliJ IDEA 12 and present the reader with concepts and tips that will give them a greater understanding of this IDE. Using a practical real-world ...
What’s Inside Preface 1 Java SE5 and SE6 .................. 2 Java SE6 ............................................The 4th edition...........................Changes ...........................................
1,01.zip 3D Text 显示3D文字(6KB)<END><br>2,02.zip A button within a button 按纽中的按纽(13KB)<END><br>3,03.zip Flat Owner Drawn Buttons 浮动的自画按纽(13KB)<END><br>4,04.zip Flat-...
1. Tutorial tips 2 2. Introducing the JavaMail API 3 3. Reviewing related protocols 4 4. Installing JavaMail 6 5. Reviewing the core classes 8 6. Using the JavaMail API 13 7. Searching ...