package operateExcel;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class ReadDescription {
public static void main(String[] args) {
// TODO Auto-generated method stub
//execl file
File excelFile=new File("C:\\documents\\在研项目\\多层分类\\中文新闻信息分类与代码\\classificationDescription.xls");
File newTxtFile=null; //new .txt file
String newTxtFilePath="C:\\file\\program file\\a"; //the path of new .txt file
try {
Workbook book = Workbook.getWorkbook(excelFile);
// 获得第一个工作表对象(Sheet)
Sheet sheet = book.getSheet(0);
Integer lineNumber=1; //the line number
Integer lineFlag=7119; //the total line number
while(lineNumber<lineFlag){
// 得到第0列第lineNumber行的单元格
Cell code = sheet.getCell(0, lineNumber);
String codeStr = code.getContents().trim();
// 得到第1列第lineNumber行的单元格
Cell className = sheet.getCell(1, lineNumber);
String classNameStr = className.getContents().trim();
// 得到第1列第lineNumber行的单元格
Cell description = sheet.getCell(2, lineNumber);
String descriptionStr = description.getContents().trim();
if(codeStr!=""&&!codeStr.equals("")){ //if code is not the null String
String txtFileName=codeStr+".txt"; //the name of txtFile
/*create file and write content*/
newTxtFile=new File(newTxtFilePath,txtFileName);
newTxtFile.createNewFile();
FileWriter fw=new FileWriter(newTxtFile);
BufferedWriter bw=new BufferedWriter(fw);
bw.write(classNameStr);
bw.newLine();
bw.write(descriptionStr);
bw.flush();
bw.close();
}
lineNumber++; //line number add 1
}
book.close();
} catch (Exception e) {
System.out.println(e);
}
}
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class ReadDescription {
public static void main(String[] args) {
// TODO Auto-generated method stub
//execl file
File excelFile=new File("C:\\documents\\在研项目\\多层分类\\中文新闻信息分类与代码\\classificationDescription.xls");
File newTxtFile=null; //new .txt file
String newTxtFilePath="C:\\file\\program file\\a"; //the path of new .txt file
try {
Workbook book = Workbook.getWorkbook(excelFile);
// 获得第一个工作表对象(Sheet)
Sheet sheet = book.getSheet(0);
Integer lineNumber=1; //the line number
Integer lineFlag=7119; //the total line number
while(lineNumber<lineFlag){
// 得到第0列第lineNumber行的单元格
Cell code = sheet.getCell(0, lineNumber);
String codeStr = code.getContents().trim();
// 得到第1列第lineNumber行的单元格
Cell className = sheet.getCell(1, lineNumber);
String classNameStr = className.getContents().trim();
// 得到第1列第lineNumber行的单元格
Cell description = sheet.getCell(2, lineNumber);
String descriptionStr = description.getContents().trim();
if(codeStr!=""&&!codeStr.equals("")){ //if code is not the null String
String txtFileName=codeStr+".txt"; //the name of txtFile
/*create file and write content*/
newTxtFile=new File(newTxtFilePath,txtFileName);
newTxtFile.createNewFile();
FileWriter fw=new FileWriter(newTxtFile);
BufferedWriter bw=new BufferedWriter(fw);
bw.write(classNameStr);
bw.newLine();
bw.write(descriptionStr);
bw.flush();
bw.close();
}
lineNumber++; //line number add 1
}
book.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
参考文章:http://www.cnblogs.com/sunzhenxing19860608/archive/2010/12/27/1918128.html