java的poi技术读,写Excel[2003-2007,2010]

上一篇blog:java的poi技术读取Excel[2003-2007,2010] 中介绍了关于java中的poi技术读取excel的相关操作

读取excel和MysqL相关:

你也可以在 : 了解到写入Excel的方法信息

使用JXL技术 :java的jxl技术导入Excel 

本文主要讲的是java中poi读和写excel(版本是2003-2007,2010)

效果:

Processing...lib/201401,name : Hongten,age : 22.0,score : 98.0201402,name : Hanyuan,age : 21.0,score : 96.0201403,name : Tom,age : 20.0,score : 94.0201404,name : HanKet,score : 90.0201405,name : Jone,score : 42.0201406,name : Kite,age : 23.0,score : 59.0201407,name : Lucy,age : 25.0,score : 60.0201408,name : Mark,score : 89.0201409,name : Jeson,age : 24.0,score : 79.0201410,name : Steven,score : 59.0201411,name : Tide,score : 88.0201412,name : Deli,score : 89.0201413,name : Goerme,score : 98.0201414,name : Som,score : 95.0 ======================================/201401,score : 95.0 ======================================/student_info_2003-2007/======================================/student_info_2003-2007201401,score : 95.0 ======================================/201401,score : 95.0

main(String[] args) String read_excel2003_2007_path = String read_excel2010_path = List list = (list != System.out.println("No. : " + student.getNo() + ",name : " + student.getName() + ",age : " + student.getAge() + ",score : " +score()); System.out.println("======================================" List list1 = (list1 != System.out.println("No. : " + student.getNo() + ",score : " +score()); System.out.println("======================================" String write_excel2003_2007_path = String write_excel2010_path = System.out.println("======================================" List list2 = (list != System.out.println("No. : " + student.getNo() + ",score : " +score()); System.out.println("======================================" List list3 = (list1 != System.out.println("No. : " + student.getNo() + ",score : " +score()); }

String OFFICE_EXCEL_2003_POSTFIX = "xls" String OFFICE_EXCEL_2010_POSTFIX = "xlsx" String EMPTY = "" String POINT = "." String LIB_PATH = "lib" String STUDENT_INFO_XLS_PATH = LIB_PATH + "/student_info" + POINT + String STUDENT_INFO_XLSX_PATH = LIB_PATH + "/student_info" + POINT + String STUDENT_INFO_XLS_OUT_PATH = "lib/student_info_2003-2007.xls" String STUDENT_INFO_XLSX_OUT_PATH = "lib/student_info_2010.xlsx" String NOT_EXCEL_FILE = " : Not the Excel file!" String PROCESSING = "Processing..." String WRITE_DATA = "write data to file : " }

hssf.usermodel.hssfCell; hssf.usermodel.hssfRichTextString; hssf.usermodel.hssfRow; hssf.usermodel.hssfSheet; hssf.usermodel.hssfWorkbook; usermodel.XSSFCell; usermodel.XSSFRichTextString; usermodel.XSSFRow; usermodel.XSSFSheet; usermodel.XSSFWorkbook; writeExcel(List list,String path) (list == } (path == || } String postfix = (! } } System.out.println(path + aram List readExcel(String path) (path == || } String postfix = (! } } System.out.println(path + aram List readXlsx(String path) System.out.println(Common.PROCESSING + InputStream is = XSSFWorkbook xssfWorkbook = Student student = List list = ArrayList ( numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++ XSSFSheet xssfSheet = (xssfSheet == ( rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++ XSSFRow xssfRow = (xssfRow != student = XSSFCell no = xssfRow.getCell(0 XSSFCell name = xssfRow.getCell(1 XSSFCell age = xssfRow.getCell(2 XSSFCell score = xssfRow.getCell(3 score(Float.valueOf(getValue(score))); aram List readXls(String path) System.out.println(Common.PROCESSING + InputStream is = hssfWorkbook hssfWorkbook = hssfWorkbook(is); Student student = List list = ArrayList ( numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++ hssfSheet hssfSheet =hssfWorkbook.getSheetAt(numSheet); (hssfSheet == ( rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++ hssfRow hssfRow =hssfSheet.getRow(rowNum); (hssfRow != student = hssfCell no = hssfRow.getCell(0 hssfCell name = hssfRow.getCell(1 hssfCell age = hssfRow.getCell(2 hssfCell score = hssfRow.getCell(3 score(Float.valueOf(getValue(score))); @SuppressWarnings("static-access" (xssfRow.getCellType() == } (xssfRow.getCellType() == } @SuppressWarnings("static-access" hssfCell hssfCell) { (hssfCell.getCellType() ==hssfCell.CELL_TYPE_BOOLEAN) { hssfCell.getBooleanCellValue()); } (hssfCell.getCellType() ==hssfCell.CELL_TYPE_NUMERIC) { hssfCell.getNumericCellValue()); } hssfCell.getStringCellValue()); writeXls(List list,String path) (list == countColumnNum = hssfWorkbook book = hssfWorkbook(); hssfSheet sheet = book.createSheet("studentSheet" irst row. hssfRow firstRow = sheet.createRow(0 hssfCell[] firstCells = hssfCell[countColumnNum]; String[] options = { "no","name","age","score" ( j = 0; j < options.length; j++ firstCells[j] =irstRow.createCell(j); firstCells[j].setCellValue(hssfRichTextString(options[j])); ( i = 0; i < countColumnNum; i++ hssfRow row = sheet.createRow(i + 1 Student student = ( column = 0; column < options.length; column++ hssfCell no = row.createCell(0 hssfCell name = row.createCell(1 hssfCell age = row.createCell(2 hssfCell score = row.createCell(3 score.setCellValue(student.getscore()); File file = OutputStream os = System.out.println(Common.WRITE_DATA + writeXlsx(List list,String path) (list == countColumnNum = XSSFWorkbook book = XSSFSheet sheet = book.createSheet("studentSheet" irst row. XSSFRow firstRow = sheet.createRow(0 XSSFCell[] firstCells = String[] options = { "no","score" ( j = 0; j < options.length; j++ firstCells[j] =irstRow.createCell(j); firstCells[j].setCellValue( ( i = 0; i < countColumnNum; i++ XSSFRow row = sheet.createRow(i + 1 Student student = ( column = 0; column < options.length; column++ XSSFCell no = row.createCell(0 XSSFCell name = row.createCell(1 XSSFCell age = row.createCell(2 XSSFCell score = row.createCell(3 score.setCellValue(student.getscore()); File file = OutputStream os = System.out.println(Common.WRITE_DATA + }

aram (path == || path.substring(path.lastIndexOf(Common.POINT) + 1 }

score; .id = .no = .name = .age = score() { score; setscore(score) { .score =score; }

========================================================

More reading,and english is important.

I'm Hongten

<pre class="code"><span style="font-size: 16px; color: #ff0000;">大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。Hongten博客排名在100名以内。粉丝过千。Hongten出品,必是精品。

E | hongtenzone@foxmail.com  B | 

========================================================

相关文章

Java中的String是不可变对象 在面向对象及函数编程语言中,不...
String, StringBuffer 和 StringBuilder 可变性 String不可变...
序列化:把对象转换为字节序列的过程称为对象的序列化. 反序...
先说结论,是对象!可以继续往下看 数组是不是对象 什么是对...
为什么浮点数 float 或 double 运算的时候会有精度丢失的风险...
面试题引入 这里引申出一个经典问题,看下面代码 Integer a ...