📄 errorinfoexcel.java
字号:
/********************************************************************
*
* $RCSfile: ErrorInfoExcel.java,v $ $Revision: 1.1 $ $Date: 2003/09/22 08:06:24 $
*
* $Log: ErrorInfoExcel.java,v $
* Revision 1.1 2003/09/22 08:06:24 icestone
* init
*
*
*
**********************************************************************/
package pcdmupgradedata;
/**
* <p>Title: 写错误信息到Excel文件类</p>
*/
import java.io.*;
import java.util.Vector;
import java.sql.*;
import jxl.*;
import jxl.write.*;
public class ErrorInfoExcel {
private WritableWorkbook workbook; //Excel文件的 Book
private WritableSheet sheet; //Excel文件的 Sheet
public ErrorInfoExcel(){
}
/**创建Excel文件*/
public void createExcel(String strFileName, //文件名(..\\..\\c.xls)
String strTableName){ //设施表名
try{
strFileName = strFileName + ".xls";
workbook = Workbook.createWorkbook((new File(strFileName)));
sheet = workbook.createSheet(strTableName,0) ;
}catch(IOException e){
Debug.print("createExcel:" + e.toString());
}
}
/**关闭Excel文件*/
public void closeExcel(){
try{
workbook.write();
workbook.close();
}catch(IOException e){
Debug.print("closeExcel:" + e.toString());
}
}
/**把表的Title写入Excel*/
public void writeExcelTitle(ResultSet rset){
Label cell = null;
int intRowNum = 0; //Sheet的第一行
int intCols; //ResultSet的字段总数
String strFieldName = null; //ResultSet字段名
int i;
try {
intCols = rset.getMetaData().getColumnCount();
for(i=0; i<intCols; i++){
strFieldName = rset.getMetaData().getColumnName(i+1);
cell = new Label(i,intRowNum,strFieldName);
sheet.addCell(cell);
//重新实例化Cell对象
cell = null;
}
}catch(SQLException e){
Debug.print(e.toString());
}catch(Exception e1){
Debug.print(e1.toString());
}
}
/**把错误信息 写入 Excel*/
public void writeExcelRow(String strError, //错误提示字符串
ResultSet rset){ //数据表结果集
Label cell = null;
int intRowNum = 0; //Sheet的行数
int intCols; //ResultSet的字段总数
String strFieldName = null; //ResultSet字段名
int i;
try {
intCols = rset.getMetaData().getColumnCount();
intRowNum = sheet.getRows();
//写入错误信息
cell = new Label(intCols,intRowNum,strError);
sheet.addCell(cell);
//把字段内容写入Excel
for(i=1;i <= intCols;i++){
strFieldName = rset.getString(i);
intRowNum = intRowNum + 1;
cell = new Label(i,intRowNum,strFieldName);
sheet.addCell(cell);
//重新实例化Cell对象
cell = null;
}//end of for
}catch(SQLException e){
Debug.print(e.toString());
}catch(Exception e1){
Debug.print(e1.toString());
}
}
/**把错误字段值 写入 Excel*/
public void writeExcelRow(String strError, //错误提示字符串
Vector vResult){ //数据表结果集
Label cell = null;
int intRowNum = 0; //Sheet的行数
int intCols; //Vector的字段总数
String strFieldName = null; //Vector字段名
int i;
try {
intCols = vResult.size();
intRowNum = sheet.getRows();
//把字段内容写入Excel
for(i=0;i < intCols;i++){
strFieldName = (String)vResult.elementAt(i);
cell = new Label(i,intRowNum,strFieldName);
sheet.addCell(cell);
//重新实例化Cell对象
cell = null;
}//end of for
//写入错误信息
cell = new Label(intCols+1,intRowNum,strError);
sheet.addCell(cell);
}catch(Exception e){
Debug.print(e.toString());
}
}
/**把错误信息 写入 Excel*/
public void writeExcelRow(String strError, //错误提示字符串
String strSql ){ //出错的Sql语句
Label cell = null;
int intRowNum = 0; //Sheet的行数
int i;
try {
intRowNum = sheet.getRows();
//写入错误信息
cell = new Label(0,intRowNum,strError);
sheet.addCell(cell);
//cell = null;
cell = new Label(1,intRowNum,strSql);
sheet.addCell(cell);
}catch(Exception e1){
Debug.print("writeExcelRow:" + e1.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -