Excel文件(xls)解析JAVA
题目描述
提取表格中”岗位职责“一列的所有数据,以文本格式保存
工具
①JAVA ②jxl.jar包(一个java对excel文件编辑的基础工具包)
代码实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList;
import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException;
public class test { public static void select_excel(File file) throws Exception { FileWriter fWriter = null; PrintWriter out = null; String fliename = file.getName().replace(".xls", ""); fWriter = new FileWriter(file.getParent() + "/" + fliename + ".txt"); out = new PrintWriter(fWriter); InputStream is = new FileInputStream(file.getAbsoluteFile()); Workbook wb = null; wb = Workbook.getWorkbook(is); int sheet_size = wb.getNumberOfSheets(); Sheet sheet = wb.getSheet(0); for (int j = 1; j < sheet.getRows(); j++) { String cellinfo = sheet.getCell(9, j).getContents(); out.println(cellinfo); } out.close(); fWriter.close(); out.flush(); } public static void main(String[] args) { try { select_excel(new File("E:\\original_info_copy1.xls")); } catch (Exception e) { e.printStackTrace(); } } }
|
)
总结
通过JAVA的jxl实现对excel的操作
I/O流进行读取和选择输出
参考文献:https://blog.csdn.net/cpcpcp123/article/details/82763937?ops_request_misc=&request_id=&biz_id=102&utm_term=xls%E6%95%B0%E6%8D%AE%E6%8F%90%E5%8F%96java&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-.first_rank_v2_pc_rank_v29&spm=1018.2226.3001.4187