/**
*
*/
package excelOperation;
/**
* 该方法的主要作用是将EXCEL表中英文字符串的单词首字母转换为大写
*/
import java.awt.Frame;
import java.io.File;
import java.io.IOException;
import java.util.*;
import javax.swing.JFileChooser;
import com.CommonFunction;
import jxl.*;
import jxl.read.biff.BiffException;
import jxl.write.*; //import jxl.write.Boolean;
import jxl.write.biff.RowsExceededException;
public class ExcelOperation
{
private Workbook workbook;
private Sheet sheet;
public static void main(String[] arges) {
Frame frame = new Frame();
int countFlag = 0;
String[] fileNames = null;
fileNames = CommonFunction.getSelectedFile(frame,
"C://Documents and Settings//Administrator//桌面");
if (fileNames!=null)
{
String fileName = fileNames[0];
String fileNameB = fileName.substring(0,
fileName.lastIndexOf("//") + 1)
+ "END"
+ fileName.substring(fileName.lastIndexOf("//") + 1,
fileName.length());
Workbook workBook_Source = null;
WritableWorkbook writeWorkBook_Middle = null;
try {
try {
workBook_Source = Workbook.getWorkbook(new File(fileName));
} catch (BiffException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
writeWorkBook_Middle = Workbook.createWorkbook(new File(
fileNameB));
writeWorkBook_Middle.createSheet("msg", 0);// -------------------------------------------------------------------
writeWorkBook_Middle.createSheet("ss", 1);
writeWorkBook_Middle.createSheet("sbc", 2);
Sheet workBook_Source_Sheet = workBook_Source.getSheet(0);
int rowNumbers = workBook_Source_Sheet.getRows();
int columnNumbers = workBook_Source_Sheet.getColumns();
Cell[] cell = new Cell[columnNumbers];
String[] value = new String[columnNumbers];
Label[] label = new Label[columnNumbers];
int globalj = 0;
for (int i = 0, realrow = 0; i < rowNumbers; i++) {
for (int j = 0; j < columnNumbers; j++) {
if (workBook_Source_Sheet.getCell(1, i) != null) {
cell[j] = workBook_Source_Sheet.getCell(j, i);
}
// 获取的值都经过过滤前后空格符的内容
if (cell[j] != null) {
value[j] = cell[j].getContents().trim();
}
if (value[j] != null) {
if (j == 1) {
String[] sb = value[1].split(" ");
String ss = "";
for (int k = 0; k < sb.length; k++) {
if (!sb[k].trim().equals("")) {
sb[k] = sb[k].substring(0, 1)
.toUpperCase()
+ sb[k].substring(1);
}
}
for (int m = 0; m < sb.length; m++) {
ss = ss + sb[m];
// ss.append(" ");
}
value[1] = ss;
}
label[j] = new Label(j, realrow, value[j]);
}
}
if (!(value[0].equals("") && value[1].equals("")
&& value[2].equals("") && value[3].equals(""))) {
for (int j = 0; j < 4; j++) {
writeWorkBook_Middle.getSheet(0).addCell(label[j]);
}
System.out.println(realrow);
realrow = realrow + 1;
}
}
writeWorkBook_Middle.write();
writeWorkBook_Middle.close();
workBook_Source.close();
System.out.println("---------------------------------ok");
} catch (Exception e) {
e.printStackTrace();
}
workBook_Source.close();
}
}
}