avid.sibelius.v7.5.sounds怎么avid media安装教程

java(44)
1.文件操作异常类
&* 文件操作异常
&* @author luox
public class FileOperationException extends Exception
&& &private static final long serialVersionUID = 1L;
&& &public FileOperationException(String strMsg)
&& &&& &super(strMsg);
&& &public FileOperationException(Throwable t)
&& &&& &super(t);
&& &public FileOperationException(String strMsg, Throwable t)
&& &&& &super(strMsg, t);
---------------------------------
2.文件操作接口IFileOperation
import java.util.L
import java.util.M
&* 文件操作接口
&* @author luox
public interface IFileOperation
&& & * 获取文件列头
&& & * @return 文件列头
&& &public String[] getColumnHeaders();
&& & * 出了正式文件头外的第一个列头
&& & * @return
&& &public String[] getMultilcColumnHeaderFirst();
&& & * 获取文件内容数据
&& & * @return 文件内容数据
&& &public List&String[]& getFileContentData();
&& & * 获取用map形式组装的数据列表
&& & * @author xufeng
&& & * @since 日
&& & * @return
&& &public List&Map&String,String&& getFileContentDataMap();
&& & * 获取文件所有数据
&& & * @return 文件所有数据
&& &public List&String[]& getFileData();
&& & * 获取文件的第一个sheet名字
&& & * @return
&& &public String getFirstSheetName();
---------------
3.文件操作接口实现类
package com.jiemai.supplier.logic.
import java.io.F
import java.io.IOE
import java.math.BigD
import java.util.ArrayL
import java.util.D
import java.util.HashM
import java.util.L
import java.util.M
import jxl.C
import jxl.CellT
import jxl.DateC
import jxl.NumberC
import jxl.S
import jxl.W
import jxl.WorkbookS
import jxl.read.biff.BiffE
import mon.utility.DateFormatU
import mon.utility.StringU
&* Excel文件解析操作类
&* @author xieyongle
public class ExcelFileOperation implements IFileOperation
&&&& * Excel文件里的标题
&&& private String[] columnH
&&&& * Excel文件内容
&&& private List&String[]&& fileContentD
&&&& * 除了正式列头外的第一个列头
&&& private String[] multiColumnFirstH
&&& private List&Map&String,String&& contentDataM
&&&& * Excel文件里所有数据
&&& private List&String[]& fileD
&&&& * 第一个sheet名字
&&& private String fistSheetN
&&&& * 根据文件路径初始化
&&&& * @param uploadfile 文件路径
&&&& * @throws FileOperationException
&&& public& ExcelFileOperation(String uploadfile) throws FileOperationException
&&&&&&& File objFile = new File(uploadfile);
&&&&&&& init(objFile);
&&&& * 以文件对象构造
&&&& * @param upFile 文件对象
&&&& * @throws FileOperationException
&&& public& ExcelFileOperation(File upFile) throws FileOperationException
&&&&&&& init(upFile);
&&& public& ExcelFileOperation(File upFile,boolean assemMap) throws FileOperationException
&&&&&&& init(upFile,assemMap,0);
&&& public& ExcelFileOperation(File upFile,boolean assemMap,int readHead) throws FileOperationException
&&&&&&& init(upFile,assemMap,readHead);
&&&& * 原始的方法,把excel中的数据组装成数组的形式
&&&& * @param objFile
&&&& * @throws FileOperationException
&&&& * @deprecated 因为使用数组索引会造成以后修改excel内容格式很麻烦,因此建议使用init(File objFile,boolean initMap)方法来实例化,使用map的形式获取每列的值& -xufeng 日
&&& @Deprecated
&&& protected void init(File objFile) throws FileOperationException
&&&&&&& init(objFile,false,0);
&&&& * 新的方法,同时把所有的excel中的所有数据组装到map中,以避免通过数组索引来获取值
&&&& * @author xufeng
&&&& * @since 日
&&&& * @param objFile
&&&& * @param initMap
&&&& * @throws FileOperationException
&&& protected void init(File objFile,boolean initMap,int readHead) throws FileOperationException
&&&&&&& Workbook objWorkbook =
&&&&&&& try {
&&&&&&&&&&& WorkbookSettings objWorkbookSettings = new WorkbookSettings();
&&&&&&&&&&& //此处用iso-8859-1反而不乱码UTF-16LE
&&&&&&&&&&& objWorkbookSettings.setEncoding(&ISO-8859-1&);
&&&&&&&&&&& objWorkbookSettings.setCellValidationDisabled(true); //禁用单元格校验,否则wps编辑的excel或因office版本差别可能导致不能正常读取内容
&&&&&&&&&&& objWorkbook = Workbook.getWorkbook(objFile,objWorkbookSettings);
&&&&&&&&&&& Sheet firstSheet = objWorkbook.getSheet(0);
&&&&&&&&&&& setFistSheetName(firstSheet.getName());
&&&&&&&&&&& int iRows = firstSheet.getRows();&& &&& &&& &
&&&&&&&&&&& int iColumn = firstSheet.getColumns();
&&&&&&&&&&& if(iRows & 0 && iColumn & 0)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& fileData = parseFileData(firstSheet, iRows, iColumn);
&&&&&&&&&&&&&&& contentDataMap = new ArrayList&Map&String,String&& ();
&&&&&&&&&&&&&&& if(fileData.size() & 0)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&& /*& if(readHead & 0){
&&&&&&&&&&&&&&&&&&&&&&& for(int i = 0 ; i&readH i++){
&&&&&&&&&&&&&&&&&&&&&&&&&&& if(i ==& readHead){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&&&&&&&&&& if(i == 0){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& multiColumnFirstHeader = fileData.remove(0);
&&&&&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& }*/
&&&&&&&&&&&&&&&&&&& columnHeaders = fileData.remove(0);
&&&&&&&&&&&&&&&&&&& //&& &&& &&& &&& &&& &fileContentData = new ArrayList&String[]&();
&&&&&&&&&&&&&&&&&&& fileContentData = fileD
&&&&&&&&&&&&&&&&&&& if(initMap){
&&&&&&&&&&&&&&&&&&&&&&& for(String[] row : fileData){
&&&&&&&&&&&&&&&&&&&&&&&&&&& Map&String,String& map = new HashMap&String,String&();
&&&&&&&&&&&&&&&&&&&&&&&&&&& for(int index = 0;index & row.index++){
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& map.put(columnHeaders[index], row[index]);
&&&&&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&&&&&&&&&& contentDataMap.add(map);
&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&&&&&& //&& &&& &&& &&& &&& &fileContentData.remove(0);
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& } catch (BiffException e) {
&&&&&&&&&&& throw new FileOperationException(e);
&&&&&&& } catch (IOException e) {
&&&&&&&&&&& throw new FileOperationException(e);
&&&&&&& }finally{
&&&&&&&&&&& if(objWorkbook != null){
&&&&&&&&&&&&&&& objWorkbook.close();
&&&&&&&&&&& }
&&& private List&String[]& parseFileData(Sheet objSheet, int iRows, int iColumn)
&&&&&&& // System.out.println(JSON.toJSONString(objSheet.getSettings()));
&&&&&&& List&String[]& fileDataList = new ArrayList&String[]&();
&&&&&&& for(int i = 0; i & iR i++)
&&&&&&&&&&& String[] arrayRow = new String[iColumn];
&&&&&&&&&&& //判断是当前行是否是空行,空行则不加
&&&&&&&&&&& boolean blNullRow =
&&&&&&&&&&& for(int j = 0; j & iC j++)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Cell cell = objSheet.getCell(j,i);
&&&&&&&&&&&&&&& //&& &&& &&& &&& &System.out.println(JSON.toJSONString(cell));
&&&&&&&&&&&&&&& String strContents =
&&&&&&&&&&&&&&& //单元格数字处理:有些数字不准确
&&&&&&&&&&&&&&& if(cell.getType().equals(CellType.NUMBER))
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& NumberCell numberCell = (NumberCell)
&&&&&&&&&&&&&&&&&&& Double numberb2 = numberCell.getValue();
&&&&&&&&&&&&&&&&&&& BigDecimal bd = new BigDecimal(numberb2);
&&&&&&&&&&&&&&&&&&& if (bd.toString().indexOf(&.&) & -1)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& strContents = String.valueOf(Float.parseFloat(bd.toString()));
&&&&&&&&&&&&&&&&&&& } else
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& strContents = bd.toString();
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }else if(cell.getType().equals(CellType.DATE))
&&&&&&&&&&&&&&& {//对单元格中的日期进行处理
&&&&&&&&&&&&&&&&&&& DateCell dateCell = (DateCell)
&&&&&&&&&&&&&&&&&&& Date date = dateCell.getDate();
&&&&&&&&&&&&&&&&&&& strContents = DateFormatUtility.getStandardDate(date);
&&&&&&&&&&&&&&& }else
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& strContents = cell.getContents();
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& //去空格
&&&&&&&&&&&&&&& if(!StringUtility.isNull(strContents))
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& strContents = strContents.trim();
&&&&&&&&&&&&&&&&&&& blNullRow =
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& arrayRow[j] = strC
&&&&&&&&&&& }
&&&&&&&&&&& if(!blNullRow)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& fileDataList.add(arrayRow);
&&&&&&&&&&& }
&&&&&&& return fileDataL
&&& public String[] getColumnHeaders()
&&&&&&& return columnH
&&& public List&String[]& getFileContentData()
&&&&&&& return fileContentD
&&& public List&String[]& getFileData()
&&&&&&& return fileD
&&& public String getFirstSheetName() {
&&&&&&& // TODO Auto-generated method stub
&&&&&&& return fistSheetN
&&& public void setFistSheetName(String fistSheetName) {
&&&&&&& this.fistSheetName = fistSheetN
&&& @Override
&&& public List&Map&String, String&& getFileContentDataMap() {
&&&&&&& return contentDataM
&&& @Override
&&& public String[] getMultilcColumnHeaderFirst() {
&&&&&& return multiColumnFirstH
-------------------
4.日期格式化工具类
package mon.
import java.text.ParseE
import java.text.SimpleDateF
import java.util.D
import java.util.GregorianC
&* 日期格式工具
&* User: Jordan
&* Time: 22:12:53
public class DateFormatUtility
& public final static String STANDARD = &yyyy-MM-dd HH:mm:ss&;
& public final static String COMPACT = &yyMMdd HH:mm:ss&;
& public final static String FILENAME = &yyMMdd_HHmmss&;
& public final static String FILENAME2 = &yyyy-MM-dd_HH-mm-ss&;
& public final static String FORMAT_DAY = &yyyy-MM-dd&;
& public final static String STANDARD2 = &yyyyMMddHHmmss&;
& public final static String STANDARD3 = &yyyyMMdd&;
& public static final int OneDay_Milliseconds = 24*60*60*1000;
& public static Date getStringDate(String strDate, String strType)
&& &&& &Date date =
&& &&& &SimpleDateFormat objSDF = new SimpleDateFormat(strType);
&& &&& &try
&& &&& &&& &date = objSDF.parse(strDate);
&& &&& &} catch (ParseException e)
&& &&& &&& &e.printStackTrace();
&& * 获得时间戳
&& * @return
& public static String getDateString(GregorianCalendar objGC,
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& String strType)
&&& if (objGC == null) return &&;
&&& Date objDate = objGC.getTime();
&&& return getDateString(objDate, strType);
& public static String getStandardDate(GregorianCalendar objGC)
&&& return getDateString(objGC, STANDARD);
& public static String getFileNameDate(GregorianCalendar objGC)
&&& return getDateString(objGC, FILENAME);
& public static String getCompactDate(GregorianCalendar objGC)
&&& return getDateString(objGC, COMPACT);
& public static String getDateString(Date objDate,String strType)
&&& if (objDate == null) return &&;
&&& SimpleDateFormat objSDF = new SimpleDateFormat(strType);
&&& return objSDF.format(objDate);
& public static String getDateString(String strDate,String strType)
&&& if (strDate == null)
&& &&& &return &&;
&&& Date objDate =
&&& SimpleDateFormat objSDF = new SimpleDateFormat(STANDARD);
&& &&& &objDate = objSDF.parse(strDate);
&& &} catch (ParseException e)
&& &&& &e.printStackTrace();
&&& objSDF = new SimpleDateFormat(strType);
&&& return objSDF.format(objDate);
& public static String getStandardDate(Date objDate)
&&& return getDateString(objDate, STANDARD);
& public static String getCompactDate(Date objDate)
&&& return getDateString(objDate, COMPACT);
& public static String getFileNameDate(Date objDate)
&&& return getDateString(objDate, FILENAME);
& public static String getSysdateString(String strType)
&&& Date objDate = new Date();
&&& return getDateString(objDate, strType);
& public static String getStandardSysdate()
&&& Date objDate = new Date();
&&& return getDateString(objDate, STANDARD);
& public static String getCompactSysdate()
&&& Date objDate = new Date();
&&& return getDateString(objDate, COMPACT);
& public static String getFileNameSysdate()
&&& Date objDate = new Date();
&&& return getDateString(objDate, FILENAME);
& public static String getFileNameSysdate2()
&&& Date objDate = new Date();
&&& return getDateString(objDate, FILENAME2);
& public static Date getStandardDate(String strDate)
&&& return getStringDate(strDate, STANDARD);
& public static void main(String[] args)
&&& System.out.println(DateFormatUtility.getSysdateString(STANDARD));
&&& System.out.println(DateFormatUtility.getSysdateString(COMPACT));
&&& System.out.println(DateFormatUtility.getSysdateString(STANDARD3));
--------------------
5、订单文件解析工厂类
import java.io.F
&* 订单文件解析工厂类
&* @author xieyongle
public class FileParseFatory
&& & * 获得订单文件操作对象
&& & * @param fileType 订单文件类型
&& & * @param uploadFile 订单文件路径,用于建立文件对象
&& & * @return 订单文件操作对象
&& & * @throws FileOperationException
&& &public static IFileOperation getFileOperation(String fileType, String uploadFile) throws FileOperationException
&& &&& &if(IFileBasic.File_Type_CSV.equalsIgnoreCase(fileType))
&& &&& &&& &return new CSVFileOperation(uploadFile);
&& &&& &&& &
&& &&& &}else if(IFileBasic.File_Type_XLS.equalsIgnoreCase(fileType))
&& &&& &&& &return new ExcelFileOperation(uploadFile);
&& &&& &}else if(IFileBasic.File_Type_XLSX.equalsIgnoreCase(fileType))
&& &&& &&& &return new XExcelFileOperation(uploadFile);
&& &&& &}else
&& &&& &&& &
&& &&& &&& &
&& & * 获得订单文件操作对象
&& & * @param fileType 订单文件类型
&& & * @param upFile 订单文件对象
&& & * @return 订单文件操作对象
&& & * @throws FileOperationException
&& &public static IFileOperation getFileOperation(String fileType, File upFile) throws FileOperationException{
&& &&& &return getFileOperation(fileType,upFile,false,0);
&& &public static IFileOperation getFileOperation(String fileType, File upFile,int readHead) throws FileOperationException{
&& &&&& return getFileOperation(fileType,upFile,false,readHead);
&& &public static IFileOperation getFileOperation(String fileType, File upFile,boolean asseMap) throws FileOperationException{
&& &&&& return getFileOperation(fileType,upFile,false,0);
&& &public static IFileOperation getFileOperation(String fileType, File upFile,boolean assemMap,int readHead) throws FileOperationException
&& &&& &if(IFileBasic.File_Type_CSV.equalsIgnoreCase(fileType))
&& &&& &&& &return new CSVFileOperation(upFile);
&& &&& &&& &
&& &&& &}else if(IFileBasic.File_Type_XLS.equalsIgnoreCase(fileType))
&& &&& &&& &return new ExcelFileOperation(upFile,assemMap,readHead);
&& &&& &}else if(IFileBasic.File_Type_XLSX.equalsIgnoreCase(fileType))
&& &&& &&& &return new XExcelFileOperation(upFile);
&& &&& &else
&& &&& &&& &
&& &&& &&& &
---------------------
6.CSV文件操作类
package com.jiemai.supplier.logic.
import java.io.F
import java.io.IOE
import java.util.ArrayL
import java.util.L
import java.util.M
import mon.utility.CSVA
&* CSV文件操作类
&* @author xieyongle
public class CSVFileOperation implements IFileOperation
&& & * CSV文件里的标题
&& &private String[] columnH
&& & * CSV文件内容
&& &private List&String[]&& fileContentD
&& & * CSV文件里所有数据
&& &private List&String[]& fileD
&& & * 第一个sheet名字
&& &private String fistSheetN
&& &public CSVFileOperation(String uploadfile) throws FileOperationException
&& &&& &try
&& &&& &&& &CSVAnalysis objCSVAnalys = new CSVAnalysis(uploadfile);
&& &&& &&& &init(objCSVAnalys);
&& &&& &} catch (IOException e)
&& &&& &&& &throw new FileOperationException(e);
&& &public CSVFileOperation(File objfile) throws FileOperationException
&& &&& &try
&& &&& &&& &CSVAnalysis objCSVAnalys = new CSVAnalysis(objfile);
&& &&& &&& &init(objCSVAnalys);
&& &&& &} catch (IOException e)
&& &&& &&& &throw new FileOperationException(e);
&& & * 对CSV文件进行解析
&& & * @param objCSVAnalysis
&& & * @throws FileOperationException
&& &public void init(CSVAnalysis objCSVAnalysis) throws FileOperationException
&& &&& &try
&& &&& &&&& List&List&String&& result = objCSVAnalysis.readCSVFile();
&& &&& &&& &
&& &&& &&&& if(result != null && result.size() & 0)
&& &&&&&&&& {
&& &&& &&& &&& &fileData = new ArrayList&String[]&();
&& &&&&&&& &&& &for(int i = 0 ; i & result.size(); i++)
&& &&&&&&& &&& &{
&& &&&&&&& &&& &&& &List&String& list& = result.get(i);
&& &&&&&&& &&& &&& &String[] arrtemp = new String[list.size()];
&& &&&&&&& &&& &&& &arrtemp = list.toArray(arrtemp);
&& &&&&&&& &&& &&& &fileData.add(arrtemp);
&& &&&&&&& &&& &}
&& &&& &&& &&& &columnHeaders = fileData.get(0);
&& &&& &&& &&& &fileContentData = new ArrayList&String[]&();
&& &&& &&& &&& &fileContentData.addAll(fileData);
&& &&& &&& &&& &fileContentData.remove(0);
&& &&&&&&&& }
&& &&& &&&& setFistSheetName(objCSVAnalysis.getFistSheetName());
&& &&& &} catch (IOException e)
&& &&& &&& &throw new FileOperationException(e);
&& &public String[] getColumnHeaders()
&& &&& &return columnH
&& &public List&String[]& getFileContentData()
&& &&& &return fileContentD
&& &public List&String[]& getFileData()
&& &&& &return fileD
&& &public String getFirstSheetName() {
&& &&& &return fistSheetN
&& &public void setFistSheetName(String fistSheetName) {
&& &&& &this.fistSheetName = fistSheetN
&& &@Override
&& &public List&Map&String, String&& getFileContentDataMap() {
&&& @Override
&&& public String[] getMultilcColumnHeaderFirst() {
&&&&&&& // TODO Auto-generated method stub
---------------------
7.文件常量类
&* 文件常量
&* @author xieyongle
public interface IFileBasic
&& &public static final String File_Type_CSV = &csv&;
&& &public static final String File_Type_XLS = &xls&;
&& &public static final String File_Type_XLSX=&xlsx&;
--------------------------
8.解析Excel文件类
import java.io.F
import java.io.FileInputS
import java.io.FileNotFoundE
import java.io.IOE
import java.io.InputS
import java.math.BigD
import java.util.ArrayL
import java.util.L
import java.util.M
import org.apache.poi.hssf.usermodel.HSSFW
import org.apache.poi.poifs.filesystem.OfficeXmlFileE
import org.apache.poi.ss.usermodel.C
import org.apache.poi.ss.usermodel.R
import org.apache.poi.ss.usermodel.S
import org.apache.poi.ss.usermodel.W
import org.apache.poi.xssf.usermodel.XSSFW
import mon.utility.StringU
&* @Project: jiemai-web
&* &p&Description:& &/p&
&* &p&解析Excel文件(兼容)&/p&&& &&& &
&* @author luo bohui
&* @version 2.x
public class XExcelFileOperation implements IFileOperation {
&& & * Excel文件里的标题
&& &private String[] columnH
&& & * Excel文件内容
&& &private List&String[]&& fileContentD
&& & * Excel文件里所有数据
&& &private List&String[]& fileD
&& & * 第一个sheet名字
&& &private String fistSheetN
&& & * 根据文件初始路径构造对象
&& & * @throws FileNotFoundException
&& & * @throws FileOperationException
&& &public XExcelFileOperation(String uploadFile) throws FileOperationException{
&& &&& &File file = new File(uploadFile);
&& &&& &init(file);
&& & * 以文件对象构造
&& & * @param upFile 文件对象
&& & * @throws FileOperationException
&& & * @throws FileNotFoundException
&& &public& XExcelFileOperation(File uploadFile) throws FileOperationException
&& &{&& &&& &&& &
&& &&& &init(uploadFile);
&& & * &p&@description 初始化文件内容& &/p&
&& & * &p&@author luo bohui& &/p&
&& & * &p& & &/p&
&& & * @lastModifier Administrator
&& & * @lastModificationDate
&& & * @remark TODO
&& & * @param objFile
&& & * @throws FileOperationException
&& & * @throws IOException
&& &protected void init(File objFile) throws FileOperationException
&& &&& &Workbook wb =
&& &&& &InputStream stream =
&& &&& &if(!objFile.isFile())
&& &&& &&& &throw new FileOperationException(&处理的不是常规文件&);&& &&& &
&& &&& & try {
&& &&& &&& & && &stream=new FileInputStream(objFile);
&& &&& &&&&&&&& try{&& &&& &&&&&&&&&& &
&& &&&&&&&&&&&&&&&& wb=new HSSFWorkbook(stream);
&& &&& &&&&&&&& }catch(OfficeXmlFileException e){
&& &&& &&&&&&& &&& &stream=new FileInputStream(objFile);//需要重新初始化
&& &&& &&&&&&& &&& &wb=new XSSFWorkbook(stream);
&& &&& &&&&&&&& }
&& &&& &&&&&&&& Sheet firstsheet = wb.getSheetAt(0);&& &&&&&&& &
&& &&& &&&&&&&& Row row = firstsheet.getRow(0);
&& &&& &&&&&&&& int rows = firstsheet.getPhysicalNumberOfRows();
&& &&& &&&&&&&& int columns = row.getPhysicalNumberOfCells();
&& &&& &&&&&&&& if(rows&0 && columns&0){
&& &&& &&&&&&& &&& &fileData = parseFileData(firstsheet, rows, columns);
&& &&& &&&&&&& &&& &if(fileData.size() & 0)
&& &&& &&& &&& &&& &{
&& &&& &&& &&& &&& &&& &columnHeaders = fileData.get(0);
&& &&& &&& &&& &&& &&& &fileContentData = new ArrayList&String[]&();
&& &&& &&& &&& &&& &&& &fileContentData.addAll(fileData);
&& &&& &&& &&& &&& &&& &fileContentData.remove(0);
&& &&& &&& &&& &&& &}
&& &&& &&&&&&&& }
&& &&& & }catch(IOException e){
&& &&& &&& & throw new FileOperationException(e);
&& &&& & }finally{
&& &&& &&& & if(stream!=null)
&& &&& &&& &&& &try {
&& &&& &&& &&& &&& &stream.close();
&& &&& &&& &&& &} catch (IOException e) {
&& &&& &&& &&& &&& &// TODO Auto-generated catch block
&& &&& &&& &&& &&& &throw new FileOperationException(e);
&& &&& &&& &&& &}
&& &&& & }
&& & * &p&@description 读取Excel文件内容& &/p&
&& & * &p&@author luo bohui& &/p&
&& & * &p& & &/p&
&& & * @lastModifier Administrator
&& & * @lastModificationDate
&& & * @remark TODO
&& & * @param sheet
&& & * @param rows
&& & * @param columns
&& & * @return
&& &private List&String[]& parseFileData(Sheet sheet, int rows, int columns) {
&& &&& &// TODO Auto-generated method stub
&& &&& &List&String[]& fileDataList = new ArrayList&String[]&();
&& &&& &for(int i=0; i& i++){
&& &&& &&& &Row row = sheet.getRow(i);
&& &&& &&& &String[] rowValues = new String[columns];
&& &&& &&& &if(row==null)
&& &&& &&& &for(int j=0; j& j++){
&& &&& &&& &&& &String strContents = &&;
&& &&& &&& &&& &Cell cell = row.getCell(j);
&& &&& &&& &&& &strContents = getCellFormatValue(cell).trim();
&& &&& &&& &&& &rowValues[j] = strC& &&& &&& &&& &&& &&& &&& &&& &
&& &&& &&& &}
&& &&& &&& &//去除掉空白行
&& &&& &&& &if(!isNULL(rowValues))
&& &&& &&& &&& &fileDataList.add(rowValues);
&& &&& &return fileDataL
&& & * &p&@description 判断行是否为空 &/p&
&& & * &p&@author luo bohui& &/p&
&& & * &p& & &/p&
&& & * @lastModifier Administrator
&& & * @lastModificationDate
&& & * @remark TODO
&& & * @param rowValues
&& & * @return 行为空 返回true,否则返回false
&& &private boolean isNULL(String[] rowValues) {
&& &&& &// TODO Auto-generated method stub
&& &&& &boolean flag =
&& &&& &if(rowValues==null)
&& &&& &for(String str:rowValues){
&& &&& &&& &if(!StringUtility.isNull(str))
&& &&& &&& &&& &flag=
&& & * &p&@description 读取单元格内容& &/p&
&& & * &p&@author luo bohui& &/p&
&& & * &p& & &/p&
&& & * @lastModifier Administrator
&& & * @lastModificationDate
&& & * @remark TODO
&& & * @param cell
&& & * @return
&& &private String getCellFormatValue(Cell cell) {
&& &&& &// TODO Auto-generated method stub
&& &&& & String cellvalue = &&;
&& &&&&&&&& if (cell != null) {
&& &&&&&&&&&&&& // 判断当前Cell的Type
&& &&&&&&&&&&&& switch (cell.getCellType()) {
&& &&&&&&&&&&&& // 如果当前Cell的Type为NUMERIC
&& &&&&&&&&&&&& case Cell.CELL_TYPE_NUMERIC: {
&& &&&&&&&&&&& &&& &Double nums = cell.getNumericCellValue();
&& &&&&&&&&&&& &&& &BigDecimal bd = new BigDecimal(nums);
&& &&&&&&&&&&& &&& &if (bd.toString().indexOf(&.&) & -1)
&& &&& &&& &&& &&& &{
&& &&& &&& &&& &&& &&& &cellvalue = String.valueOf(Float.parseFloat(bd.toString()));
&& &&& &&& &&& &&& &} else
&& &&& &&& &&& &&& &{
&& &&& &&& &&& &&& &&& &cellvalue = bd.toString();
&& &&& &&& &&& &&& &}
&& &&&&&&&&&&& &&& &
&& &&&&&&&&&&&& }
&& &&&&&&&&&&&& case Cell.CELL_TYPE_BOOLEAN: {
&& &&&&&&&&&&& &&& &cellvalue = String.valueOf(cell.getBooleanCellValue());
&& &&&&&&&&&&&& }
&& &&&&&&&&&&&& //公式类型暂不处理
&& &&&&&&&&&&&& case Cell.CELL_TYPE_FORMULA: {&& &&&&&&&&&&&&&&& &
&& &&&&&&&&&&&&&&&&
&& &&&&&&&&&&&& }
&& &&&&&&&&&&&& case Cell.CELL_TYPE_STRING:
&& &&&&&&&&&&&&&&&& cellvalue = cell.getRichStringCellValue().getString();
&& &&&&&&&&&&&&&&&&
&& &&&&&&&&&&&& default:
&& &&&&&&&&&&&&&&&& cellvalue = &&;
&& &&&&&&&&&&&& }
&& &&&&&&&& } else {
&& &&&&&&&&&&&& cellvalue = &&;
&& &&&&&&&& }
&& &&&&&&&&
&&& public static void main(String[] args) throws FileNotFoundException, FileOperationException {
&& &&& &File file = new File(&C:\\Users\\Administrator\\Desktop\\template&);
&& &&& &int j=0;
&& &&& &for(File f:file.listFiles()){
&& &&& &&& & System.out.println(&-------------------------解析第 &+(++j)+& 个文件&+f.getName()+&----------------------&);
&& &&&&&&& XExcelFileOperation operation = new XExcelFileOperation(f);
&& &&&&&&& List&String[]& contents = operation.getFileData();
&& &&&&&&& String[] titles = operation.getColumnHeaders();
&& &&&&&&& for(String title:titles){
&& &&& &&& &&& System.out.println(title);
&& &&&&&&& }
&& &&&&&&& int i = 0;
&& &&&&&&& for(String[] rowvalues:contents){
&& &&& &&& &&& System.out.println(&-------------------------第 &+(++i)+& 行内容----------------------&);
&& &&& &&& &&& for(String cell:rowvalues){
&& &&& &&& &&& &&& System.out.println(cell);
&& &&& &&& &&& }
&& &&&&&&& }
&& &public String[] getColumnHeaders() {
&& &&& &return columnH
&& &public void setColumnHeaders(String[] columnHeaders) {
&& &&& &this.columnHeaders = columnH
&& &public List&String[]& getFileContentData() {
&& &&& &return fileContentD
&& &public void setFileContentData(List&String[]& fileContentData) {
&& &&& &this.fileContentData = fileContentD
&& &public List&String[]& getFileData() {
&& &&& &return fileD
&& &public void setFileData(List&String[]& fileData) {
&& &&& &this.fileData = fileD
&& &public String getFirstSheetName() {
&& &&& &return fistSheetN
&& &public void setFistSheetName(String fistSheetName) {
&& &&& &this.fistSheetName = fistSheetN
&& &@Override
&& &public List&Map&String, String&& getFileContentDataMap() {
&&& @Override
&&& public String[] getMultilcColumnHeaderFirst() {
&&&&&&& // TODO Auto-generated method stub
------------------
9.最终读取导入excel文件内容方法类
import java.io.BufferedOutputS
import java.io.F
import java.io.FileOutputS
import java.io.IOE
import java.io.OutputS
import java.net.URLE
import java.text.SimpleDateF
import java.util.ArrayL
import java.util.D
import java.util.HashM
import java.util.L
import java.util.M
import javax.servlet.http.HttpS
import jxl.write.WritableW
import jxl.write.WriteE
import mons.lang.StringU
import org.springframework.beans.factory.annotation.A
import mon.util.CollectionU
import com.haitao.seller.order.IExceptionOrderL
import com.jiemai.JMC
import com.jiemai.JMU
import com.jiemai.download.DownloadP
import com.jiemai.download.DownloadP
import com.jiemai.download.ProgressP
import com.jiemai.order.dto.ExceptionO
import com.jiemai.seller.dto.SellerShowM
import com.jiemai.seller.dto.TsoS
import com.jiemai.seller.logic.SoOrderL
import com.jiemai.supplier.logic.fileparse.FileParseF
import com.jiemai.supplier.logic.fileparse.IFileB
import com.jiemai.supplier.logic.fileparse.IFileO
import com.jiemai.system.logic.P
import com.jiemai.util.StringU
import com.jiemai.util.ValidateI
public class readExcel{
&&&& * 产品文件对象
&&& private File uploadF
&&&& * 内容类型
&&& private String uploadFileContentT
&&&& * 文件名称
&&& private String uploadFileFileN
& &public File getUploadFile() {
&&&&&&& return uploadF
&&& public void setUploadFile(File uploadFile) {
&&&&&&& this.uploadFile = uploadF
&&& public String getUploadFileContentType() {
&&&&&&& return uploadFileContentT
&&& public void setUploadFileContentType(String uploadFileContentType) {
&&&&&&& this.uploadFileContentType = uploadFileContentT
&&& public String getUploadFileFileName() {
&&&&&&& return uploadFileFileN
&&& public void setUploadFileFileName(String uploadFileFileName) {
&&&&&&& this.uploadFileFileName = uploadFileFileN
& private List&String[]& resolveFileContent(){
&&&&&&& // 判断是否上传成功
&&&&&&& if (StringUtility.isNull(uploadFileFileName)
&&&&&&&&&&&&&&& || uploadFile == null) {
&&&&&&&&&&& lstMsg.add(getShowMessage(&不能上传空文件,请重新上传,谢谢!&));
&&&&&&&&&&&
&&&&&&& // 解析Excel文件
&&&&&&& IFileOperation fileOperation =
&&&&&&& try {
&&&&&&&&&&& fileOperation = FileParseFatory.getFileOperation(IFileBasic.File_Type_XLS, uploadFile);
&&&&&&& } catch (Exception e1) {
&&&&&&&&&&& LOG.error(&上传文件出错&,e1);
&&&&&&&&&&& lstMsg.add(getShowMessage(&请传XLS格式的文件&));
&&&&&&&&&&&
&&&&&&& if (fileOperation == null) {
&&&&&&&&&&& lstMsg.add(getShowMessage(&请传XLS格式的文件&));
&&&&&&&&&&&
&&&&&&& // 取出文件内容
&&&&&&& List&String[]& datas = fileOperation.getFileContentData();
&&&&&&& if (datas == null || datas.size() == 0) {
&&&&&&&&&&& lstMsg.add(getShowMessage(&上传Excel文件内容为空,请重新填写!&BR&&));
&&&&&&&&&&&
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:49894次
排名:千里之外
原创:38篇
转载:45篇
(1)(3)(1)(1)(1)(4)(5)(8)(2)(1)(2)(2)(4)(2)(1)(1)(3)(1)(1)(39)(1)

我要回帖

更多关于 nocopyrightsounds 的文章

 

随机推荐