📄 copydatatoexcel.java
字号:
package edu.xscj.action;
import javax.swing.JTable;
import java.awt.datatransfer.*;
import java.awt.*;
import javax.swing.JOptionPane;
import java.util.Vector;
public class CopyDataToExcel {
StringBuffer sbf = new StringBuffer();
Clipboard clipboard;
StringSelection strselection;
public CopyDataToExcel() {
}
public void copy(JTable jtable) {
if (jtable == null) {
return;
}
int row = jtable.getRowCount();
int col = jtable.getColumnCount();
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
sbf.append(jtable.getModel().getValueAt(i, j));
if (j < col - 1) {
sbf.append("\t");
}
}
sbf.append("\n");
}
strselection = new StringSelection(sbf.toString());
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(strselection, strselection);
}
public void copyRow(Vector vect) {
int col = vect.size();
for (int i = 0; i < col; i++) {
sbf.append(vect.elementAt(i));
sbf.append("\t");
}
strselection = new StringSelection(sbf.toString());
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(strselection, strselection);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -