Author: lazylt
(2010/01/09 23:26) Over 2 years ago
Changes made on 1/9/2010 11am.
27
import javax.swing.event.TableModelEvent;
28
import javax.swing.event.TableModelListener;
29
import javax.swing.table.TableModel;
30
import jxl.Workbook;
31
import jxl.write.WritableSheet;
32
import jxl.write.WritableWorkbook;
33
import jxl.write.WriteException;
34
35
class ropingExample implements ActionListener, TableModelListener{
36
JFrame frame;
...
45
int rounds = 4;
41
46
String[] columnNames;
42
47
private WriteExcelFile ropingDataExcelFile;
43
48
private WritableSheet ropingDataSheet;
49
private File ropingDataFileName = new File("RopingData.xls");
44
50
51
ropingExample() throws WriteException{
ropingExample(){
52
try {
ropingDataExcelFile = new WriteExcelFile();
53
ropingDataExcelFile.setOutputFile("RopingData.xls");
54
ropingDataExcelFile.setSheet("Roping Data", 0);
55
56
}
57
catch (IOException ex) {
58
Logger.getLogger(ropingExample.class.getName()).log(Level.SEVERE, null, ex);
59
60
catch (WriteException ex){
61
62
63
rows = new Vector();
64
columns = new Vector();
65
167
deletRow(table.getSelectedRow());
154
168
155
169
if(source.getSource() == (JButton)saveFile){
156
170
157
171
saveDataExcel();
158
172
String msg = "Data Saved to " + ropingDataFileName.getName();
159
173
JOptionPane.showMessageDialog(null, msg, "Table Example", JOptionPane.INFORMATION_MESSAGE);
160
174
} catch (IOException ex) {
175
176
} catch (WriteException ex) {
177
178
179
161
180
162
181
if(source.getSource() == (JButton)cmdGetValue){
163
207
return colNames;
189
208
190
209
191
210
public void saveDataExcel() throws IOException, WriteException{
192
public void saveDataExcel(){
211
ropingDataExcelFile.write("Roping Data");
193
212
194
213
195
215
* @param args the command line arguments
197
216
*/
198
217
public static void main(String[] args) {
199
218
200
ropingExample t = new ropingExample();
219
220
221
222
223
201
224
202
7
import java.io.IOException;
8
import java.util.Locale;
9
import java.util.Vector;
10
import java.util.logging.Level;
11
import java.util.logging.Logger;
12
import javax.swing.JOptionPane;
import jxl.CellView;
13
14
import jxl.WorkbookSettings;
15
Vector rows, columns;
public WriteExcelFile() throws WriteException, IOException{
37
public WriteExcelFile(){
38
// Lets create a times font
39
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
40
// Define the cell format
times = new WritableCellFormat(times10pt);
// Lets automatically wrap the cells
times.setWrap(true);
WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);
timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
timesBoldUnderline.setWrap(true);
CellView cv = new CellView();
cv.setFormat(times);
cv.setFormat(timesBoldUnderline);
cv.setAutosize(true);
inputFile = "Test.xls";
excelFile = new File(inputFile);
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
workbook = Workbook.createWorkbook(excelFile, wbSettings);
workbook.createSheet("Test Data", 0);
String msg = "Error: " + ex.toString();
JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.INFORMATION_MESSAGE);
}catch (IOException ex) {
66
// Create create a bold font with unterlines
WritableFont times10ptBoldUnderline = new WritableFont(
WritableFont.TIMES, 10, WritableFont.BOLD, false,
UnderlineStyle.SINGLE);
67
68
public void setOutputFile(String inputFile) throws IOException {
69
public void setOutputFile(String inputFile){
this.inputFile = inputFile;
70
71
72
73
74
75
76
77
78
79
80
81
public void write(String name) throws IOException, WriteException {
82
public void write(String name){
WritableSheet sheet = workbook.getSheet(name);
83
createContent(sheet);
84
workbook.write();
85
workbook.close();
86
87
88
89
90
91
92
93
94
95
96
public void setSheet(String name, int sheetNumber){
97
rows = row;
106
107
108
// public void setColomns(Vector col){
// columns = col;
// }
//
// public void setRowsColumns(Vector row, Vector col){
// setRows(row);
// setColomns(col);
98
private void createContent(WritableSheet ws)throws WriteException,
109
99
RowsExceededException {
110
100
111
import jxl.Workbook;import jxl.write.WritableSheet;import jxl.write.WritableWorkbook;import jxl.write.WriteException;class ropingExample implements ActionListener, TableModelListener{class ropingExample implements ActionListener, TableModelListener{private WritableSheet ropingDataSheet;private File ropingDataFileName = new File("RopingData.xls");private File ropingDataFileName = new File("RopingData.xls");ropingExample() throws WriteException{ropingExample(){try {ropingDataExcelFile = new WriteExcelFile();ropingDataExcelFile = new WriteExcelFile();ropingDataExcelFile.setOutputFile("RopingData.xls");ropingDataExcelFile.setOutputFile("RopingData.xls");ropingDataExcelFile.setSheet("Roping Data", 0);ropingDataExcelFile.setSheet("Roping Data", 0);}catch (IOException ex) {Logger.getLogger(ropingExample.class.getName()).log(Level.SEVERE, null, ex);}catch (WriteException ex){Logger.getLogger(ropingExample.class.getName()).log(Level.SEVERE, null, ex);}if(source.getSource() == (JButton)saveFile){if(source.getSource() == (JButton)saveFile){try {saveDataExcel();String msg = "Data Saved to " + ropingDataFileName.getName();JOptionPane.showMessageDialog(null, msg, "Table Example", JOptionPane.INFORMATION_MESSAGE);} catch (IOException ex) {Logger.getLogger(ropingExample.class.getName()).log(Level.SEVERE, null, ex);} catch (WriteException ex) {Logger.getLogger(ropingExample.class.getName()).log(Level.SEVERE, null, ex);}if(source.getSource() == (JButton)cmdGetValue){if(source.getSource() == (JButton)cmdGetValue){public void saveDataExcel() throws IOException, WriteException{public void saveDataExcel(){ropingDataExcelFile.write("Roping Data");ropingDataExcelFile.write("Roping Data");public static void main(String[] args) {public static void main(String[] args) {try {ropingExample t = new ropingExample();ropingExample t = new ropingExample();} catch (WriteException ex) {Logger.getLogger(ropingExample.class.getName()).log(Level.SEVERE, null, ex);}public WriteExcelFile() throws WriteException, IOException{public WriteExcelFile(){try {WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);// Define the cell formattimes = new WritableCellFormat(times10pt);// Lets automatically wrap the cellstimes.setWrap(true);WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);// Lets automatically wrap the cellstimesBoldUnderline.setWrap(true);CellView cv = new CellView();cv.setFormat(times);cv.setFormat(timesBoldUnderline);cv.setAutosize(true);inputFile = "Test.xls";excelFile = new File(inputFile);WorkbookSettings wbSettings = new WorkbookSettings();wbSettings.setLocale(new Locale("en", "EN"));workbook = Workbook.createWorkbook(excelFile, wbSettings);workbook.createSheet("Test Data", 0);} catch (WriteException ex) {String msg = "Error: " + ex.toString();JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.INFORMATION_MESSAGE);}catch (IOException ex) {String msg = "Error: " + ex.toString();JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.INFORMATION_MESSAGE);}// Create create a bold font with unterlinesWritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false,UnderlineStyle.SINGLE);timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);// Lets automatically wrap the cellstimesBoldUnderline.setWrap(true);CellView cv = new CellView();cv.setFormat(times);cv.setFormat(timesBoldUnderline);cv.setAutosize(true);inputFile = "Test.xls";excelFile = new File(inputFile);WorkbookSettings wbSettings = new WorkbookSettings();wbSettings.setLocale(new Locale("en", "EN"));workbook = Workbook.createWorkbook(excelFile, wbSettings);workbook.createSheet("Test Data", 0);public void setOutputFile(String inputFile) throws IOException {public void setOutputFile(String inputFile){wbSettings.setLocale(new Locale("en", "EN"));wbSettings.setLocale(new Locale("en", "EN"));workbook = Workbook.createWorkbook(excelFile, wbSettings);try {workbook = Workbook.createWorkbook(excelFile, wbSettings);} catch (IOException ex) {String msg = "Error: " + ex.toString();JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.INFORMATION_MESSAGE);}public void write(String name) throws IOException, WriteException {public void write(String name){WritableSheet sheet = workbook.getSheet(name);try {createContent(sheet);WritableSheet sheet = workbook.getSheet(name);workbook.write();createContent(sheet);workbook.close();workbook.write();workbook.close();} catch (WriteException ex) {String msg = "Error: " + ex.toString();JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.INFORMATION_MESSAGE);} catch (IOException ex) {String msg = "Error: " + ex.toString();JOptionPane.showMessageDialog(null, msg, "Error", JOptionPane.INFORMATION_MESSAGE);}public void setSheet(String name, int sheetNumber){public void setSheet(String name, int sheetNumber){// public void setColomns(Vector col){// columns = col;// }//// public void setRowsColumns(Vector row, Vector col){// setRows(row);// setColomns(col);// }//RowsExceededException {RowsExceededException {