⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exportdao.java

📁 一个优秀的干洗店管理系统
💻 JAVA
字号:
package dao.export;

import java.io.File;
import java.util.Vector;

import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;

import view.common.ExcelFileFilterImpl;
import control.export.ExportInfo;

public class ExportDao {
	private JFileChooser fileChooser;
	private JDialog dialog;
	public ExportDao(JDialog dialog){
		this.dialog = dialog;
	}
	public void export(JTable table,String headTitle,String[] head){
		String fileName = null;
		fileChooser = new JFileChooser();
		fileChooser.setCurrentDirectory(new File("."));// 指定文件保存位置
		fileChooser.addChoosableFileFilter(new ExcelFileFilterImpl("xls"));
		File file = null;
		if (fileName == null) {
			int result = fileChooser.showSaveDialog(dialog);
			if (result == JFileChooser.APPROVE_OPTION) {
				file = fileChooser.getSelectedFile();
				fileName = file.getAbsolutePath();
			} else {
				return;
			}
		}

		try {
//			ExportClothesList exportAction = new ExportClothesList();
			ExportInfo ex = new ExportInfo();
			String fileNameSave = file.getAbsolutePath() + fileName;
			Vector data = getTableData(table);
			/*String headTitle = "会员消费记录";
			String[] head = {"交易单号", "添加日期", "取衣日期", "应收金额", "实收金额", "优惠金额",
					"会员编号", "会员名称", "联系手机", "衣服状态", "备注", "储值卡" };*/
			ex.writeExcelOfFile(fileName, data, null,headTitle,head);
			// 记录到数据库中去
//			String content = "导出信息 ";
			JOptionPane.showMessageDialog(null, "报表已经导出!");
		} catch (Exception ex) {
			System.out.println("导出message: " + ex.getMessage());
		}		
	}	
	
	public Vector getTableData(JTable table) {
		int columns = table.getColumnCount();
		int rows = table.getRowCount();
		// String[] data = new String[columns];
		Vector datas = new Vector();
		for (int i = 0; i < rows; i++) {
			Vector v = new Vector();
			for (int j = 0; j < columns; j++) {
				if (table.getValueAt(i, j).toString() != null) {
					v.add(table.getValueAt(i, j).toString());
//					System.out.println(table.getValueAt(i, j).toString());
				} else {
					v.add(" ");
					System.out.println(table.getValueAt(i, j).toString());
				}
				// System.out.println(table.getValueAt(i, j));
			}
			datas.addElement(v);
		}
		return datas;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -