91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 12KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-09
  • 語言: Java
  • 標簽: Java??POI??Excel??servlet??web??

資源簡介

Java POI 導入導出Excel簡單實例源代碼 該源代碼的jar包,參見以下博文附錄截圖 Java POI導出EXCEL經典實現 Java導出Excel彈出下載框 http://blog.csdn.net/evangel_z/article/details/7332535 web頁面導出Excel文檔,路徑:http://localhost:8080/poi/export

資源截圖

代碼片段和文件信息

package?test;

import?java.io.File;
import?java.io.FileInputStream;
import?java.io.FileNotFoundException;
import?java.io.IOException;
import?java.text.DecimalFormat;
import?java.text.SimpleDateFormat;
import?java.util.linkedList;
import?java.util.List;

import?org.apache.poi.hssf.usermodel.HSSFCell;
import?org.apache.poi.hssf.usermodel.HSSFDateUtil;
import?org.apache.poi.hssf.usermodel.HSSFRow;
import?org.apache.poi.hssf.usermodel.HSSFSheet;
import?org.apache.poi.hssf.usermodel.HSSFWorkbook;
import?org.apache.poi.xssf.usermodel.XSSFCell;
import?org.apache.poi.xssf.usermodel.XSSFRow;
import?org.apache.poi.xssf.usermodel.XSSFSheet;
import?org.apache.poi.xssf.usermodel.XSSFWorkbook;

public?class?ReadExcel?{
/**
?*?對外提供讀取excel?的方法
?*?*/
public?static?Listject>>?readExcel(File?file)?throws?IOException?{
String?fileName?=?file.getName();
String?extension?=?fileName.lastIndexOf(“.“)?==?-1???““?:?fileName
.substring(fileName.lastIndexOf(“.“)?+?1);
if?(“xls“.equals(extension))?{
return?read2003Excel(file);
}?else?if?(“xlsx“.equals(extension))?{
return?read2007Excel(file);
}?else?{
throw?new?IOException(“不支持的文件類型“);
}
}

/**
?*?讀取?office?2003?excel
?*?
?*?@throws?IOException
?*?@throws?FileNotFoundException
?*/
private?static?Listject>>?read2003Excel(File?file)
throws?IOException?{
Listject>>?list?=?new?linkedListject>>();
HSSFWorkbook?hwb?=?new?HSSFWorkbook(new?FileInputStream(file));
HSSFSheet?sheet?=?hwb.getSheetAt(0);
object?value?=?null;
HSSFRow?row?=?null;
HSSFCell?cell?=?null;
int?counter?=?0;
for?(int?i?=?sheet.getFirstRowNum();?counter? .getPhysicalNumberOfRows();?i++)?{
row?=?sheet.getRow(i);
if?(row?==?null)?{
continue;
}?else?{
counter++;
}
Listject>?linked?=?new?linkedListject>();
for?(int?j?=?row.getFirstCellNum();?j?<=?row.getLastCellNum();?j++)?{
cell?=?row.getCell(j);
if?(cell?==?null)?{
continue;
}
DecimalFormat?df?=?new?DecimalFormat(“0“);//?格式化?number?String
//?字符
SimpleDateFormat?sdf?=?new?SimpleDateFormat(
“yyyy-MM-dd?HH:mm:ss“);//?格式化日期字符串
DecimalFormat?nf?=?new?DecimalFormat(“0.00“);//?格式化數字
switch?(cell.getCellType())?{
case?XSSFCell.CELL_TYPE_STRING:
System.out.println(i?+?“行“?+?j?+?“?列?is?String?type“);
value?=?cell.getStringCellValue();
break;
case?XSSFCell.CELL_TYPE_NUMERIC:
System.out.println(i?+?“行“?+?j
+?“?列?is?Number?type?;?DateFormt:“
+?cell.getCellstyle().getDataFormatString());
if?(“@“.equals(cell.getCellstyle().getDataFormatString()))?{
value?=?df.format(cell.getNumericCellValue());
}?else?if?(“General“.equals(cell.getCellstyle()
.getDataFormatString()))?{
value?=?nf.format(cell.getNumericCellValue());
}?else?{
value?=?sdf.format(HSSFDateUtil.getJavaDate(cell
.ge

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????529??2014-07-03?14:12??poi\.classpath
?????文件?????????282??2014-08-28?15:52??poi\.mymetadata
?????文件????????1746??2014-08-28?16:03??poi\.project
?????文件?????????493??2014-07-03?14:12??poi\.settings\.jsdtscope
?????文件?????????109??2014-07-03?14:12??poi\.settings\com.genuitec.eclipse.ws.prefs
?????文件?????????395??2014-07-03?14:12??poi\.settings\org.eclipse.jdt.core.prefs
?????文件?????????447??2014-07-03?14:12??poi\.settings\org.eclipse.wst.common.component
?????文件?????????252??2014-07-03?14:12??poi\.settings\org.eclipse.wst.common.project.facet.core.xml
?????文件??????????49??2014-07-03?14:12??poi\.settings\org.eclipse.wst.jsdt.ui.superType.container
?????文件???????????6??2014-07-03?14:12??poi\.settings\org.eclipse.wst.jsdt.ui.superType.name
?????文件?????????829??2014-07-03?14:12??poi\WebRoot\index.jsp
?????文件??????????36??2014-07-03?14:12??poi\WebRoot\meta-INF\MANIFEST.MF
?????文件?????????626??2014-08-28?16:03??poi\WebRoot\WEB-INF\web.xml
?????文件????????6361??2014-07-03?14:17??poi\src\test\ReadExcel.java
?????文件????????1386??2014-08-28?15:53??poi\src\testExport\Book.java
?????文件????????1740??2014-08-28?15:59??poi\src\testExport\ExcelServlet.java
?????文件???????11259??2014-08-28?16:00??poi\src\testExport\ExportExcel.java
?????文件?????????957??2014-08-28?15:52??poi\src\testExport\Student.java

評論

共有 條評論