亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? spreadsheettablemodel.java

?? 將DB2數據庫里的數據導出為excel文件的java代碼
?? JAVA
字號:
/*********************************************************************/
/*(c) Copyright IBM Corp. 2004  All rights reserved.                 */
/*                                                                   */
/*This sample program is owned by International Business Machines    */
/*Corporation or one of its subsidiaries ("IBM") and is copyrighted  */
/*and licensed, not sold.                                            */
/*                                                                   */
/*You may copy, modify, and distribute this sample program in any    */
/*form without payment to IBM,  for any purpose including developing,*/
/*using, marketing or distributing programs that include or are      */
/*derivative works of the sample program.                            */
/*                                                                   */
/*The sample program is provided to you on an "AS IS" basis, without */
/*warranty of any kind.  IBM HEREBY  EXPRESSLY DISCLAIMS ALL         */
/*WARRANTIES EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO*/
/*THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTIC-*/
/*ULAR PURPOSE. Some jurisdictions do not allow for the exclusion or */
/*limitation of implied warranties, so the above limitations or      */
/*exclusions may not apply to you.  IBM shall not be liable for any  */
/*damages you suffer as a result of using, modifying or distributing */
/*the sample program or its derivatives.                             */
/*                                                                   */
/*Each copy of any portion of this sample program or any derivative  */
/*work,  must include a the above copyright notice and disclaimer of */
/*warranty.                                                          */
/*                                                                   */
/*********************************************************************/

package com.ibm.ExcelDB2;
 
/*********************************************************************/
/* Stores the contents of a database table                           */
/*********************************************************************/
import javax.swing.table.AbstractTableModel;
import java.io.*;
import java.util.List;
import java.util.*;
import org.apache.poi.hssf.usermodel.*;

/**
* Implements the TableModel interface so that a JTable can display the contents of ResultSet.
**/
public class SpreadsheetTableModel extends AbstractTableModel {
	
	/**
	* number of rows in the ResultSet
	*/
	private int rowCount;

	/**
	* number of columns in ResultSet
	*/
	private int colCount;

	/**
	* The names of the columns in the ResultSet
	*/
	private List columnNames = new ArrayList();

	/**
	*  The class types of the columns being displayed.
	*/
	private List columnTypes = new ArrayList();

	/**
	*  Transcribes the data in the ResultSet into a List of lists
	*/
	private List result = new ArrayList();

	/**
	* Name of the spreadsheet table being displayed
	*/
	private String tableName;

	/**
	 * @see java.lang.Object#Object()
	 */
	public SpreadsheetTableModel() {
    }

// ----------------------------------------------------------------------------------------- //
// methods of javax.swing.table.TableModel interface
// ----------------------------------------------------------------------------------------- //
	/**
	* Method getRowCount.
	* @see javax.swing.table.TableModel#getRowCount()
	*/
	public int getRowCount() {
		return rowCount;
	}

	/**
	* Method getColumnCount.
	* @see javax.swing.table.TableModel#getColumnCount()
	*/
	public int getColumnCount() {
		if(rowCount > 0) {
			return colCount+1;
		} else {
			return 0;
		}
	}

	/**
	* Method getValueAt.
	* @see javax.swing.table.TableModel#getValueAt(int, int)
	*/
	public Object getValueAt(int rowIndex, int columnIndex) {
		if(columnIndex == 0) {
			return new Integer(rowIndex);
		} else {
			// We subtract one from the columnIndex since the first column is used for row numbers
            return ((ArrayList) result.get(rowIndex)).get(columnIndex-1);
		}
	}

	/**
	* Method getColumnName.
	* @see javax.swing.table.TableModel#getColumnName(int)
	*/
	public String getColumnName(int colIndex) {
		if(colIndex == 0) {
			// The first column is used for the row numbers, with a column name of "Row"
			return "Row";
		} else {
			// We subtract one from the columnIndex since the first column is used for row numbers
			return (String) columnNames.get(colIndex-1);
		}
	}

	/**
	* Method getColumnNames.
	* returns the list of column names
	*/
	public List getColumnNames() {
		return columnNames;
	}

	/**
	* Method getColumnTypes.
	* returns the list of column names
	*/
	public List getColumnTypes() {
		return columnTypes;
	}

	/**
	* Method getSpreadsheetName.
	* returns the name of the spreadsheet
	*/
	public String getSpreadsheetName() {
		return tableName;
	}

	/**
	* Method reloadSpreadsheetModelAlternate.
	* Reloads the TableModel with the contents of specified fileName.
	* This alternative version uses the iterators provided by POI/HSSF to demonstrate additional features.  It cannot guarantee correct column ordering.
	* @param tableName table with which to reload the TableModel
	* @exception SQLException if a database error occurs
	* @exception ClassNotFoundException
	*/
	public void reloadSpreadsheetModelAlternate(String fileName) throws IOException {
		// Use POI to read the selected Excel Spreadsheet
		HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(fileName));
		// Extract the name of the first worksheet and use this for the tableName
		tableName =  wb.getSheetName(0);
		// Select the first worksheet
		HSSFSheet sheet = wb.getSheet(tableName); 		    
		try {
			clearAll();
			updateColumnModelAlternate(fileName);
			// Use the iterators provided by POI to step through the rows and columns
			Iterator rowiter = sheet.rowIterator();
			// Skip the first row, the column names are extracted from this row.
			if (rowiter.hasNext()) {
				HSSFRow row = (HSSFRow)(rowiter.next());
			}
//			for(row = (HSSFRow)(rowiter.next()); row != null; row = rowiter.hasNext() ? (HSSFRow)(rowiter.next()) : null) {
			while (rowiter.hasNext()) {
				HSSFRow row=(HSSFRow)(rowiter.next()); 
				// Store the row in a list
				ArrayList list = new ArrayList();
				Iterator celliter = row.cellIterator();
//				for(HSSFCell cell = (HSSFCell)(celliter.next()); cell != null; cell = celliter.hasNext() ? (HSSFCell)(celliter.next()) : null) {
				while (celliter.hasNext()) {
					HSSFCell cell=(HSSFCell)(celliter.next());
					// Add each cell to the row
					list.add(cell);
				}
				// Store the row in a list of lists
				result.add(list);
			}
			// Use the HFFS functions for the number of rows & columns, instead of computing them ourselves
			rowCount = sheet.getPhysicalNumberOfRows()-1;
			colCount = sheet.getRow(0).getPhysicalNumberOfCells();
			fireTableStructureChanged();
		// Catch all Exceptions, most likely a POI error
		} catch (Exception e) {
			System.out.println("A POI error has occured.");
			e.printStackTrace();
		}
    }

	/**
	* Method reloadSpreadsheetModel.
	* Reloads the TableModel with the contents of specified fileName.
	* @param tableName table with which to reload the TableModel
	* @exception SQLException if a database error occurs
	* @exception ClassNotFoundException
	*/
	public void reloadSpreadsheetModel(String fileName) throws IOException {
		// Use POI to read the selected Excel Spreadsheet
		HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(fileName));
		// Extract the name of the first worksheet and use this for the tableName
		tableName =  wb.getSheetName(0);
		// Select the first worksheet
		HSSFSheet sheet = wb.getSheet(tableName); 		    
		try {
			clearAll();
//			System.out.println("Updating model...");
			updateColumnModel(fileName);
			// Use the HFFS functions for the number of rows & columns, instead of computing them ourselves
//			System.out.println("Getting Spreadsheet Dimensions...");
			rowCount = sheet.getPhysicalNumberOfRows();
			colCount = sheet.getRow(0).getPhysicalNumberOfCells();
//			System.out.println("Number of rows ==" + rowCount);
//			System.out.println("Number of cols ==" + colCount);
			// Skip the first row, the column names are extracted from this row.
			for(int i = 1; i < rowCount; i++) {
				// Get row number i
//				System.out.println("Getting row  " + i);
				HSSFRow row = sheet.getRow(i); 
				// Store the row in a list
				ArrayList list = new ArrayList();
				for(short j = 0; j <colCount; j++) {
					// Add each cell to the row
//					System.out.println("Getting cell " + j);
					list.add(row.getCell(j));
				}
				// Store the row in a list of lists
				result.add(list);
			}
			// Remove one row from the rowCount, since the first row is assumed to be the column names 
			rowCount--;
//			System.out.println("Done");
			fireTableStructureChanged();
		// Catch all Exceptions, most likely a POI error
		} catch (Exception e) {
			System.out.println("A POI error has occured.");
			e.printStackTrace();
		}
    }

	/**
	* Method updateColumnModelAlternate.
	* Extracts column metadata from the specified fileName.
	* This alternative version uses the iterators provided by POI/HSSF to demonstrate additional features.  It cannot guarantee correct column ordering.
	* @param fileName
	* @throws IOException
	*/
	private void updateColumnModelAlternate(String fileName) throws IOException {
		// Use POI to read the selected Excel Spreadsheet
		HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(fileName));
		// Extract the name of the first worksheet and use this for the tableName
		String tableName =  wb.getSheetName(0);
		// Select the first worksheet
		HSSFSheet sheet = wb.getSheet(tableName);
		// Extract column names from the first row
		HSSFRow row = sheet.getRow(0);
		// Use the iterators provided by POI to step through the rows and columns
		Iterator celliter = row.cellIterator();
		try {
//			for(HSSFCell cell = (HSSFCell)(celliter.next()); cell != null; cell = celliter.hasNext() ? (HSSFCell)(celliter.next()) : null) {
			while(celliter.hasNext()) {
			  HSSFCell cell= (HSSFCell)(celliter.next());
				// Get the Column names from each cell
				columnNames.add(cell.getStringCellValue());
			}
			// Extract column types from first non-empty row
			// Set a flag when we have found a non-empty row
			boolean found = false;
			// Use the iterators provided by POI to step through the rows and columns
			Iterator rowiter=sheet.rowIterator();
			// Skip the first row, the column names are extracted from this row.
			if (rowiter.hasNext()) {
				row = (HSSFRow)(rowiter.next());
			}
//			for(row = (HSSFRow)(rowiter.next()); row != null && !found; row = rowiter.hasNext() ? (HSSFRow)(rowiter.next()) : null) {
			while (rowiter.hasNext()) {
				row = (HSSFRow)(rowiter.next());
				ArrayList list = new ArrayList();
				// To check if the row is blank, inspect the first column only
				if (row.getCell((short)0).getCellType() != HSSFCell.CELL_TYPE_BLANK) {
					found=true;
					celliter = row.cellIterator();
//					for(HSSFCell cell = (HSSFCell)(celliter.next()); cell != null; cell = celliter.hasNext() ? (HSSFCell)(celliter.next()) : null) {
					while (celliter.hasNext()) {
						HSSFCell cell=(HSSFCell)(celliter.next());
						columnTypes.add(new Integer(cell.getCellType()));
					}
				}
			}
		// Catch all Exceptions, most likely a POI error
		} catch (Exception e) {
			System.out.println("A POI error has occured.");
			e.printStackTrace();
		}
	}

	/**
	* Method updateColumnModel.
	* Extracts column metadata from the specified fileName.
	* @param fileName
	* @throws IOException
	*/
	private void updateColumnModel(String fileName) throws IOException {
		// Use POI to read the selected Excel Spreadsheet
		HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(fileName));
		// Extract the name of the first worksheet and use this for the tableName
		String tableName =  wb.getSheetName(0);
		// Select the first worksheet
		HSSFSheet sheet = wb.getSheet(tableName);
		// Extract column names from the first row
		HSSFRow row = sheet.getRow(0);
		try {
//			System.out.println("Updating model...");
			for(short j = 0; j < row.getPhysicalNumberOfCells(); j++) {
//			System.out.println("Getting column name " + j + row.getCell(j).getStringCellValue());
				// Get the Column names from each cell
				columnNames.add(row.getCell(j).getStringCellValue());
			}
			// Extract column types from first non-empty row
			// Set a flag when we have found a non-empty row
//			System.out.println("Setting Flag");
			boolean found = false;
			// Skip the first row, the column names are extracted from this row.
			for(int i = 1; (i < sheet.getPhysicalNumberOfRows()) && !found; i++) {
				// Get row number i 
//				System.out.println("Getting row " + i);
				row = sheet.getRow(i);
				ArrayList list = new ArrayList();
				// To check if the row is blank, inspect the first column only
				if (row.getCell((short)0).getCellType() != HSSFCell.CELL_TYPE_BLANK) {
//					System.out.println("Non-empty row found");
					found=true;
					for(short j = 0; j < row.getPhysicalNumberOfCells(); j++) {
//						System.out.println("Getting cell " + j);
						columnTypes.add(new Integer(row.getCell(j).getCellType()));
					}
				}
			}
		// Catch all Exceptions, most likely a POI error
		} catch (Exception e) {
			System.out.println("A POI error has occured.");
			e.printStackTrace();
		}
	}

	/**
	* Method clearAll.
	* clears the TableModel
	*/
    private void clearAll() {
    	// Clear each List representing each row
		for (int i = 0; i < result.size(); i++) {
			ArrayList list = (ArrayList) result.get(i);
			list.clear();
		}
		// Clear all rows
		result.clear();
		// Clear Metadata
		columnNames.clear();
		columnTypes.clear();
		// Clear the row and column counts
		colCount = 0;
		rowCount = 0;
	}

	/**
	* Method getRow.
	* @param i
	* @return List
	*/
	public List getRow(int i) {
		return (List)(result.get(i));
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人精品视频一区二区三区| 亚洲人成网站色在线观看| 欧美综合一区二区| 91丨九色丨蝌蚪丨老版| 99久久国产免费看| 91色porny| 欧美日韩你懂得| 这里只有精品99re| 精品精品国产高清一毛片一天堂| 亚洲精品一区在线观看| 2020国产成人综合网| 久久久久久久久蜜桃| 国产精品久久久久影院老司| 中文字幕一区二区日韩精品绯色| 日韩美女视频一区二区| 亚洲高清免费一级二级三级| 午夜久久久影院| 国内精品久久久久影院色 | 欧美午夜一区二区三区免费大片| 91久久精品网| 91精品一区二区三区久久久久久| 日韩欧美国产三级| 国产精品女主播av| 亚洲国产精品久久人人爱| 免费成人在线网站| 不卡视频一二三四| 欧美区在线观看| 国产欧美一区二区三区鸳鸯浴| 亚洲人成精品久久久久| 蜜臀99久久精品久久久久久软件| 国产成人精品亚洲777人妖| 色哟哟精品一区| 精品国产一区二区亚洲人成毛片| 国产精品久久久久影院色老大| 首页国产欧美久久| 高清国产一区二区| 欧美一卡二卡在线| 国产精品久久久久影视| 蜜臀av一区二区在线观看| www.在线欧美| 精品久久久久久综合日本欧美| 一区在线观看视频| 国产一区二区在线电影| 欧美精三区欧美精三区| 欧美国产97人人爽人人喊| 日日噜噜夜夜狠狠视频欧美人| 波多野结衣在线一区| 日韩欧美成人午夜| 亚洲成人动漫在线免费观看| 成人国产一区二区三区精品| 精品理论电影在线| 亚洲成精国产精品女| 久久精品国产99| 色94色欧美sute亚洲线路一ni| 国产欧美日韩精品a在线观看| 日韩福利电影在线| 欧美视频第二页| 亚洲美女视频在线观看| 国产成人精品亚洲日本在线桃色| 日韩精品一区二区在线观看| 亚洲国产一区二区在线播放| 91在线观看美女| 国产精品免费av| 成人激情电影免费在线观看| 国产亚洲一区字幕| 国产综合色产在线精品| 精品少妇一区二区三区在线视频| 污片在线观看一区二区| 欧美日韩一区 二区 三区 久久精品| 亚洲欧美偷拍另类a∨色屁股| 成人毛片在线观看| 国产精品久久久久三级| 成人av电影在线观看| 国产精品美女久久久久久| 成人免费毛片aaaaa**| 国产精品视频一二| 成人av网址在线观看| 国产精品久久久久四虎| 91在线精品秘密一区二区| 国产精品国产三级国产aⅴ中文| 成人av资源在线| 亚洲精品国产一区二区精华液| 色屁屁一区二区| 婷婷国产在线综合| 日韩一区二区电影网| 国内久久精品视频| 欧美国产禁国产网站cc| 99久久久久久| 亚洲chinese男男1069| 欧美一区2区视频在线观看| 激情小说亚洲一区| 国产精品久久久久久久久晋中 | 成人avav在线| 亚洲精品欧美激情| 欧美日韩免费观看一区二区三区| 亚洲r级在线视频| 欧美大片国产精品| 成人丝袜视频网| 亚洲成人精品一区| 精品国产电影一区二区| 成人精品小蝌蚪| 亚洲综合清纯丝袜自拍| 日韩精品中文字幕一区| 国产乱对白刺激视频不卡| 国产精品电影院| 制服.丝袜.亚洲.中文.综合| 国产精品99久| 一区二区三区四区亚洲| 精品乱码亚洲一区二区不卡| 北岛玲一区二区三区四区| 亚洲国产aⅴ成人精品无吗| 日韩欧美资源站| 成人高清免费观看| 日日夜夜免费精品| 国产精品美女久久久久久久久| 欧美三级视频在线播放| 精品一区二区三区在线播放视频| 亚洲三级电影网站| 欧美一区二区免费视频| www.av精品| 精品亚洲国产成人av制服丝袜| 一区二区三区资源| 精品国产一区二区三区久久影院| 在线观看国产日韩| 成人高清在线视频| 激情av综合网| 蜜乳av一区二区| 亚洲第一av色| 亚洲精品写真福利| 日本一区二区三区在线观看| 欧美一区二区三区电影| 91亚洲国产成人精品一区二区三| 精品夜夜嗨av一区二区三区| 蜜臀久久久99精品久久久久久| 亚洲美女区一区| 亚洲国产精品精华液2区45| 精品国偷自产国产一区| 日韩一区二区三区三四区视频在线观看 | 亚洲电影视频在线| 亚洲欧美国产77777| 亚洲国产成人午夜在线一区 | 亚洲欧洲在线观看av| 2023国产精品自拍| 精品国产乱码久久久久久蜜臀 | 成人一区二区三区在线观看| 寂寞少妇一区二区三区| 免费观看在线色综合| 欧美aⅴ一区二区三区视频| 亚洲午夜久久久久久久久电影院| 中文字幕一区二区三| 中文字幕一区二区三区乱码在线| 国产精品久久免费看| 国产精品久久久久aaaa| 日本一二三四高清不卡| 国产精品传媒在线| 亚洲色图欧美激情| 亚洲精品视频免费观看| 亚洲v中文字幕| 日韩av电影免费观看高清完整版| 日日摸夜夜添夜夜添亚洲女人| 日韩成人精品在线| 韩国欧美国产一区| 成人性生交大片免费看视频在线| 成人av集中营| 在线看一区二区| 正在播放一区二区| 久久久五月婷婷| 中文字幕一区免费在线观看| 亚洲精选视频免费看| 亚洲福利视频一区二区| 天天综合网 天天综合色| 日韩精品每日更新| 国内精品伊人久久久久av一坑| 成人深夜福利app| 欧美视频精品在线观看| 精品久久人人做人人爽| 国产精品第五页| 日韩福利电影在线| 成人综合激情网| 欧美日韩视频在线第一区| 精品国产网站在线观看| 亚洲色欲色欲www在线观看| 午夜成人在线视频| 国产精品一区久久久久| 91国偷自产一区二区三区观看 | 日韩精品免费专区| 国产69精品久久777的优势| 色婷婷综合激情| 精品国产一区二区三区久久久蜜月 | 在线观看国产一区二区| 日韩欧美黄色影院| 国产精品国产三级国产普通话蜜臀 | 国产精品美女久久久久久2018| 亚洲va国产天堂va久久en| 国产成人在线影院 | 开心九九激情九九欧美日韩精美视频电影 | 久久久午夜精品| 午夜国产不卡在线观看视频| 国产精品一二三四五| 欧美日韩成人在线|